char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Safi Ullahvulkan : added the PAD_REFLECT_1D operation (#26586)3f545becc

char/aliceai-t5-moe
1.3 KiB43 linesraw
1#version 450
2
3#include "types.glsl"
4#include "generic_unary_head.glsl" // included to use functions like fastdiv etc.
5
6layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
7
8void main() {
9
10    const uint idx = get_idx();
11
12    if (idx >= p.ne) {
13        return;
14    }
15
16    const uint p0 = floatBitsToUint(p.param1);
17    const uint p1 = floatBitsToUint(p.param2);
18
19    const uint i3 = fastdiv(idx, p.ne1_012mp, fastdiv_L(p.ne1_Ls, 0));
20    const uint i3_offset = i3 * p.ne12 * p.ne11 * p.ne10;
21
22    const uint i2 = fastdiv(idx - i3_offset, p.ne1_01mp, fastdiv_L(p.ne1_Ls, 1));
23    const uint i2_offset = i2 * p.ne11 * p.ne10;
24
25    const uint i1 = fastdiv(idx - i3_offset - i2_offset, p.ne1_0mp, fastdiv_L(p.ne1_Ls, 2));
26    const uint i0 = idx - i3_offset - i2_offset - i1 * p.ne10;
27
28    uint src_col;
29
30    if (i0 < p0) {
31        src_col = p0 - i0;    // left pad area
32    } else if (i0 < p0 + p.ne00) {
33        src_col = i0 - p0;    // center area
34    } else {
35        src_col = 2u * p.ne00 - 2u - (i0 - p0);  // right pad area
36    }
37
38    const uint src_idx = i3 * p.nb03 + i2 * p.nb02 + i1 * p.nb01 + src_col * p.nb00;
39    const uint d_idx = i3 * p.nb13 + i2 * p.nb12 + i1 * p.nb11 + i0 * p.nb10;
40
41    // copy the computed value to the destination tensor
42    data_d[get_doffset() + d_idx] = D_TYPE(data_a[get_aoffset() + src_idx]);
43}