Skip to content

Commit a8757fe

Browse files
Implement most of remaining byteswap functions
1 parent 9a4b0df commit a8757fe

File tree

1 file changed

+90
-62
lines changed

1 file changed

+90
-62
lines changed

ggml/src/ggml.c

Lines changed: 90 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ static void ggml_byteswap_iq3_xxs (void * restrict buffer, size_t elements);
619619
static void ggml_byteswap_iq3_s (void * restrict buffer, size_t elements);
620620
static void ggml_byteswap_iq2_s (void * restrict buffer, size_t elements);
621621
static void ggml_byteswap_iq1_s (void * restrict buffer, size_t elements);
622-
static void ggml_byteswap_iq1_m (void * restrict buffer, size_t elements);
623622
static void ggml_byteswap_iq4_nl (void * restrict buffer, size_t elements);
624623
static void ggml_byteswap_iq4_xs (void * restrict buffer, size_t elements);
625624
static void ggml_byteswap_q8_k (void * restrict buffer, size_t elements);
@@ -849,7 +848,6 @@ static const struct ggml_type_traits type_traits[GGML_TYPE_COUNT] = {
849848
.is_quantized = true,
850849
.to_float = (ggml_to_float_t) dequantize_row_iq1_m,
851850
.from_float_ref = NULL,
852-
.byteswap = ggml_byteswap_iq1_m,
853851
},
854852
[GGML_TYPE_IQ4_NL] = {
855853
.type_name = "iq4_nl",
@@ -6619,51 +6617,63 @@ static void ggml_byteswap_i64(void * restrict buffer, size_t elements) {
66196617
}
66206618

66216619
static void ggml_byteswap_q4_0(void * restrict buffer, size_t elements) {
6622-
GGML_ASSERT(false && "byteswap function not implemented yet");
6623-
UNUSED(buffer);
6624-
UNUSED(elements);
6620+
block_q4_0 *data_ptr = (block_q4_0*) buffer;
6621+
for (size_t i = 0; i < elements; ++i) {
6622+
convert_from_le16(&(data_ptr[i].d));
6623+
}
66256624
}
66266625

66276626
static void ggml_byteswap_q4_1(void * restrict buffer, size_t elements) {
6628-
GGML_ASSERT(false && "byteswap function not implemented yet");
6629-
UNUSED(buffer);
6630-
UNUSED(elements);
6627+
block_q4_1 *data_ptr = (block_q4_1*) buffer;
6628+
for (size_t i = 0; i < elements; ++i) {
6629+
convert_from_le16(&(data_ptr[i].d));
6630+
convert_from_le16(&(data_ptr[i].m));
6631+
}
66316632
}
66326633

66336634
static void ggml_byteswap_q5_0(void * restrict buffer, size_t elements) {
6634-
GGML_ASSERT(false && "byteswap function not implemented yet");
6635-
UNUSED(buffer);
6636-
UNUSED(elements);
6635+
block_q5_0 *data_ptr = (block_q5_0*) buffer;
6636+
for (size_t i = 0; i < elements; ++i) {
6637+
convert_from_le16(&(data_ptr[i].d));
6638+
}
66376639
}
66386640

66396641
static void ggml_byteswap_q5_1(void * restrict buffer, size_t elements) {
6640-
GGML_ASSERT(false && "byteswap function not implemented yet");
6641-
UNUSED(buffer);
6642-
UNUSED(elements);
6642+
block_q5_1 *data_ptr = (block_q5_1*) buffer;
6643+
for (size_t i = 0; i < elements; ++i) {
6644+
convert_from_le16(&(data_ptr[i].d));
6645+
convert_from_le16(&(data_ptr[i].m));
6646+
}
66436647
}
66446648

66456649
static void ggml_byteswap_q8_0(void * restrict buffer, size_t elements) {
6646-
GGML_ASSERT(false && "byteswap function not implemented yet");
6647-
UNUSED(buffer);
6648-
UNUSED(elements);
6650+
block_q8_0 *data_ptr = (block_q8_0*) buffer;
6651+
for (size_t i = 0; i < elements; ++i) {
6652+
convert_from_le16(&(data_ptr[i].d));
6653+
}
66496654
}
66506655

66516656
static void ggml_byteswap_q8_1(void * restrict buffer, size_t elements) {
6652-
GGML_ASSERT(false && "byteswap function not implemented yet");
6653-
UNUSED(buffer);
6654-
UNUSED(elements);
6657+
block_q8_1 *data_ptr = (block_q8_1*) buffer;
6658+
for (size_t i = 0; i < elements; ++i) {
6659+
convert_from_le16(&(data_ptr[i].d));
6660+
convert_from_le16(&(data_ptr[i].s));
6661+
}
66556662
}
66566663

66576664
static void ggml_byteswap_q2_k(void * restrict buffer, size_t elements) {
6658-
GGML_ASSERT(false && "byteswap function not implemented yet");
6659-
UNUSED(buffer);
6660-
UNUSED(elements);
6665+
block_q2_K *data_ptr = (block_q2_K*) buffer;
6666+
for (size_t i = 0; i < elements; ++i) {
6667+
convert_from_le16(&(data_ptr[i].d));
6668+
convert_from_le16(&(data_ptr[i].dmin));
6669+
}
66616670
}
66626671

66636672
static void ggml_byteswap_q3_k(void * restrict buffer, size_t elements) {
6664-
GGML_ASSERT(false && "byteswap function not implemented yet");
6665-
UNUSED(buffer);
6666-
UNUSED(elements);
6673+
block_q3_K *data_ptr = (block_q3_K*) buffer;
6674+
for (size_t i = 0; i < elements; ++i) {
6675+
convert_from_le16(&(data_ptr[i].d));
6676+
}
66676677
}
66686678

66696679
static void ggml_byteswap_q4_k(void * restrict buffer, size_t elements) {
@@ -6675,9 +6685,11 @@ static void ggml_byteswap_q4_k(void * restrict buffer, size_t elements) {
66756685
}
66766686

66776687
static void ggml_byteswap_q5_k(void * restrict buffer, size_t elements) {
6678-
GGML_ASSERT(false && "byteswap function not implemented yet");
6679-
UNUSED(buffer);
6680-
UNUSED(elements);
6688+
block_q5_K *data_ptr = (block_q5_K*) buffer;
6689+
for (size_t i = 0; i < elements; ++i) {
6690+
convert_from_le16(&(data_ptr[i].d));
6691+
convert_from_le16(&(data_ptr[i].dmin));
6692+
}
66816693
}
66826694

66836695
static void ggml_byteswap_q6_k(void * restrict buffer, size_t elements) {
@@ -6688,63 +6700,79 @@ static void ggml_byteswap_q6_k(void * restrict buffer, size_t elements) {
66886700
}
66896701

66906702
static void ggml_byteswap_iq2_xxs(void * restrict buffer, size_t elements) {
6691-
GGML_ASSERT(false && "byteswap function not implemented yet");
6692-
UNUSED(buffer);
6693-
UNUSED(elements);
6703+
block_iq2_xxs *data_ptr = (block_iq2_xxs*) buffer;
6704+
for (size_t i = 0; i < elements; ++i) {
6705+
convert_from_le16(&(data_ptr[i].d));
6706+
for (size_t j = 0; j < QK_K/8; ++j) {
6707+
convert_from_le16(&(data_ptr[i].qs[j]));
6708+
}
6709+
}
66946710
}
66956711

66966712
static void ggml_byteswap_iq2_xs(void * restrict buffer, size_t elements) {
6697-
GGML_ASSERT(false && "byteswap function not implemented yet");
6698-
UNUSED(buffer);
6699-
UNUSED(elements);
6713+
block_iq2_xs *data_ptr = (block_iq2_xs*) buffer;
6714+
for (size_t i = 0; i < elements; ++i) {
6715+
convert_from_le16(&(data_ptr[i].d));
6716+
for (size_t j = 0; j < QK_K/8; ++j) {
6717+
convert_from_le16(&(data_ptr[i].qs[j]));
6718+
}
6719+
}
67006720
}
67016721

67026722
static void ggml_byteswap_iq3_xxs(void * restrict buffer, size_t elements) {
6703-
GGML_ASSERT(false && "byteswap function not implemented yet");
6704-
UNUSED(buffer);
6705-
UNUSED(elements);
6723+
block_iq3_xxs *data_ptr = (block_iq3_xxs*) buffer;
6724+
for (size_t i = 0; i < elements; ++i) {
6725+
convert_from_le16(&(data_ptr[i].d));
6726+
}
67066727
}
67076728

67086729
static void ggml_byteswap_iq3_s(void * restrict buffer, size_t elements) {
6709-
GGML_ASSERT(false && "byteswap function not implemented yet");
6710-
UNUSED(buffer);
6711-
UNUSED(elements);
6730+
block_iq3_s *data_ptr = (block_iq3_s*) buffer;
6731+
for (size_t i = 0; i < elements; ++i) {
6732+
convert_from_le16(&(data_ptr[i].d));
6733+
}
67126734
}
67136735

67146736
static void ggml_byteswap_iq2_s(void * restrict buffer, size_t elements) {
6715-
GGML_ASSERT(false && "byteswap function not implemented yet");
6716-
UNUSED(buffer);
6717-
UNUSED(elements);
6737+
block_iq2_s *data_ptr = (block_iq2_s*) buffer;
6738+
for (size_t i = 0; i < elements; ++i) {
6739+
convert_from_le16(&(data_ptr[i].d));
6740+
}
67186741
}
67196742

67206743
static void ggml_byteswap_iq1_s(void * restrict buffer, size_t elements) {
6721-
GGML_ASSERT(false && "byteswap function not implemented yet");
6722-
UNUSED(buffer);
6723-
UNUSED(elements);
6724-
}
6725-
6726-
static void ggml_byteswap_iq1_m(void * restrict buffer, size_t elements) {
6727-
GGML_ASSERT(false && "byteswap function not implemented yet");
6728-
UNUSED(buffer);
6729-
UNUSED(elements);
6744+
block_iq1_s *data_ptr = (block_iq1_s*) buffer;
6745+
for (size_t i = 0; i < elements; ++i) {
6746+
convert_from_le16(&(data_ptr[i].d));
6747+
for (size_t j = 0; j < QK_K/32; ++j) {
6748+
convert_from_le16(&(data_ptr[i].qh[j]));
6749+
}
6750+
}
67306751
}
67316752

67326753
static void ggml_byteswap_iq4_nl(void * restrict buffer, size_t elements) {
6733-
GGML_ASSERT(false && "byteswap function not implemented yet");
6734-
UNUSED(buffer);
6735-
UNUSED(elements);
6754+
block_iq4_nl *data_ptr = (block_iq4_nl*) buffer;
6755+
for (size_t i = 0; i < elements; ++i) {
6756+
convert_from_le16(&(data_ptr[i].d));
6757+
}
67366758
}
67376759

67386760
static void ggml_byteswap_iq4_xs(void * restrict buffer, size_t elements) {
6739-
GGML_ASSERT(false && "byteswap function not implemented yet");
6740-
UNUSED(buffer);
6741-
UNUSED(elements);
6761+
block_iq4_xs *data_ptr = (block_iq4_xs*) buffer;
6762+
for (size_t i = 0; i < elements; ++i) {
6763+
convert_from_le16(&(data_ptr[i].d));
6764+
convert_from_le16(&(data_ptr[i].scales_h));
6765+
}
67426766
}
67436767

67446768
static void ggml_byteswap_q8_k(void * restrict buffer, size_t elements) {
6745-
GGML_ASSERT(false && "byteswap function not implemented yet");
6746-
UNUSED(buffer);
6747-
UNUSED(elements);
6769+
block_q8_K *data_ptr = (block_q8_K*) buffer;
6770+
for (size_t i = 0; i < elements; ++i) {
6771+
convert_from_le32(&(data_ptr[i].d));
6772+
for (size_t j = 0; j < QK_K/16; ++j) {
6773+
convert_from_le16(&(data_ptr[i].bsums[j]));
6774+
}
6775+
}
67486776
}
67496777

67506778
static void ggml_byteswap_q4_0_4x4(void * restrict buffer, size_t elements) {

0 commit comments

Comments
 (0)