ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnkit::support::tf::TensorDataMap Class Reference

Class to map parsed tensor and memory for tensor values. For parsed tensor, this memory is used to fill input or output values of graph. More...

#include <TensorDataMap.h>

Public Member Functions

 TensorDataMap ()
 
uint8_t * allocate (const ParsedTensor *parsed_tensor)
 
uint8_t * data (const ParsedTensor *parsed_tensor)
 

Detailed Description

Class to map parsed tensor and memory for tensor values. For parsed tensor, this memory is used to fill input or output values of graph.

Definition at line 41 of file TensorDataMap.h.

Constructor & Destructor Documentation

◆ TensorDataMap()

nnkit::support::tf::TensorDataMap::TensorDataMap ( )
inline

Definition at line 44 of file TensorDataMap.h.

45 { /* empty */
46 }

Member Function Documentation

◆ allocate()

uint8_t * nnkit::support::tf::TensorDataMap::allocate ( const ParsedTensor parsed_tensor)
inline

Definition at line 48 of file TensorDataMap.h.

49 {
50 auto it = _data_map.find(parsed_tensor);
51 if (it != _data_map.end())
52 throw std::runtime_error("Already allocated");
53
54 int bytes = 0;
55 if (parsed_tensor->isFloatTensor())
56 bytes = sizeof(float);
57 else
58 throw std::runtime_error("Unsupported or wrong data type");
59
60 uint64_t size = num_elements(parsed_tensor->shape()) * bytes;
61 _data_map[parsed_tensor] = std::move(std::unique_ptr<uint8_t[]>(new uint8_t[size]));
62
63 return _data_map[parsed_tensor].get();
64 }
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
int32_t size[5]
Definition Slice.cpp:35

References nnkit::support::tftestinfo::ParsedTensor::isFloatTensor(), nnkit::support::tftestinfo::ParsedTensor::shape(), and size.

Referenced by nnkit::support::tf::Backend::prepare(), and nnkit::support::tf::Backend::run().

◆ data()

uint8_t * nnkit::support::tf::TensorDataMap::data ( const ParsedTensor parsed_tensor)
inline

Definition at line 66 of file TensorDataMap.h.

67 {
68 auto it = _data_map.find(parsed_tensor);
69 if (it == _data_map.end())
70 throw std::runtime_error("Cannot find parsed tensor");
71
72 return it->second.get();
73 }

Referenced by nnkit::support::tf::TensorContext::getConstFloatTensor(), nnkit::support::tf::TensorContext::getMutableFloatTensor(), and nnkit::support::tf::Runner::prepareInputs().


The documentation for this class was generated from the following file: