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-vulkan / vulkan-shaders / utils.glsl

37 lines · 1059 bytes Raw Blame History
1#ifndef UTILS_COMP
2#define UTILS_COMP
3
4// mod and div are expensive and coordinates/dimensions are often power of 2 or equal to 1
5uint fastmod(uint a, uint b) {
6 if ((b & (b-1)) == 0) {
7 return a & (b-1);
8 }
9 return a % b;
10}
11
12// see init_fastdiv_values in ggml-vulkan.cpp
13uint fastdiv(uint n, uint mp, uint L) {
14 uint msbs, lsbs;
15 // msbs = mulhi(n, mp)
16 umulExtended(n, mp, msbs, lsbs);
17 return (msbs + n) >> L;
18}
19
20uint fastdiv_L(uint packed, uint slot) {
21 return (packed >> (slot * 8)) & 0x3Fu;
22}
23
24uint fastdiv_small(uint a, uint b) {
25 return (a < b) ? 0 : (a / b);
26}
27
28void get_indices(uint idx, out uint i00, out uint i01, out uint i02, out uint i03, uint ne00, uint ne01, uint ne02, uint ne03) {
29 i03 = fastdiv_small(idx, (ne02*ne01*ne00));
30 const uint i03_offset = i03 * ne02*ne01*ne00;
31 i02 = fastdiv_small((idx - i03_offset), (ne01*ne00));
32 const uint i02_offset = i02*ne01*ne00;
33 i01 = (idx - i03_offset - i02_offset) / ne00;
34 i00 = idx - i03_offset - i02_offset - i01*ne00;
35}
36
37#endif // UTILS_COMP