|
| 1 | +#ifndef GGML_ZDNN_IMPL |
| 2 | +#define GGML_ZDNN_IMPL |
| 3 | + |
| 4 | +#include "zdnn.h" |
| 5 | +#include "ggml.h" |
| 6 | +#include "ggml-zdnn.h" |
| 7 | + |
| 8 | +#include <vector> |
| 9 | +#include <memory> |
| 10 | +#include <vecintrin.h> |
| 11 | + |
| 12 | +#define GGML_ZDNN_NAME "zDNN" |
| 13 | +#define GGML_ZDNN_VERSION ZDNN_VERNUM |
| 14 | + |
| 15 | +#define vec_neg(a) (-(a)) // Vector Negate |
| 16 | +#define vec_add(a, b) ((a) + (b)) // Vector Add |
| 17 | +#define vec_sub(a, b) ((a) - (b)) // Vector Subtract |
| 18 | +#define vec_mul(a, b) ((a) * (b)) // Vector Multiply |
| 19 | +#define vec_div(a, b) ((a) / (b)) // Vector Divide |
| 20 | +#define vec_sl(a, b) ((a) << (b)) // Vector Shift Left |
| 21 | +#define vec_sra(a, b) ((a) >> (b)) // Vector Shift Right |
| 22 | +#define vec_sr(a, b) ((a) >> (b)) // Vector Shift Right Algebraic |
| 23 | +#define vec_slo(a, b) vec_slb(a, (b) << 64) // Vector Shift Left by Octet |
| 24 | +#define vec_sro(a, b) vec_srb(a, (b) << 64) // Vector Shift Right by Octet |
| 25 | + |
| 26 | +#ifndef vec_and |
| 27 | +#define vec_and(a, b) ((a) & (b)) // Vector AND |
| 28 | +#endif |
| 29 | + |
| 30 | +#ifndef vec_or |
| 31 | +#define vec_or(a, b) ((a) | (b)) // Vector OR |
| 32 | +#endif |
| 33 | + |
| 34 | +#ifndef vec_xor |
| 35 | +#define vec_xor(a, b) ((a) ^ (b)) // Vector XOR |
| 36 | +#endif |
| 37 | + |
| 38 | +typedef signed char char8x16_t __attribute__((vector_size(16))); |
| 39 | +typedef unsigned char uchar8x16_t __attribute__((vector_size(16))); |
| 40 | + |
| 41 | +typedef int8_t int8x16_t __attribute__((vector_size(16))); |
| 42 | +typedef int16_t int16x8_t __attribute__((vector_size(16))); |
| 43 | +typedef int32_t int32x4_t __attribute__((vector_size(16))); |
| 44 | +typedef uint8_t uint8x16_t __attribute__((vector_size(16))); |
| 45 | +typedef uint16_t uint16x8_t __attribute__((vector_size(16))); |
| 46 | +typedef uint32_t uint32x4_t __attribute__((vector_size(16))); |
| 47 | + |
| 48 | +typedef float float32x4_t __attribute__((vector_size(16))); |
| 49 | +typedef double double64x2_t __attribute__((vector_size(16))); |
| 50 | + |
| 51 | +typedef signed long long long64x2_t __attribute__((vector_size(16))); |
| 52 | +typedef unsigned long long ulong64x2_t __attribute__((vector_size(16))); |
| 53 | + |
| 54 | +#define ZDNN_CHECK(stmt) \ |
| 55 | + do { \ |
| 56 | + zdnn_status status = (stmt); \ |
| 57 | + GGML_ASSERT(status == ZDNN_OK); \ |
| 58 | + } while (0); |
| 59 | + |
| 60 | +struct ggml_backend_zdnn_device_context { |
| 61 | + int zdnn_device; |
| 62 | + int zdnn_device_ref_count; |
| 63 | + |
| 64 | + bool has_parmblkformat_0; |
| 65 | + bool has_parmblkformat_1; |
| 66 | + |
| 67 | + size_t max_size; |
| 68 | + |
| 69 | + char name[128]; |
| 70 | +}; |
| 71 | + |
| 72 | +struct ggml_backend_zdnn_context { |
| 73 | + int device; |
| 74 | + ggml_cgraph * gf; |
| 75 | +}; |
| 76 | + |
| 77 | +struct ggml_backend_zdnn_buffer { |
| 78 | + void * data; |
| 79 | + size_t size; |
| 80 | + |
| 81 | + zdnn_tensor_desc pre_tfm_desc; |
| 82 | + zdnn_tensor_desc tfm_desc; |
| 83 | + zdnn_ztensor ztensor; |
| 84 | + |
| 85 | + char name[GGML_MAX_NAME]; |
| 86 | +}; |
| 87 | + |
| 88 | +struct ggml_backend_zdnn_buffer_context { |
| 89 | + void * all_data; |
| 90 | + size_t all_size; |
| 91 | + bool owned; |
| 92 | + |
| 93 | + int n_buffers; |
| 94 | + std::vector<std::unique_ptr<ggml_backend_zdnn_buffer>> buffers; |
| 95 | +}; |
| 96 | + |
| 97 | +#endif // GGML_ZDNN_IMPL |
0 commit comments