Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions ggml/src/ggml-cpu/ggml-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,6 @@ UseGgmlGemm1:;
if (src1->type != vec_dot_type) {
char * wdata = params->wdata;

const size_t nbw0 = ggml_type_size(vec_dot_type);
const size_t nbw1 = ggml_row_size(vec_dot_type, ne10);
const size_t nbw2 = nbw1*ne11;
const size_t nbw3 = nbw2*ne12;
Expand All @@ -1372,36 +1371,22 @@ UseGgmlGemm1:;
GGML_ASSERT(src1->type == GGML_TYPE_F32 ||
(src1->type == GGML_TYPE_F16 && vec_dot_type == GGML_TYPE_F32));

#if 0
for (int64_t i13 = 0; i13 < ne13; ++i13) {
for (int64_t i12 = 0; i12 < ne12; ++i12) {
for (int64_t i11 = ith; i11 < ne11; i11 += nth) {
from_float((float *)((char *) src1->data + i13*nb13 + i12*nb12 + i11*nb11),
(void *) (wdata + i13*nbw3 + i12*nbw2 + i11*nbw1),
ne10);
}
}
}
#else
for (int64_t i13 = 0; i13 < ne13; ++i13) {
for (int64_t i12 = 0; i12 < ne12; ++i12) {
for (int64_t i11 = 0; i11 < ne11; ++i11) {
size_t bs = ggml_blck_size(vec_dot_type);
int64_t ne10_block_start = (ith * ne10/bs) / nth;
int64_t ne10_block_end = ((ith + 1) * ne10/bs) / nth;
const char * src1_block = (const char *) src1->data + i13*nb13 + i12*nb12 + i11*nb11 + ne10_block_start*bs*nb10;
char * dst_block = wdata + i13*nbw3 + i12*nbw2 + i11*nbw1 + ne10_block_start*nbw0;
const int64_t n_block = (ne10_block_end - ne10_block_start) * bs;

if (src1->type == GGML_TYPE_F32) {
from_float((const float *) src1_block, dst_block, n_block);
} else {
ggml_cpu_fp16_to_fp32((const ggml_fp16_t *) src1_block, (float *) dst_block, n_block);
}
}
// one thread per src1 row: splitting a row across threads makes several cores write the same
// cache lines, and every later vec_dot read of the row gets slow (10x on a 2-socket Xeon)
const int64_t nr1 = ne11*ne12*ne13;
for (int64_t ir = ith; ir < nr1; ir += nth) {
const int64_t i13 = ir/(ne12*ne11);
const int64_t i12 = (ir - i13*ne12*ne11)/ne11;
const int64_t i11 = ir - i13*ne12*ne11 - i12*ne11;
const char * src1_row = (const char *) src1->data + i13*nb13 + i12*nb12 + i11*nb11;
char * dst_row = wdata + i13*nbw3 + i12*nbw2 + i11*nbw1;

if (src1->type == GGML_TYPE_F32) {
from_float((const float *) src1_row, dst_row, ne10);
} else {
ggml_cpu_fp16_to_fp32((const ggml_fp16_t *) src1_row, (float *) dst_row, ne10);
}
}
#endif
}

if (ith == 0) {
Expand Down