Skip to content

Commit 64bb149

Browse files
committed
data b cache example, slower than original
1 parent 860159c commit 64bb149

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_q6_k.comp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ layout (constant_id = 1) const uint NUM_ROWS = 1;
1212
shared FLOAT_TYPE tmpsh[NUM_ROWS][BLOCK_SIZE];
1313
shared FLOAT_TYPE sccache[BLOCK_SIZE/16][16];
1414
shared block_q6_K_packed16 blkcache[BLOCK_SIZE/16];
15+
shared B_TYPE bycache[BLOCK_SIZE/16][QUANT_K];
1516

1617
void compute_outputs(const uint32_t first_row, const uint32_t num_rows) {
1718
uint a_offset, b_offset, d_offset;
@@ -34,7 +35,6 @@ void compute_outputs(const uint32_t first_row, const uint32_t num_rows) {
3435
const uint ql_offset = 64*v_im + l0;
3536
const uint qh_offset = 32*v_im + l0;
3637
const uint s_offset = 8*v_im + is;
37-
const uint y_offset = 128*v_im + l0;
3838
const uint bcs_offset = (itid%2 == 1) ? 8 : 0;
3939

4040
FLOAT_TYPE temp[NUM_ROWS];
@@ -45,12 +45,16 @@ void compute_outputs(const uint32_t first_row, const uint32_t num_rows) {
4545

4646
[[unroll]] for (uint i0 = 0; i0 < num_blocks_per_row; i0 += it_size) {
4747
uint i = i0 + ix; // 16 thread group specific counter
48-
const uint y_idx = i * QUANT_K + y_offset;
48+
const uint y_idx = i0 * QUANT_K;
49+
const int blim = min(int(num_blocks_per_row) - int(i0), 4);
4950

50-
B_TYPE_VEC4 by0 = data_b_v4[(b_offset + y_idx) / 4];
51-
B_TYPE_VEC4 by32 = data_b_v4[(b_offset + y_idx) / 4 + 8];
52-
B_TYPE_VEC4 by64 = data_b_v4[(b_offset + y_idx) / 4 + 16];
53-
B_TYPE_VEC4 by96 = data_b_v4[(b_offset + y_idx) / 4 + 24];
51+
// assume 64 threads
52+
[[unroll]] for (int n = 0; n < blim; ++n) {
53+
[[unroll]] for (int l = 0; l < 4; ++l) {
54+
bycache[n][tid + 64*l] = data_b[b_offset + y_idx + QUANT_K*n + tid + 64*l];
55+
}
56+
}
57+
barrier();
5458

5559
uint ibi = first_row*num_blocks_per_row;
5660
[[unroll]] for (uint n = 0; n < num_rows; ++n) {
@@ -59,7 +63,6 @@ void compute_outputs(const uint32_t first_row, const uint32_t num_rows) {
5963

6064
// cache full superblock into shared memory with coalesced reads
6165
// we assume 64 threads here!
62-
const int blim = min(int(num_blocks_per_row) - int(i0), 4);
6366
// this is required as this loop is super sensitive to unrolling with hardcoded 4
6467
if (blim == 4) {
6568
if (tid < 52) {
@@ -109,10 +112,10 @@ void compute_outputs(const uint32_t first_row, const uint32_t num_rows) {
109112

110113
FLOAT_TYPE sum[4] = {0, 0, 0, 0};
111114
[[unroll]] for (uint l = 0; l < 4; ++l) {
112-
sum[0] = fma(FLOAT_TYPE(by0[l]), FLOAT_TYPE(int8_t(q0[l]) - 32), sum[0]);
113-
sum[1] = fma(FLOAT_TYPE(by32[l]), FLOAT_TYPE(int8_t(q1[l]) - 32), sum[1]);
114-
sum[2] = fma(FLOAT_TYPE(by64[l]), FLOAT_TYPE(int8_t(q2[l]) - 32), sum[2]);
115-
sum[3] = fma(FLOAT_TYPE(by96[l]), FLOAT_TYPE(int8_t(q3[l]) - 32), sum[3]);
115+
sum[0] = fma(FLOAT_TYPE(bycache[ix][128*v_im + l0 + l]), FLOAT_TYPE(int8_t(q0[l]) - 32), sum[0]);
116+
sum[1] = fma(FLOAT_TYPE(bycache[ix][128*v_im + l0 + 32 + l]), FLOAT_TYPE(int8_t(q1[l]) - 32), sum[1]);
117+
sum[2] = fma(FLOAT_TYPE(bycache[ix][128*v_im + l0 + 64 + l]), FLOAT_TYPE(int8_t(q2[l]) - 32), sum[2]);
118+
sum[3] = fma(FLOAT_TYPE(bycache[ix][128*v_im + l0 + 96 + l]), FLOAT_TYPE(int8_t(q3[l]) - 32), sum[3]);
116119
}
117120

118121
[[unroll]] for (uint l = 0; l < 4; ++l)

0 commit comments

Comments
 (0)