MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_cl_mul_mat_f32

Function ggml_cl_mul_mat_f32

ggml-opencl.cpp:1456–1539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1454}
1455
1456static void ggml_cl_mul_mat_f32(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
1457 const int64_t ne00 = src0->ne[0];
1458 const int64_t ne01 = src0->ne[1];
1459 const int64_t ne02 = src0->ne[2];
1460 const int64_t ne03 = src0->ne[3];
1461
1462 const int64_t ne10 = src1->ne[0];
1463 const int64_t ne11 = src1->ne[1];
1464 const int64_t ne12 = src1->ne[2];
1465 const int64_t ne13 = src1->ne[3];
1466
1467 const int nb2 = dst->nb[2];
1468 const int nb3 = dst->nb[3];
1469
1470 const int64_t r2 = ne12 / ne02;
1471 const int64_t r3 = ne13 / ne03;
1472
1473 const float alpha = 1.0f;
1474 const float beta = 0.0f;
1475 const int x_ne = ne01 * ne00;
1476 const int y_ne = ne11 * ne10;
1477 const int d_ne = ne11 * ne01;
1478
1479 size_t x_size;
1480 size_t y_size;
1481 size_t d_size;
1482 cl_mem d_X;
1483 if (src0->backend == GGML_BACKEND_GPU) { // NOLINT
1484 d_X = (cl_mem) src0->extra;
1485 } else {
1486 d_X = ggml_cl_pool_malloc(sizeof(float) * x_ne, &x_size);
1487 }
1488 cl_mem d_Y = ggml_cl_pool_malloc(sizeof(float) * y_ne, &y_size);
1489 cl_mem d_D = ggml_cl_pool_malloc(sizeof(float) * d_ne, &d_size);
1490
1491 size_t x_offset = 0;
1492
1493 for (int64_t i03 = 0; i03 < ne03; i03++) {
1494 // TODO: copy src0 here when r3>1
1495 for (int64_t i13 = i03 * r3, e13 = i13 + r3; i13 < e13; i13++) {
1496 for (int64_t i02 = 0; i02 < ne02; i02++) {
1497 if (src0->backend == GGML_BACKEND_GPU) {
1498 x_offset = (i03 * ne02 + i02) * x_ne;
1499 } else {
1500 // copy src0 to device
1501 CL_CHECK(ggml_cl_h2d_tensor_2d(queue, d_X, 0, src0, i03, i02, NULL));
1502 }
1503
1504 for (int64_t i12 = i02 * r2, e12 = i12 + r2; i12 < e12; i12++) {
1505 // copy src1 to device
1506 CL_CHECK(ggml_cl_h2d_tensor_2d(queue, d_Y, 0, src1, i13, i12, NULL));
1507
1508 CL_CHECK(clFinish(queue));
1509
1510 // compute
1511 cl_event ev_sgemm;
1512 clblast::StatusCode status = clblast::Gemm<cl_float>(clblast::Layout::kColMajor,
1513 clblast::Transpose::kYes, clblast::Transpose::kNo,

Callers 1

ggml_cl_mul_matFunction · 0.85

Calls 3

ggml_cl_pool_mallocFunction · 0.85
ggml_cl_h2d_tensor_2dFunction · 0.85
ggml_cl_pool_freeFunction · 0.85

Tested by

no test coverage detected