| 296 | } |
| 297 | |
| 298 | std::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()) |
no test coverage detected