MCPcopy Create free account
hub / github.com/ARM-software/armnn / GetUIntBuffer

Function GetUIntBuffer

src/armnnTfLiteParser/TfLiteParser.cpp:298–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296}
297
298std::vector<unsigned int> GetUIntBuffer(armnn::TensorInfo info,
299 const TfLiteParserImpl::ModelPtr& model,
300 size_t bufferIndex)
301{
302 TfLiteParserImpl::BufferRawPtr bufferPtr = TfLiteParserImpl::GetBuffer(model, bufferIndex);
303
304 if (!bufferPtr || bufferPtr->data.empty())
305 {
306 throw ParseException("UInt buffer is null or empty.");
307 }
308
309 const size_t numElements = info.GetNumElements();
310 std::vector<unsigned int> buffer(info.GetNumElements());
311 buffer.reserve(numElements);
312
313 if (info.GetDataType() == DataType::Signed32)
314 {
315 size_t requiredBytes = numElements * sizeof(int32_t);
316 if (bufferPtr->data.size() < requiredBytes)
317 {
318 throw ParseException("UInt buffer too small for Signed32 tensor.");
319 }
320
321 ::memcpy(buffer.data(), bufferPtr->data.data(), requiredBytes);
322 }
323 else if (info.GetDataType() == DataType::Signed64)
324 {
325 size_t requiredBytes = numElements * sizeof(int64_t);
326 if (bufferPtr->data.size() < requiredBytes)
327 {
328 throw ParseException("UInt buffer too small for Signed64 tensor.");
329 }
330
331 std::vector<uint64_t> uint64Buffer(numElements);
332 ::memcpy(uint64Buffer.data(), bufferPtr->data.data(), requiredBytes);
333 buffer.assign(std::begin(uint64Buffer), std::end(uint64Buffer));
334 }
335 else
336 {
337 CheckLocation location = CHECK_LOCATION();
338 throw ParseException(
339 fmt::format("Unsupported data type for uint buffer {}, only Signed 32 or Signed 64 are supported. {}",
340 GetDataTypeName(info.GetDataType()),
341 location.AsString()));
342 }
343 return buffer;
344}
345
346#define CHECK_BUFFER_SIZE(BUFFER_PTR, TENSOR_INFO, BUFFER_ID) \
347 CheckBufferSize(BUFFER_PTR, TENSOR_INFO, BUFFER_ID, CHECK_LOCATION())

Callers 1

ParsePadMethod · 0.85

Calls 13

ParseExceptionClass · 0.85
beginFunction · 0.85
endFunction · 0.85
formatEnum · 0.85
GetDataTypeNameFunction · 0.85
emptyMethod · 0.80
GetNumElementsMethod · 0.45
reserveMethod · 0.45
GetDataTypeMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected