ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Tensor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __CIRCLE_EVAL_DIFF_TENSOR_H__
18#define __CIRCLE_EVAL_DIFF_TENSOR_H__
19
20#include <loco.h>
22
23#include <vector>
24
25namespace circle_eval_diff
26{
27
29{
30public:
31 const loco::DataType &dtype(void) const { return _dtype; }
32 void dtype(const loco::DataType &dtype) { _dtype = dtype; }
33
34private:
35 loco::DataType _dtype = loco::DataType::Unknown;
36};
37
39{
40public:
41 uint32_t rank(void) const { return _dims.size(); }
42 void rank(uint32_t value) { _dims.resize(value); }
43
44 const loco::Dimension &dim(uint32_t axis) const { return _dims.at(axis); }
45 loco::Dimension &dim(uint32_t axis) { return _dims.at(axis); }
46
47 void shape(std::initializer_list<uint32_t> dims)
48 {
49 rank(dims.size());
50
51 uint32_t axis = 0;
52 for (auto d : dims)
53 {
54 dim(axis++) = d;
55 }
56 }
57
58private:
59 std::vector<loco::Dimension> _dims;
60};
61
62// Tensor has three kinds of data
63// 1. DataType (_dtype)
64// 2. Shape (_dims)
65// 3. Buffer (_data)
66struct Tensor final : public TensorShape, public TensorDataType
67{
68public:
69 template <loco::DataType DT> uint32_t size(void) const;
70 template <loco::DataType DT> void size(uint32_t size);
71 template <loco::DataType DT> const typename loco::DataTypeImpl<DT>::Type &at(uint32_t n) const;
72 template <loco::DataType DT> typename loco::DataTypeImpl<DT>::Type &at(uint32_t n);
73 uint8_t *buffer(void) { return _data.data(); }
74 uint32_t byte_size(void) const { return _data.size(); }
75
76private:
77 std::vector<uint8_t> _data;
78};
79
80std::shared_ptr<Tensor> createEmptyTensor(const luci::CircleNode *node);
81
82} // namespace circle_eval_diff
83
84#endif // __CIRCLE_EVAL_DIFF_TENSOR_H__
The value of one dimension in a tensor shape.
Definition Dimension.h:30
std::shared_ptr< Tensor > createEmptyTensor(const luci::CircleNode *node)
Definition Tensor.cpp:90
DataType
"scalar" value type
Definition DataType.h:27
void dtype(const loco::DataType &dtype)
Definition Tensor.h:32
const loco::DataType & dtype(void) const
Definition Tensor.h:31
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
Definition Tensor.cpp:58
uint8_t * buffer(void)
Definition Tensor.h:73
uint32_t size(void) const
Definition Tensor.cpp:44
uint32_t byte_size(void) const
Definition Tensor.h:74
void shape(std::initializer_list< uint32_t > dims)
Definition Tensor.h:47
loco::Dimension & dim(uint32_t axis)
Definition Tensor.h:45
const loco::Dimension & dim(uint32_t axis) const
Definition Tensor.h:44
uint32_t rank(void) const
Definition Tensor.h:41
void rank(uint32_t value)
Definition Tensor.h:42
C++ scalar type corresponding to each DataType.