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 / rope-ops.h

62 lines · 2153 bytes Raw Blame History
1#ifndef HTP_ROPE_OPS_H
2#define HTP_ROPE_OPS_H
3
4#include "hex-common.h"
5#include "hex-fastdiv.h"
6#include "htp-vtcm.h"
7
8#define HTP_ROPE_SPAD_BLOCK 8
9#define HTP_ROPE_SPAD_NSLOTS 4
10#define HTP_ROPE_SPAD_NROWS (HTP_ROPE_SPAD_BLOCK * HTP_ROPE_SPAD_NSLOTS)
11
12struct htp_rope_kernel_params {
13 uint32_t n_threads;
14 uint32_t vtcm_size;
15
16 struct fastdiv_values div_ne2_ne1;
17 struct fastdiv_values div_ne1;
18};
19
20#if defined(__cplusplus)
21static_assert(sizeof(struct htp_rope_kernel_params) <= 128, "htp_rope_kernel_params is too large for kernel_params blob");
22#else
23_Static_assert(sizeof(struct htp_rope_kernel_params) <= 128, "htp_rope_kernel_params is too large for kernel_params blob");
24#endif
25
26struct htp_rope_vtcm_layout {
27 size_t total_bytes;
28 size_t off_spad;
29 size_t off_freq_factors;
30 size_t bytes_per_thread;
31 size_t theta_cache_size_aligned;
32 size_t src0_row_size_aligned;
33 size_t freq_factors_size_aligned;
34};
35
36static inline void htp_rope_vtcm_layout_build(
37 struct htp_rope_vtcm_layout * L,
38 uint32_t ne00,
39 uint32_t n_threads,
40 uint32_t n_freq_factors
41) {
42 const size_t src0_row_size = ne00 * sizeof(float);
43 const size_t src0_row_size_aligned = hex_round_up((uint32_t) src0_row_size, 128);
44 const size_t theta_cache_size_aligned = hex_round_up((uint32_t) src0_row_size, 256);
45 const size_t freq_factors_size_aligned = hex_round_up(n_freq_factors * sizeof(float), 256);
46
47 L->src0_row_size_aligned = src0_row_size_aligned;
48 L->theta_cache_size_aligned = theta_cache_size_aligned;
49 L->freq_factors_size_aligned = freq_factors_size_aligned;
50 L->bytes_per_thread = theta_cache_size_aligned + HTP_ROPE_SPAD_NROWS * src0_row_size_aligned;
51
52 size_t off = 0;
53 VTCM_LAYOUT_ALLOC(off, off_spad, L->bytes_per_thread * n_threads);
54 VTCM_LAYOUT_ALLOC_OPTIONAL(off, off_freq_factors, freq_factors_size_aligned, n_freq_factors > 0);
55 L->total_bytes = off;
56}
57
58static inline uint8_t * rope_spad_slot(uint8_t * base, uint32_t slot, size_t row_size_aligned) {
59 return base + (slot * HTP_ROPE_SPAD_BLOCK) * row_size_aligned;
60}
61
62#endif // HTP_ROPE_OPS_H