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 / ssm-conv.h

82 lines · 2895 bytes Raw Blame History
1#ifndef HTP_SSM_CONV_H
2#define HTP_SSM_CONV_H
3
4#include <stdint.h>
5
6#include "hex-common.h"
7#include "hex-fastdiv.h"
8#include "htp-ops.h"
9#include "htp-vtcm.h"
10
11struct htp_ssm_conv_kernel_params {
12 uint32_t n_threads;
13 uint32_t d_conv;
14 uint32_t d_inner;
15 uint32_t n_t;
16 uint32_t n_s;
17 uint32_t d_inner_tile;
18
19 uint32_t vtcm_size;
20 uint32_t silu;
21
22 struct fastdiv_values div_d_inner_tile;
23};
24
25struct htp_ssm_conv_vtcm_layout {
26 size_t total_bytes;
27 size_t off_src0;
28 size_t off_src1;
29 size_t off_dst;
30 size_t src0_bytes_per_thread;
31 size_t src1_bytes_per_thread;
32 size_t dst_bytes_per_thread;
33 size_t src0_bytes;
34 size_t src1_bytes;
35 size_t dst_bytes;
36};
37
38static inline void htp_ssm_conv_vtcm_layout_build(
39 struct htp_ssm_conv_vtcm_layout * L,
40 uint32_t d_inner_per_thread,
41 uint32_t d_conv,
42 uint32_t n_t,
43 uint32_t d_inner_tile,
44 uint32_t n_threads
45) {
46 const size_t src1_raw_bytes = hex_round_up((size_t) d_inner_per_thread * d_conv * sizeof(float), 128) + 128;
47 const size_t src1_T_bytes = hex_round_up((size_t) d_conv * d_inner_per_thread * sizeof(float), 128);
48
49 L->src1_bytes_per_thread = src1_raw_bytes + src1_T_bytes;
50
51 if (n_t == 1) {
52 const size_t src0_tile_raw_bytes = hex_round_up((size_t) d_inner_tile * d_conv * sizeof(float), 128);
53 const size_t src0_T_bytes = hex_round_up((size_t) d_conv * d_inner_tile * sizeof(float), 128);
54 L->src0_bytes_per_thread = 2 * src0_tile_raw_bytes + src0_T_bytes;
55 L->dst_bytes_per_thread = 2 * hex_round_up((size_t) d_inner_tile * sizeof(float), 128);
56 } else {
57 const uint32_t ncs = d_conv - 1 + n_t;
58 const size_t raw_stride_bytes = ncs * sizeof(float) + sizeof(float);
59 const size_t src0_block_T = hex_round_up((size_t) ncs * 32 * sizeof(float), 128);
60 const size_t src0_tile_raw = hex_round_up((size_t) d_inner_tile * raw_stride_bytes, 128);
61 L->src0_bytes_per_thread = 2 * src0_tile_raw + src0_block_T;
62 L->dst_bytes_per_thread = 2 * hex_round_up((size_t) d_inner_tile * n_t * sizeof(float), 128);
63 }
64
65 L->src0_bytes = L->src0_bytes_per_thread * n_threads;
66 L->src1_bytes = L->src1_bytes_per_thread * n_threads;
67 L->dst_bytes = L->dst_bytes_per_thread * n_threads;
68
69 size_t off = 0;
70 VTCM_LAYOUT_ALLOC(off, off_src0, L->src0_bytes);
71 VTCM_LAYOUT_ALLOC(off, off_src1, L->src1_bytes);
72 VTCM_LAYOUT_ALLOC(off, off_dst, L->dst_bytes);
73 L->total_bytes = off;
74}
75
76#if defined(__cplusplus)
77static_assert(sizeof(struct htp_ssm_conv_kernel_params) <= 128, "htp_ssm_conv_kernel_params is too large for kernel_params blob");
78#else
79_Static_assert(sizeof(struct htp_ssm_conv_kernel_params) <= 128, "htp_ssm_conv_kernel_params is too large for kernel_params blob");
80#endif
81
82#endif // HTP_SSM_CONV_H