ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

convolution layer followed by RELU : can convolutionlayer's output data tensor be passed to RELU as input data tensor ?

Open joel-mi opened this issue 9 years ago • 6 comments

Convolution layer stores its output data to its output tensor’s data buffer, and RELU takes its input from its input tensor’s data buffer (input tensor specified as 1st argument of NEActivationLayerKernel::configure). In order to pass convolution layer’s output to RELU operation as input, do we have to use 2 separate tensors - one for NEConvolutionLayer output and another one for NEActivationLayerKernel input ? In this case, the data would have to be copied row after row from one tensor's data buffer to the other one.

Or can we directly pass convolution layer’s output tensor as input tensor to NEActivationLayerKernel ? I would prefer this implementation as it would save precious CPU time (zero-copy), but do we have to expect some incompatibility of data buffer layout, due to padding performed in convolution layer (we use 3x3 filters for convolution layer, with 1-element padding on each side) ? If so, is there a way to overcome this incompatibility ?

joel-mi avatar Apr 23 '17 11:04 joel-mi

in my question, I mentioned by mistake NEActivationLayerKernel - I actually meant NEActivationLayer

joel-mi avatar Apr 24 '17 08:04 joel-mi

There is no need to use two different tensors for input and output. As long as the dimensions match you directly reuse the same tensor the output of the first function is written to. The library will handle the padding etc. transparently.

mpflanzer avatar Apr 24 '17 08:04 mpflanzer

Many thanks !

From: Moritz Pflanzer [mailto:[email protected]] Sent: Monday, April 24, 2017 11:28 AM To: ARM-software/ComputeLibrary Cc: Joel Miedzigorski; Author Subject: Re: [ARM-software/ComputeLibrary] convolution layer followed by RELU : can convolutionlayer's output data tensor be passed to RELU as input data tensor ? (#60)

There is no need to use two different tensors for input and output. As long as the dimensions match you directly reuse the same tensor the output of the first function is written to. The library will handle the padding etc. transparently.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ARM-software/ComputeLibrary/issues/60#issuecomment-296574753, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AaiCl_pDFZNuhLVaIsDGg8IFLAYnP3nHks5rzF0pgaJpZM4NFYWa.

joel-mi avatar Apr 24 '17 08:04 joel-mi

one more question related to this issue : if I reuse a tensor for input, I understand that I must refrain from calling allocator()->allocate() for this tensor after calling configure - am I right ? (While for new tensors - not reused ones - I call allocator()->allocate() after configure)

joel-mi avatar Apr 24 '17 10:04 joel-mi

Yes, you need to allocate the tensor only once. However, to make sure that it will have enough padding for all the functions you want to use it with (no matter whether the tensor will be input or output) you need to first configure all functions before allocating.

mpflanzer avatar Apr 24 '17 13:04 mpflanzer

Assuming question has been addressed. Closing issue. Reopen if required!

GeorgeARM avatar May 03 '17 09:05 GeorgeARM