Forums - UDLContext uses incorrect data type to store blob

4 posts / 0 new
Last post
UDLContext uses incorrect data type to store blob
gino0
Join Date: 26 May 19
Posts: 12
Posted: Mon, 2019-07-01 23:26

I am using SNPE 1.27.1.382 and I am following the UDL tutorial https://developer.qualcomm.com/docs/snpe/udl_tutorial.html.

I am experiencing a problem with packing and unpacking the blob data. On the Python converter side, I am packing 4-byte integers, which could result in packing "0x00" bytes (for example, 5 is packed as \x05\x00\x00\x00). 

self._blob  # 112\x00\x18\x00\x02\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\x01\x00\x00\x80...

This seems to be a problem on the runtime side, because the UDLContext class (include/zdl/DlSystem/UDLContext.hpp) seems to store the blob as a std::string, which truncates on `0x00` bytes. So the data received on the UDL factory callback is already truncated. 

const void *blob = c->getBlob();     # c.m_Buffer = "112"
const int blobSize = c->getSize();   # c.m_Size = 3
The UDLContext object stores the blob as std::string, which truncates on the 4th byte \x00. The resulting m_Size(blob.size()) is now only 3, and then UDLContext initializes m_Buffer by copying m_Size bytes from the blob. So only the first 3 bytes are copied. The rest of the data is not copied over to m_Buffer. All of the UDL callbacks then become useless because the rest of the blob data is missing.
 
Here is the code for the UDLContext.hpp constructor:
 
UDLContext(const std::string& name,
           const std::string& type,
           int32_t id,
           const std::string& blob) :
    m_Name(name), m_Type(type), m_Size(blob.size()), m_Id(id) {
    std::cout << blob << std::endl;
    // FIXME not dealing with alloc error
    m_Buffer = new uint8_t[m_Size];
    std::memcpy(m_Buffer, blob.data(), m_Size);
}
 
Notice that blob is a std::string and that m_Buffer allocation is based on string.size which truncates on null characters.
 
Am I missing something here? 
  • Up0
  • Down0
gino0
Join Date: 26 May 19
Posts: 12
Posted: Wed, 2019-07-03 00:30

The issue is reproducible with the sample UDL codes from the tutorial.

  • $SNPE_ROOT/examples/Python/UdlExample
  • $SNPE_ROOT/examples/NativeCpp/UdlExample

 

The blob size returned by snpe-dlc-info and by the UDLContext is 1 (which is because the layer type is \x01\x00\x00\x00).

This is different from what is displayed on the tutorial where the blob size is 2017.

 

  • Up0
  • Down0
luochenchi
Join Date: 3 Aug 17
Posts: 1
Posted: Tue, 2019-07-09 20:30

This problem exists since 1.25. The last working UDL version is 1.24. Interestingly, 'include/zdl/DlSystem/UDLContext.hpp' has not changed from 1.24 and 1.25. Hope, SNPE team come up and fix it. Your offical UDL example is NOT working.

  • Up0
  • Down0
gino0
Join Date: 26 May 19
Posts: 12
Posted: Wed, 2019-07-10 02:45

The problem is indeed fixed by using an older SNPE, specifically 1.24.0.256.  

The blob size and contents are now correct.

You can download the older version from here: https://developer.qualcomm.com/downloads/neural-processing-sdk-ai-v1240?...

Do not use 1.25, 1.26, and 1.27 if you want to use UDLs.

  • 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.