Skip to content

Commit 0682209

Browse files
Implement byteswap for tq1_0 and tq2_0
1 parent a8757fe commit 0682209

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ggml/src/ggml.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ static void ggml_byteswap_q8_k (void * restrict buffer, size_t elements);
625625
static void ggml_byteswap_q4_0_4x4(void * restrict buffer, size_t elements);
626626
static void ggml_byteswap_q4_0_4x8(void * restrict buffer, size_t elements);
627627
static void ggml_byteswap_q4_0_8x8(void * restrict buffer, size_t elements);
628+
static void ggml_byteswap_tq1_0 (void * restrict buffer, size_t elements);
629+
static void ggml_byteswap_tq2_0 (void * restrict buffer, size_t elements);
628630

629631
static const struct ggml_type_traits type_traits[GGML_TYPE_COUNT] = {
630632
[GGML_TYPE_I8] = {
@@ -911,6 +913,7 @@ static const struct ggml_type_traits type_traits[GGML_TYPE_COUNT] = {
911913
.is_quantized = true,
912914
.to_float = (ggml_to_float_t) dequantize_row_tq1_0,
913915
.from_float_ref = (ggml_from_float_t) quantize_row_tq1_0_ref,
916+
.byteswap = ggml_byteswap_tq1_0,
914917
},
915918
[GGML_TYPE_TQ2_0] = {
916919
.type_name = "tq2_0",
@@ -919,6 +922,7 @@ static const struct ggml_type_traits type_traits[GGML_TYPE_COUNT] = {
919922
.is_quantized = true,
920923
.to_float = (ggml_to_float_t) dequantize_row_tq2_0,
921924
.from_float_ref = (ggml_from_float_t) quantize_row_tq2_0_ref,
925+
.byteswap = ggml_byteswap_tq2_0,
922926
},
923927
[36] = { // GGML_TYPE_IQ4_NL_4_4
924928
.type_name = "TYPE_IQ4_NL_4_4 REMOVED, use IQ4_NL with runtime repacking",
@@ -6792,3 +6796,17 @@ static void ggml_byteswap_q4_0_8x8(void * restrict buffer, size_t elements) {
67926796
UNUSED(buffer);
67936797
UNUSED(elements);
67946798
}
6799+
6800+
static void ggml_byteswap_tq1_0(void * restrict buffer, size_t elements) {
6801+
block_tq1_0 *data_ptr = (block_tq1_0*) buffer;
6802+
for (size_t i = 0; i < elements; ++i) {
6803+
convert_from_le16(&(data_ptr[i].d));
6804+
}
6805+
}
6806+
6807+
static void ggml_byteswap_tq2_0(void * restrict buffer, size_t elements) {
6808+
block_tq2_0 *data_ptr = (block_tq2_0*) buffer;
6809+
for (size_t i = 0; i < elements; ++i) {
6810+
convert_from_le16(&(data_ptr[i].d));
6811+
}
6812+
}

0 commit comments

Comments
 (0)