ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

How can I assign the all value of src_data1 to input0 without FOR loop?

Open duhuanxianzi opened this issue 9 years ago • 9 comments

Hi, I want to assign the value of src_data1 to input0 without FOR loop.

neon_gemmlowp.cpp . . . Tensor input0; . . . const char src_data1 = a; //a is a single-dimensional array . . . //For input0 for( int z = 0; z < ifm_src_img; ++z) { for( int y = 0; y < height_src1_image; ++y) { for( int x = 0; x < width_src1_image; ++x) { * reinterpret_cast<char>( input0.buffer() +input0.info()->offset_element_in_bytes(Coordinates(x,y,z))) = src_data1[ z * (width_src1_imageheight_src1_image) + y * width_src1_image + x]; } } } //std::cout << "Look"<<std::endl; //For input1 for( int z = 0; z < ifm_src_img; ++z) { for( int y = 0; y < height_src2_image; ++y) { for( int x = 0; x < width_src2_image; ++x) { * reinterpret_cast<char>( input1.buffer()+input1.info()->offset_element_in_bytes(Coordinates(x,y,z))) = src_data2[ z * (width_src2_image*height_src2_image) + y * width_src2_image + x]; } } } . . .

duhuanxianzi avatar May 25 '17 02:05 duhuanxianzi

Hi, you can use the iterator and execution window instead. You can memcpy each row. There is an example at https://github.com/ARM-software/ComputeLibrary/blob/master/examples/neon_copy_objects.cpp.

steniu01 avatar May 25 '17 07:05 steniu01

But this method even runs slower than my method. Is there any other method that can assign the value of src_data to input quickly without FOR loop and execution window?

duhuanxianzi avatar May 25 '17 07:05 duhuanxianzi

Unfortunately as the tensor has padding around the two-dimensional image, one can't simply memcpy the whole single dimensional array into a Tensor. You have to at least iterate each row.

steniu01 avatar May 25 '17 08:05 steniu01

Thanks a lot, I'd seek other method

duhuanxianzi avatar May 25 '17 08:05 duhuanxianzi

That's sad. I would like to be able to use the buffer directly like NNPACK.

digitalbrain79 avatar May 26 '17 00:05 digitalbrain79

we are planning zero-copy method by which you can use the buffer directly. Hopefully, it could be ready at next quarter.

steniu01 avatar May 26 '17 08:05 steniu01

Hello @duhuanxianzi,

Well you could create a tensor with the shape that you want and allocate upfront without passing it to any function which might add padding to it. Then you could directly memcpy the buffer to it, but be aware that any Function you configure with this tensor might shrink the execution window as it doesn't have the padding that a kernel might require. While this is OK for vision functions might be destructive for Neural Network ones (depending on your model).

Concerning the zero-copy method we are planning to add, I think the current limitation will be the same as the one I mentioned above. You could directly say to a tensor use this memory and do not allocate yourself but then again the tensor will lock and will have to shrink the execution window in case padding is required.

GeorgeARM avatar May 26 '17 10:05 GeorgeARM

Hi, I have solved this problem. And the efficiency of the new method is faster than before.

Thanks a lot!

duhuanxianzi avatar Jun 01 '17 10:06 duhuanxianzi

Closing. Reopen if required.

GeorgeARM avatar Jun 01 '17 10:06 GeorgeARM