Forums - How SNPE use ION buffers to avoid memory copy ?

3 posts / 0 new
Last post
How SNPE use ION buffers to avoid memory copy ?
yutianzuijin
Join Date: 20 Oct 22
Posts: 2
Posted: Fri, 2023-03-10 02:36

I find SNPE has two functions registerIonBuffers and deregisterIonBuffers, are these two functions used to avoid memory copy between cpu and dsp? If so, how to use them?

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sat, 2023-03-11 23:53

Dear developer,

You can call the API of 

bool registerIonBuffers(const zdl::DlSystem::UserMemoryMap & ionBufferMap) 

in your application directly. The parameter of ionBufferMap will allocate ION buffer according to your SNPE instance.

BR.

Wei

  • Up0
  • Down0
yutianzuijin
Join Date: 20 Oct 22
Posts: 2
Posted: Mon, 2023-03-13 02:39

Dear wei,

Thanks for your reply.

I tried three ways to use regiserIonBuffers, but none works.

1. use ioctl&mmap to alloc ION buffer beforehand, and assign the buffer to registerIonBuffers functions like:

    ioctl(ion_fd_, ION_IOC_ALLOC, &alloc_data);

   void* buffer=mmap(NULL, alloc_data.len, PROT_READ | PROT_WRITE, MAP_SHARED, alloc_data.fd, 0);

    UseMemoryMap map;

    map.add(name,buffer);

   snpe-> registerIonBuffers(map);

registerIonBuffers will return false from above pseudo code.

2. Do not alloc ION buffer in advance, and map add NULL like:

   UseMemoryMap map;

    map.add(name,NULL);

   snpe-> registerIonBuffers(map);

registerIonBuffers will also return false from above pseudo code.

3. Do not alloc ION buffer in advance, and map is empty like:

   UseMemoryMap map;

   snpe-> registerIonBuffers(map);

Nothing happened.

 

So, I just wonder whether shold I alloc ION buffer by myself or leave this work to SNPE. I want to use ION buffers because my app needs to transfer a huge data between CPU and DSP memories, alloc a ION shared buffer between them to avoid memcpy is a good choice, but I have no way to make SNPE know I alreadly alloc an ION buffer and just use it. Can you give me a tiny sample code?

Sincely,

guangchao

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.