NEConvolutionLayer - filling weights tensor and biases tensor data buffers
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 ?
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
}
Thanks !
Assuming question has been addressed. Closing issue. Reopen if required!