41 for (
const auto &v :
vect)
53template <loco::DataType DT>
65 assert(raw_data.
size() == num_elements *
sizeof(T));
66 const auto *
data =
reinterpret_cast<const T *
>(raw_data.
data());
81 const auto *
data =
reinterpret_cast<const char *
>(raw_data.
data());
82 const auto *
i32d =
reinterpret_cast<const int32_t *
>(raw_data.
data());
91 std::vector<int32_t> offsets;
92 offsets.push_back(*
i32d++);
95 offsets.push_back(*
i32d++);
97 assert(offsets.size() == num_elements + 1);
102 int32_t start = offsets[
i];
103 int32_t next = offsets[
i + 1];
105 std::string value(
data + start, next - start);
106 const_node->
at<loco::DataType::STRING>(
i) = value;
113template <loco::DataType DT>
133 const_node->
at<
DT>(
idx) =
static_cast<T
>(
data[
i] << 4) >> 4;
134 if (
idx + 1 < num_elements)
136 const_node->
at<
DT>(
idx + 1) =
static_cast<T
>(
data[
i]) >> 4;
152 auto graph = context->
graph();
153 auto reader = context->
reader();
154 const auto tensors = reader->
tensors();
163 const auto r_buffers = reader->buffers();
170 throw std::runtime_error(
"CircleConst: Circle file with invalid extended Buffer.");
178 if (
r_buffer->size() >= std::numeric_limits<uint32_t>::max())
181 throw std::runtime_error(
"CircleConst: Circle file with invalid extended Buffer.");
236 if (buffer.
empty() && num_elements > 0)
242 auto const_node = graph->nodes()->create<
CircleConst>();
245 INFO(l) <<
"[luci] NodeFinder const_node(" <<
tensor_index <<
") -> " << const_node <<
" "
247 if (num_elements > 0)
251 case loco::DataType::FLOAT32:
255 case loco::DataType::FLOAT16:
259 case loco::DataType::U4:
263 case loco::DataType::U8:
267 case loco::DataType::S4:
271 case loco::DataType::S8:
275 case loco::DataType::S16:
279 case loco::DataType::S32:
283 case loco::DataType::S64:
287 case loco::DataType::BOOL:
291 case loco::DataType::STRING:
Class to build tensor data.
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
uint32_t size(void) const
CircleNode * build(TensorIndex tensor_index, GraphBuilderContext *ctx) const final
CircleTensors tensors() const
Class to store context to build loco graph IR from TensorFlow.
IndexTensorOutputs * tensoroutputs()
Wrapper to use flatbuffers::Vector pointer as std::vector entity.
std::ostream & operator<<(std::ostream &os, const Shape &shape)
Print the shape in format [1, 2, 3].
const T * data(const std::vector< T, Alloc > &v)
loco::DataType luci_datatype(circle::TensorType type)
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
Copy common tensor attributes such as name, type, etc. to node.
T must_cast(loco::Node *node)
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
C++ scalar type corresponding to each DataType.
SparsityParam * sparsityparam(void) const
ShapeStatus shape_status(void) const