ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

Memory assignment to Tensor

Open Subarukun opened this issue 8 years ago • 7 comments

Hi,

Can I allocate a buffer and assign that ptr to Tensor for neon based layers as shown below

float* buf=new float[size] Tensor.allocator()->allocate(buf)

instead of using the existing allocation strategy

Tensor.allocator()->allocate() Is there any overloaded function for allocate as it is for memory Memory(uint8_t *memory);

If I do so , are there any repercussions? do I need to handle any extra things?

Thanks

Subarukun avatar Feb 26 '18 07:02 Subarukun

Hi,

Instead of doing Tensor.allocator()->allocate() you can do Tensor.allocator()->import_memory(arm_compute::Memory(your_ptr))

However you need to make sure the alignment/padding meet the minimum requirements or it will not work.

AnthonyBarbier avatar Feb 26 '18 09:02 AnthonyBarbier

Thanks for quick reply. I will use the Tensor specific details for assigning memory, for memory increase after configure. But my concern is, Is it ok to maintain always doubleword alignment ?

I assume it is enough if I maintain the double word alignment and handle the padding requirements? If the padding is handled do we need to always maintain the padded element values to be zeroes?

Subarukun avatar Feb 27 '18 09:02 Subarukun

Yes, as long as you handle the padding requirements it should work. The function will automatically zero the padding bytes for you if it relies on their values

AnthonyBarbier avatar Feb 27 '18 09:02 AnthonyBarbier

I want to know about the impact on the output, if the padded elements of input are non-zeroes.

Example Scenario

If I have actual input/output size of 10, and due to the padding requirements let us say configure will change it to 16.

In this case, Does the read/write happen on the 16 values or only on the 10 values. If I give a buffer of 16 values size which as input with last 6 values are other than zeros , does it impact the output values?

Subarukun avatar Mar 01 '18 06:03 Subarukun

It depends, sometimes padding is required by vector loads, sometimes by vector store, so can't really tell if the padding bytes will be written to. However the content of the padding bytes won't affect the output: if a kernel uses the values from the padding bytes then the ACL Function will run a fill border kernel before that kernel to make sure the value of the padding bytes won't affect the output of the kernel

AnthonyBarbier avatar Mar 01 '18 08:03 AnthonyBarbier

Good to know that " padding bytes won't affect the output of the kernel" .Thanks Anthony.

Subarukun avatar Mar 02 '18 04:03 Subarukun

@Subarukun what is the reason for reopening this?

GeorgeARM avatar Mar 06 '18 16:03 GeorgeARM