Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-hexagon/htp-common.h # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 7 struct htp_tensor_extra { 8 std::vector shadow_buf; 9 size_t shadow_size { 0 }; 10 uint32_t flags { 0 }; 11 }; 12 13 extern int opt_arch; 14 extern size_t opt_ndev; 15 extern size_t opt_nhvx; 16 extern int opt_nhmx; 17 extern size_t opt_vmem; 18 extern int opt_etm; 19 extern int opt_verbose; 20 extern int opt_profile; 21 extern bool opt_hostbuf; 22 extern bool opt_dma64; 23 extern int opt_power_mode; 24 25 extern size_t opt_mbuf_dyn; 26 extern size_t opt_mbuf_static; 27 extern size_t opt_mbuf_total; 28 29 extern int opt_mm_select; 30 extern int opt_fa_select; 31 extern int opt_fa_split; 32 extern int opt_li_select; 33 extern int opt_gdn_select; 34 extern int opt_ar_select; 35 extern int opt_ar_scatter; 36 37 extern int opt_opbatch; 38 extern int opt_opqueue; 39 extern int opt_optrace; 40 extern int opt_oppoll; 41 extern int opt_opfusion; 42 extern 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 49 static 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 55 static 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 65 static 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 73 static 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 81 static 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 90 static 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 97 struct ggml_hexagon_session; 98 99 const char * htp_session_name(const struct ggml_hexagon_session * sess); 100 size_t htp_session_vtcm_size(const struct ggml_hexagon_session * sess); 101 uint32_t htp_session_n_threads(const struct ggml_hexagon_session * sess); 102 uint32_t htp_session_n_hmx(const struct ggml_hexagon_session * sess); 103 uint32_t htp_session_mdev_count(const struct ggml_hexagon_session * sess); 104 105 htp_op_code htp_op_remap(const struct ggml_tensor * t); 106 107 #endif // HTP_COMMON_H