3#ifndef EVE_TENSOR_TENSOR_H
4#define EVE_TENSOR_TENSOR_H
50 static constexpr int kMaxRank = 6;
55 explicit Tensor(
const int *dims,
int rank);
57 explicit Tensor(
DType dtype,
const int *dims,
int rank);
63 Tensor(
int d0,
int d1,
int d2);
65 Tensor(
int d0,
int d1,
int d2,
int d3);
67 Tensor(
int d0,
int d1,
int d2,
int d3,
int d4);
69 Tensor(
int d0,
int d1,
int d2,
int d3,
int d4,
int d5);
75 bool isSymbolic()
const {
return kind_ == Kind::Symbolic; }
77 bool isEager()
const {
return kind_ == Kind::Eager; }
81 int nodeId()
const {
return nodeId_; }
88 int getDim(
int axis)
const;
116 std::vector<float> dequantized()
const;
120 const std::vector<float> &
qScales()
const {
return qScales_; }
124 const std::vector<uint8_t> &
qBytes()
const {
return bytes_; }
127 float get(
int flatIndex)
const;
129 void set(
int flatIndex,
float value);
131 float get1(
int i0)
const;
133 void set1(
int i0,
float value);
135 float get2(
int i0,
int i1)
const;
139 float get3(
int i0,
int i1,
int i2)
const;
143 float get4(
int i0,
int i1,
int i2,
int i3)
const;
145 void set4(
int i0,
int i1,
int i2,
int i3,
float value);
147 float get5(
int i0,
int i1,
int i2,
int i3,
int i4)
const;
149 void set5(
int i0,
int i1,
int i2,
int i3,
int i4,
float value);
151 float get6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5)
const;
153 void set6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5,
float value);
156 void fill(
float value);
158 void copyFrom(
const Tensor *other);
171 Tensor *addScalar(
float s)
const;
173 Tensor *subScalar(
float s)
const;
175 Tensor *mulScalar(
float s)
const;
177 Tensor *divScalar(
float s)
const;
203 Tensor *powScalar(
float exp)
const;
205 Tensor *clamp(
float lo,
float hi)
const;
207 Tensor *maximumScalar(
float s)
const;
209 Tensor *minimumScalar(
float s)
const;
212 void addInPlace(
const Tensor *other);
214 void multiplyInPlace(
const Tensor *other);
216 void addScalarInPlace(
float s);
218 void mulScalarInPlace(
float s);
223 float reduceSum()
const;
225 float reduceMean()
const;
227 float reduceMin()
const;
229 float reduceMax()
const;
231 float dot(
const Tensor *other)
const;
236 Tensor *transpose()
const;
240 Tensor *reshape1(
int d0)
const;
242 Tensor *reshape2(
int d0,
int d1)
const;
244 Tensor *reshape3(
int d0,
int d1,
int d2)
const;
246 Tensor *reshape4(
int d0,
int d1,
int d2,
int d3)
const;
248 Tensor *reshape5(
int d0,
int d1,
int d2,
int d3,
int d4)
const;
250 Tensor *reshape6(
int d0,
int d1,
int d2,
int d3,
int d4,
int d5)
const;
257 const float *data()
const;
260 void ensureEager(
const char *op)
const;
263 static int product(
const int *dims,
int rank);
271 enum class Kind { Eager, Symbolic };
273 void initDims(
DType dtype,
const int *dims,
int rank);
274 void checkSameShape(
const Tensor *other,
const char *op)
const;
275 int offset2(
int i0,
int i1)
const;
276 int offset3(
int i0,
int i1,
int i2)
const;
277 int offset4(
int i0,
int i1,
int i2,
int i3)
const;
278 int offset5(
int i0,
int i1,
int i2,
int i3,
int i4)
const;
279 int offset6(
int i0,
int i1,
int i2,
int i3,
int i4,
int i5)
const;
281 Kind kind_ = Kind::Eager;
282 Graph *graph_ =
nullptr;
285 int dims_[kMaxRank] = {0, 0, 0, 0, 0, 0};
287 DType dtype_ = DType::Float32;
288 std::vector<float> data_;
289 std::vector<uint8_t> bytes_;
290 std::vector<float> qScales_;
292 std::string device_ =
"cpu";
#define EVENGINE_API_DOMAINS
std::array< double, 10 > q
std::map< std::string, std::vector< std::string > > graph
Optimized / scheduled graph ready to run with feeds.
Trace builder — TF2 tf.function analogue (tf.func in scripts). While active, TF ops record into this ...
EVENGINE_API_DOMAINS public API.
TF2-like namespace module. Script: tf <- eve.TF(); Default eager; tf.func() traces a graph for compil...
float32 / int32 tensor (rank 1–6), row-major. Eager: owns a buffer. Symbolic: node in a Func graph (n...
Tensor * tanh() const
Tanh.
const std::vector< float > & qScales() const
Q scales.
std::string getDtype() const
Returns the dtype.
int getDim4() const
Returns the dim 4.
int qGroup() const
Q group.
bool isQuantized() const
True when quantized.
int getDim2() const
Returns the dim 2.
Tensor * sigmoid() const
Sigmoid.
int getDim3() const
Returns the dim 3.
const std::vector< uint8_t > & qBytes() const
Q bytes.
std::string getDevice() const
Returns the device.
int getSize() const
Byte length of the owned buffer.
Tensor * relu() const
Relu.
int nodeId() const
Node id.
Tensor * gelu() const
Gelu.
bool isSymbolic() const
True when symbolic.
int getDim1() const
Returns the dim 1.
int getDim0() const
Returns the dim 0.
Graph * graph() const
Graph.
int getRank() const
Returns the rank.
Tensor * sqrt() const
Sqrt.
Tensor * silu() const
Silu.
bool isEager() const
True when eager.
DType dtype() const
Dtype.
void setDtype(DType dtype)
Sets the dtype.
int getDim5() const
Returns the dim 5.
bool isQuantDType(DType dt)
True when quant d type.
bool parseDType(const std::string &name, DType &out)
Parse d type.
DType
Tensor element types.
const char * dtypeName(DType dtype)
Dtype name.