/home/runner/work/LabNeura/LabNeura/include/labneura/backends/common/base.h
Line | Count | Source |
1 | | #pragma once |
2 | | #include <memory> |
3 | | #include "labneura/tensor.h" |
4 | | #include "labneura/visibility.h" |
5 | | |
6 | | namespace labneura { |
7 | | |
8 | | class LABNEURA_API TensorBackend { |
9 | | public: |
10 | 2.08k | virtual ~TensorBackend() = default; |
11 | | |
12 | | // ---- Metadata ---- |
13 | | virtual std::size_t size() const = 0; |
14 | | virtual QuantizationMode quantization_mode() const = 0; |
15 | | |
16 | | // ---- Raw data access ---- |
17 | | virtual float* data_fp32() = 0; |
18 | | virtual const float* data_fp32() const = 0; |
19 | | virtual int8_t* data_int8() = 0; |
20 | | virtual const int8_t* data_int8() const = 0; |
21 | | // Optional FP16/INT16 accessors (default throw) |
22 | | virtual int16_t* data_fp16(); |
23 | | virtual const int16_t* data_fp16() const; |
24 | | virtual int16_t* data_int16(); |
25 | | virtual const int16_t* data_int16() const; |
26 | | |
27 | | // ---- Cloning ---- |
28 | | virtual std::unique_ptr<TensorBackend> clone() const = 0; |
29 | | |
30 | | // ---- Public operations (NON-virtual interface) ---- |
31 | | void add_inplace(const TensorBackend& other); |
32 | | void sub_inplace(const TensorBackend& other); |
33 | | void mul_inplace(const TensorBackend& other); |
34 | | void div_inplace(const TensorBackend& other); |
35 | | void operation(const TensorBackend& other, OperationType op); |
36 | | |
37 | | protected: |
38 | | // ---- Backend-specific kernels (virtual hooks) ---- |
39 | | virtual void operation_fp32(const TensorBackend& other, OperationType op) = 0; |
40 | | virtual void operation_int8(const TensorBackend& other, OperationType op) = 0; |
41 | | // Optional FP16/INT16 kernels (default throw) |
42 | | virtual void operation_fp16(const TensorBackend& other, OperationType op); |
43 | | virtual void operation_int16(const TensorBackend& other, OperationType op); |
44 | | }; |
45 | | |
46 | | } // namespace labneura |