Skip to content

Commit b1a6564

Browse files
retroheimclaude
andcommitted
Fix CUDA backend merge resolution truncations
Five additional CUDA-specific issues from the union-style PrismML merge resolution surfaced during nvcc compilation (CPU build skipped these files entirely): - common.cuh: removed duplicate ggml_cuda_type_traits<GGML_TYPE_Q1_0> specialization (line 928 was redundant with line 977) - dequantize.cuh: removed duplicated body inside dequantize_q1_0_g128 (caused "already declared in current scope" for bit_index_0 etc.) - mmq.cu: removed duplicate `case GGML_TYPE_Q1_0:` in ggml_cuda_should_use_mmq switch - mmq.cuh: added missing closing brace after load_tiles_q1_0_g128 before load_tiles_q2_0 began - vecdotq.cuh: re-added vec_dot_q2_0_q8_1 function (dropped by union resolver, but referenced in mmvq.cu switch) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9e2eea3 commit b1a6564

5 files changed

Lines changed: 50 additions & 24 deletions

File tree

ggml/src/ggml-cuda/common.cuh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,13 +973,6 @@ struct ggml_cuda_type_traits<GGML_TYPE_Q8_0> {
973973
static constexpr int qi = QI8_0;
974974
};
975975

976-
template<>
977-
struct ggml_cuda_type_traits<GGML_TYPE_Q1_0> {
978-
static constexpr int qk = QK1_0;
979-
static constexpr int qr = QR1_0;
980-
static constexpr int qi = QI1_0;
981-
};
982-
983976
template<>
984977
struct ggml_cuda_type_traits<GGML_TYPE_Q1_0_g128> {
985978
static constexpr int qk = QK1_0_g128;

ggml/src/ggml-cuda/dequantize.cuh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,6 @@ static __device__ __forceinline__ void dequantize_q1_0_g128(const void * vx, con
4444

4545
v.x = bit_0 ? d : neg_d;
4646
v.y = bit_1 ? d : neg_d;
47-
48-
const int bit_index_0 = iqs;
49-
const int bit_index_1 = iqs + 1;
50-
51-
const int byte_index_0 = bit_index_0 / 8;
52-
const int bit_offset_0 = bit_index_0 % 8;
53-
54-
const int byte_index_1 = bit_index_1 / 8;
55-
const int bit_offset_1 = bit_index_1 % 8;
56-
57-
// Extract bits: 1 = +d, 0 = -d (branchless)
58-
const int bit_0 = (x[ib].qs[byte_index_0] >> bit_offset_0) & 1;
59-
const int bit_1 = (x[ib].qs[byte_index_1] >> bit_offset_1) & 1;
60-
61-
v.x = (2*bit_0 - 1) * d;
62-
v.y = (2*bit_1 - 1) * d;
6347
}
6448

6549
static __device__ __forceinline__ void dequantize_q2_0(const void * vx, const int64_t ib, const int iqs, float2 & v){

ggml/src/ggml-cuda/mmq.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t
283283
// TODO: Q1_0 and Q1_0_g128 MMQ implementation exists but is currently disabled due to accuracy issues
284284
case GGML_TYPE_Q1_0:
285285
case GGML_TYPE_Q1_0_g128:
286-
case GGML_TYPE_Q1_0:
287286
case GGML_TYPE_Q2_0:
288287
case GGML_TYPE_Q4_0:
289288
case GGML_TYPE_Q4_1:

ggml/src/ggml-cuda/mmq.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ template <int mmq_y, bool need_check> static __device__ __forceinline__ void loa
455455
x_df[i*MMQ_MMA_TILE_X_K_Q8_0 + ksx] = bxi->d;
456456
}
457457
#endif // defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE)
458+
}
459+
458460
template <int mmq_y, bool need_check> static __device__ __forceinline__ void load_tiles_q2_0(
459461
const char * __restrict__ x, int * __restrict__ x_tile, const int kbx0, const int i_max, const int stride) {
460462
constexpr int nwarps = mmq_get_nwarps_device();

ggml/src/ggml-cuda/vecdotq.cuh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,54 @@ static __device__ __forceinline__ float vec_dot_q1_0_g128_q8_1(
788788
return d1 * ds8f.x * sumi;
789789
}
790790

791+
static __device__ __forceinline__ float vec_dot_q2_0_q8_1(
792+
const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs) {
793+
794+
const block_q2_0 * bq2_0 = (const block_q2_0 *) vbq + kbx;
795+
796+
const float d2 = bq2_0->d;
797+
798+
const block_q8_1 * bq8_1_chunk = bq8_1 + iqs;
799+
800+
const int offset = iqs * 8;
801+
const int v0 = bq2_0->qs[offset + 0] | (bq2_0->qs[offset + 1] << 8) |
802+
(bq2_0->qs[offset + 2] << 16) | (bq2_0->qs[offset + 3] << 24);
803+
const int v1 = bq2_0->qs[offset + 4] | (bq2_0->qs[offset + 5] << 8) |
804+
(bq2_0->qs[offset + 6] << 16) | (bq2_0->qs[offset + 7] << 24);
805+
806+
int vi_bytes[8];
807+
#pragma unroll
808+
for (int j = 0; j < 4; ++j) {
809+
const int shift = j * 8;
810+
const int codes = (v0 >> shift) & 0xFF;
811+
const int c0 = ((codes >> 0) & 0x3) - 1;
812+
const int c1 = ((codes >> 2) & 0x3) - 1;
813+
const int c2 = ((codes >> 4) & 0x3) - 1;
814+
const int c3 = ((codes >> 6) & 0x3) - 1;
815+
vi_bytes[j] = (c0 & 0xFF) | ((c1 & 0xFF) << 8) | ((c2 & 0xFF) << 16) | ((c3 & 0xFF) << 24);
816+
}
817+
#pragma unroll
818+
for (int j = 0; j < 4; ++j) {
819+
const int shift = j * 8;
820+
const int codes = (v1 >> shift) & 0xFF;
821+
const int c0 = ((codes >> 0) & 0x3) - 1;
822+
const int c1 = ((codes >> 2) & 0x3) - 1;
823+
const int c2 = ((codes >> 4) & 0x3) - 1;
824+
const int c3 = ((codes >> 6) & 0x3) - 1;
825+
vi_bytes[4 + j] = (c0 & 0xFF) | ((c1 & 0xFF) << 8) | ((c2 & 0xFF) << 16) | ((c3 & 0xFF) << 24);
826+
}
827+
828+
int sumi = 0;
829+
#pragma unroll
830+
for (int j = 0; j < 8; ++j) {
831+
const int u = get_int_b4(bq8_1_chunk->qs, j);
832+
sumi = ggml_cuda_dp4a(vi_bytes[j], u, sumi);
833+
}
834+
835+
const float d8 = __low2float(bq8_1_chunk->ds);
836+
return d2 * d8 * sumi;
837+
}
838+
791839
static __device__ __forceinline__ float vec_dot_q4_0_q8_1(
792840
const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs) {
793841

0 commit comments

Comments
 (0)