Skip to content

Commit 243d354

Browse files
authored
Merge branch 'ggml-org:master' into mradermacher
2 parents 369a3aa + 08f9d3c commit 243d354

File tree

3 files changed

+105
-22
lines changed

3 files changed

+105
-22
lines changed

.github/actions/windows-setup-cuda/action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,34 @@ runs:
6565
echo "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\libnvvp" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
6666
echo "CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
6767
echo "CUDA_PATH_V12_4=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
68+
69+
- name: Install Cuda Toolkit 13.1
70+
if: ${{ inputs.cuda_version == '13.1' }}
71+
shell: pwsh
72+
run: |
73+
mkdir -p "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1"
74+
choco install unzip -y
75+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_crt/windows-x86_64/cuda_crt-windows-x86_64-13.1.80-archive.zip"
76+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_cudart/windows-x86_64/cuda_cudart-windows-x86_64-13.1.80-archive.zip"
77+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvcc/windows-x86_64/cuda_nvcc-windows-x86_64-13.1.80-archive.zip"
78+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvrtc/windows-x86_64/cuda_nvrtc-windows-x86_64-13.1.80-archive.zip"
79+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/libcublas/windows-x86_64/libcublas-windows-x86_64-13.2.0.9-archive.zip"
80+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/libnvvm/windows-x86_64/libnvvm-windows-x86_64-13.1.80-archive.zip"
81+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvtx/windows-x86_64/cuda_nvtx-windows-x86_64-13.1.68-archive.zip"
82+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_profiler_api/windows-x86_64/cuda_profiler_api-windows-x86_64-13.1.80-archive.zip"
83+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/visual_studio_integration/windows-x86_64/visual_studio_integration-windows-x86_64-13.1.68-archive.zip"
84+
curl -O "https://developer.download.nvidia.com/compute/cuda/redist/cuda_cccl/windows-x86_64/cuda_cccl-windows-x86_64-13.1.78-archive.zip"
85+
unzip '*.zip' -d "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1"
86+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_crt-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
87+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_cudart-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
88+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_nvcc-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
89+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_nvrtc-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
90+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\libcublas-windows-x86_64-13.2.0.9-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
91+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\libnvvm-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
92+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_nvtx-windows-x86_64-13.1.68-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
93+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_profiler_api-windows-x86_64-13.1.80-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
94+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\visual_studio_integration-windows-x86_64-13.1.68-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
95+
xcopy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\cuda_cccl-windows-x86_64-13.1.78-archive\*" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" /E /I /H /Y
96+
echo "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
97+
echo "CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
98+
echo "CUDA_PATH_V13_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ jobs:
421421

422422
strategy:
423423
matrix:
424-
cuda: ['12.4']
424+
cuda: ['12.4', '13.1']
425425

426426
steps:
427427
- name: Clone
@@ -476,6 +476,7 @@ jobs:
476476
$dst='.\build\bin\cudart\'
477477
robocopy "${{env.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
478478
robocopy "${{env.CUDA_PATH}}\lib" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
479+
robocopy "${{env.CUDA_PATH}}\bin\x64" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
479480
7z a cudart-llama-bin-win-cuda-${{ matrix.cuda }}-x64.zip $dst\*
480481
481482
- name: Upload Cuda runtime
@@ -835,7 +836,8 @@ jobs:
835836
**Windows:**
836837
- [Windows x64 (CPU)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-cpu-x64.zip)
837838
- [Windows arm64 (CPU)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-cpu-arm64.zip)
838-
- [Windows x64 (CUDA)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-cuda-12.4-x64.zip)
839+
- [Windows x64 (CUDA 12)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-cuda-12.4-x64.zip)
840+
- [Windows x64 (CUDA 13)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-cuda-13.1-x64.zip)
839841
- [Windows x64 (Vulkan)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-vulkan-x64.zip)
840842
- [Windows x64 (SYCL)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-sycl-x64.zip)
841843
- [Windows x64 (HIP)](https://github.com/ggml-org/llama.cpp/releases/download/${{ steps.tag.outputs.name }}/llama-${{ steps.tag.outputs.name }}-bin-win-hip-radeon-x64.zip)

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

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,85 @@ layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in;
77

88
FLOAT_TYPE temp[NUM_COLS][NUM_ROWS];
99

10-
void calc_superblock(const uint a_offset, const uint b_offset, const uint ib32, const uint i, const uint num_blocks_per_row, const uint first_row, const uint num_rows) {
10+
void calc_superblock(const uint a_offset, const uint b_offset, const uint ib32, const uint i,
11+
const uint num_blocks_per_row, const uint first_row, const uint num_rows) {
12+
// Compute starting index in matrix B for this superblock
1113
const uint y_idx = i * QUANT_K + 32 * ib32;
12-
1314
uint ibi = a_offset / QUANT_K + first_row * num_blocks_per_row + i;
15+
16+
// Precompute indices for quantization lookup tables
17+
const uint qh_base = 2 * ib32;
18+
const uint qs_base = 4 * ib32;
19+
const uint sc_index = ib32 / 2;
20+
const uint sc_shift = 6 * (ib32 & 1);
21+
22+
// Loop over rows in the superblock
1423
[[unroll]] for (uint n = 0; n < num_rows; ++n) {
24+
// Load per-block scales and shift for quantization
1525
const uint16_t[4] scales = data_a[ibi].scales;
1626
const u16vec4 s = u16vec4(scales[0], scales[1], scales[2], scales[3]) >> 12;
1727
const float d = float(unpackHalf2x16(s.x | (s.y << 4) | (s.z << 8) | (s.w << 12)).x);
28+
const uint sc = data_a[ibi].scales[sc_index] >> sc_shift;
1829

19-
const uint sc = data_a[ibi].scales[ib32 / 2] >> (6 * (ib32 & 1));
30+
// Temporary caches for decoding
31+
FLOAT_TYPE dl_cache[4];
32+
uint16_t gvf_cache[4];
33+
float delta_cache[4];
34+
35+
// Precompute the multiplier and lookup values for 4 sub-blocks
2036
[[unroll]] for (uint l = 0; l < 4; ++l) {
21-
const uint qh = data_a[ibi].qh[2 * ib32 + l / 2] >> (4 * (l&1));
22-
const uint qs = data_a[ibi].qs[4 * ib32 + l];
23-
const float delta = ((qh & 8) != 0) ? -IQ1M_DELTA : IQ1M_DELTA;
24-
const float dl = d * (2 * bitfieldExtract(sc, 3 * int(l / 2), 3) + 1);
25-
26-
const int16_t grid = int16_t(iq1s_grid[qs | ((qh & 7) << 8)]);
27-
28-
[[unroll]] for (uint j = 0; j < NUM_COLS; ++j) {
29-
vec4 b0 = vec4(data_b_v4[(j*p.batch_stride_b + b_offset + y_idx) / 4 + 2*l + 0]);
30-
vec4 b4 = vec4(data_b_v4[(j*p.batch_stride_b + b_offset + y_idx) / 4 + 2*l + 1]);
31-
32-
FLOAT_TYPE sum = FLOAT_TYPE(0.0);
33-
[[unroll]] for (int k = 0; k < 4; ++k) {
34-
sum = fma(FLOAT_TYPE(b0[k]), bitfieldExtract(grid, 2 * k, 2) + delta,
35-
fma(FLOAT_TYPE(b4[k]), bitfieldExtract(grid, 8 + 2 * k, 2) + delta, sum));
36-
}
37-
temp[j][n] = fma(dl, sum, temp[j][n]);
37+
dl_cache[l] = FLOAT_TYPE(d * (2 * bitfieldExtract(sc, 3 * int(l / 2), 3) + 1));
38+
const uint qh = data_a[ibi].qh[qh_base + l / 2] >> (4 * (l & 1));
39+
const uint qs = data_a[ibi].qs[qs_base + l];
40+
gvf_cache[l] = iq1s_grid[qs | ((qh & 7) << 8)];
41+
delta_cache[l] = ((qh & 8) != 0) ? -IQ1M_DELTA : IQ1M_DELTA;
42+
}
43+
44+
// Loop over columns of the output
45+
[[unroll]] for (uint j = 0; j < NUM_COLS; ++j) {
46+
// Compute base index for matrix B
47+
const uint base_b_idx = (j * p.batch_stride_b + b_offset + y_idx) / 4;
48+
vec4 b_vals[8];
49+
50+
// Load 8 vec4 values from matrix B
51+
[[unroll]] for (int idx = 0; idx < 8; ++idx) {
52+
b_vals[idx] = vec4(data_b_v4[base_b_idx + idx]);
53+
}
54+
55+
FLOAT_TYPE col_sum = FLOAT_TYPE(0.0);
56+
57+
// Loop over sub-blocks
58+
[[unroll]] for (uint l = 0; l < 4; ++l) {
59+
const uint16_t grid = gvf_cache[l];
60+
const float dl = dl_cache[l];
61+
62+
// Decode 8 2-bit fbits from gvf_cache
63+
float f0 = float(bitfieldExtract(grid, 0, 2));
64+
float f1 = float(bitfieldExtract(grid, 2, 2));
65+
float f2 = float(bitfieldExtract(grid, 4, 2));
66+
float f3 = float(bitfieldExtract(grid, 6, 2));
67+
float f4 = float(bitfieldExtract(grid, 8, 2));
68+
float f5 = float(bitfieldExtract(grid, 10, 2));
69+
float f6 = float(bitfieldExtract(grid, 12, 2));
70+
float f7 = float(bitfieldExtract(grid, 14, 2));
71+
72+
// Pack into vec4 for vectorized FMA
73+
const vec4 fbits_v0 = vec4(f0, f1, f2, f3);
74+
const vec4 fbits_v1 = vec4(f4, f5, f6, f7);
75+
const vec4 delta_v = vec4(delta_cache[l]);
76+
77+
// Vectorized fused multiply-add
78+
vec4 sum_v = fma(b_vals[2*l + 0], fbits_v0 + delta_v, vec4(0.0));
79+
sum_v = fma(b_vals[2*l + 1], fbits_v1 + delta_v, sum_v);
80+
81+
// Horizontal add to get scalar sum
82+
FLOAT_TYPE sum = sum_v.x + sum_v.y + sum_v.z + sum_v.w;
83+
84+
// Accumulate to column sum
85+
col_sum = fma(dl, sum, col_sum);
3886
}
87+
// Write result to temporary buffer
88+
temp[j][n] += col_sum;
3989
}
4090
ibi += num_blocks_per_row;
4191
}

0 commit comments

Comments
 (0)