interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-hexagon / htp-common.h

107 lines · 3245 bytes Raw Blame History
1#ifndef HTP_COMMON_H
2#define HTP_COMMON_H
3
4#include "htp-opnode.h"
5#include "htp-repack.h"
6
7struct htp_tensor_extra {
8 std::vector<uint8_t> shadow_buf;
9 size_t shadow_size { 0 };
10 uint32_t flags { 0 };
11};
12
13extern int opt_arch;
14extern size_t opt_ndev;
15extern size_t opt_nhvx;
16extern int opt_nhmx;
17extern size_t opt_vmem;
18extern int opt_etm;
19extern int opt_verbose;
20extern int opt_profile;
21extern bool opt_hostbuf;
22extern bool opt_dma64;
23extern int opt_power_mode;
24
25extern size_t opt_mbuf_dyn;
26extern size_t opt_mbuf_static;
27extern size_t opt_mbuf_total;
28
29extern int opt_mm_select;
30extern int opt_fa_select;
31extern int opt_fa_split;
32extern int opt_li_select;
33extern int opt_gdn_select;
34extern int opt_ar_select;
35extern int opt_ar_scatter;
36
37extern int opt_opbatch;
38extern int opt_opqueue;
39extern int opt_optrace;
40extern int opt_oppoll;
41extern int opt_opfusion;
42extern int opt_rt_repack;
43
44#ifndef HEX_VERBOSE
45#define HEX_VERBOSE(...) \
46 if (opt_verbose) GGML_LOG_DEBUG(__VA_ARGS__)
47#endif
48
49static inline bool htp_tensor_is_fuseable(const struct ggml_tensor * t) {
50 if (!t || !t->extra) return false;
51 const auto * extra = (const struct htp_tensor_extra *) t->extra;
52 return (extra->flags & HTP_TENSOR_FUSEABLE) != 0;
53}
54
55static inline bool htp_can_rt_repack(const struct ggml_tensor * t) {
56 if (opt_rt_repack == 0 || !htp_is_tiled_weight_tensor(t)) {
57 return false;
58 }
59 if (t->buffer && ggml_backend_buft_is_host(t->buffer->buft)) {
60 return false;
61 }
62 return opt_rt_repack > 1 || ggml_is_quantized(t->type);
63}
64
65static inline bool htp_tensor_is_tiled(const struct ggml_tensor * t) {
66 const auto * extra = (const struct htp_tensor_extra *) t->extra;
67 if (extra && (extra->flags & HTP_TENSOR_TILED)) {
68 return true;
69 }
70 return htp_can_rt_repack(t);
71}
72
73static inline bool htp_needs_repack(const struct ggml_tensor * t) {
74 const auto * extra = (const struct htp_tensor_extra *) t->extra;
75 if (extra && (extra->flags & HTP_TENSOR_TILED)) {
76 return false;
77 }
78 return htp_can_rt_repack(t);
79}
80
81static inline bool htp_tensors_overlap(const struct ggml_tensor * a, const struct ggml_tensor * b) {
82 const uintptr_t a0 = (uintptr_t) a->data;
83 const uintptr_t b0 = (uintptr_t) b->data;
84 const uintptr_t a1 = a0 + ggml_nbytes(a);
85 const uintptr_t b1 = b0 + ggml_nbytes(b);
86
87 return a0 < b1 && b0 < a1;
88}
89
90static inline bool htp_can_row_partition(const struct ggml_tensor * t) {
91 if (t->ne[1] > 1 && (t->nb[1] & 127) != 0) return false;
92 if (t->ne[2] > 1 && (t->nb[2] & 127) != 0) return false;
93 if (t->ne[3] > 1 && (t->nb[3] & 127) != 0) return false;
94 return true;
95}
96
97struct ggml_hexagon_session;
98
99const char * htp_session_name(const struct ggml_hexagon_session * sess);
100size_t htp_session_vtcm_size(const struct ggml_hexagon_session * sess);
101uint32_t htp_session_n_threads(const struct ggml_hexagon_session * sess);
102uint32_t htp_session_n_hmx(const struct ggml_hexagon_session * sess);
103uint32_t htp_session_mdev_count(const struct ggml_hexagon_session * sess);
104
105htp_op_code htp_op_remap(const struct ggml_tensor * t);
106
107#endif // HTP_COMMON_H