ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

NEConvolutionLayer - filling weights tensor and biases tensor data buffers

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

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

For convolution layer, we have to copy data to 3 tensors : Input data, weights and biases. For input data tensor, we have to copy the data row by row, because of padding performed on the data for convolution operation. Can we safely assume that there is no padding for the data in weights tensor, and all data can be copied to each of this tensor in just one memcpy ? And similarly for biases tensor ?

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

Currently the library doesn't need any padding for the weights and biases passed to NEConvolution layer. However, that should be considered an implementation detail that could change in future versions.

Instead of relying on that assumption the better approach is to check at runtime if padding is needed and to fill accordingly. For example:

Tensor input;
Tensor weights;
Tensor biases;
Tensor output;

// Init tensors
// ... setup tensors with the required sizes; don't allocate

PadStrideInfo pad_stride_info(/* ... */);
NEConvolutionlayer(&inputs, &weights, &biases, &output, pad_stride_info);

// Allocate tensors
input.allocator()->allocate();
weights.allocator()->allocate();
biases.allocator()->allocate();
output.allocator()->allocate();

// Fill tensors
// ...

if(weights.info()->has_padding())
{
    // row-by-row copy
}
else
{
    // memcpy
}

mpflanzer avatar Apr 24 '17 08:04 mpflanzer

Thanks !

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

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

GeorgeARM avatar May 03 '17 09:05 GeorgeARM