| 1539 | } |
| 1540 | |
| 1541 | static void ggml_cl_mul_mat_f16(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst, void * wdata, size_t wsize) { |
| 1542 | GGML_ASSERT(fp16_support); |
| 1543 | |
| 1544 | const int64_t ne00 = src0->ne[0]; |
| 1545 | const int64_t ne01 = src0->ne[1]; |
| 1546 | const int64_t ne02 = src0->ne[2]; |
| 1547 | const int64_t ne03 = src0->ne[3]; |
| 1548 | |
| 1549 | const int64_t ne10 = src1->ne[0]; |
| 1550 | const int64_t ne11 = src1->ne[1]; |
| 1551 | const int64_t ne12 = src1->ne[2]; |
| 1552 | const int64_t ne13 = src1->ne[3]; |
| 1553 | |
| 1554 | const int nb10 = src1->nb[0]; |
| 1555 | const int nb11 = src1->nb[1]; |
| 1556 | const int nb12 = src1->nb[2]; |
| 1557 | const int nb13 = src1->nb[3]; |
| 1558 | |
| 1559 | const int nb2 = dst->nb[2]; |
| 1560 | const int nb3 = dst->nb[3]; |
| 1561 | |
| 1562 | const int64_t r2 = ne12 / ne02; |
| 1563 | const int64_t r3 = ne13 / ne03; |
| 1564 | |
| 1565 | const ggml_fp16_t alpha = ggml_fp32_to_fp16(1.0f); |
| 1566 | const ggml_fp16_t beta = ggml_fp32_to_fp16(0.0f); |
| 1567 | const int x_ne = ne01 * ne00; |
| 1568 | const int y_ne = ne11 * ne10; |
| 1569 | const int d_ne = ne11 * ne01; |
| 1570 | |
| 1571 | GGML_ASSERT(wsize >= sizeof(ggml_fp16_t) * y_ne); |
| 1572 | GGML_ASSERT(wsize >= sizeof(ggml_fp16_t) * d_ne); |
| 1573 | ggml_fp16_t * const tmp = (ggml_fp16_t *) wdata; |
| 1574 | |
| 1575 | size_t x_size; |
| 1576 | size_t y_size; |
| 1577 | size_t d_size; |
| 1578 | cl_mem d_X; |
| 1579 | if (src0->backend == GGML_BACKEND_GPU) { // NOLINT |
| 1580 | d_X = (cl_mem) src0->extra; |
| 1581 | } else { |
| 1582 | d_X = ggml_cl_pool_malloc(sizeof(ggml_fp16_t) * x_ne, &x_size); |
| 1583 | } |
| 1584 | cl_mem d_Y = ggml_cl_pool_malloc(sizeof(ggml_fp16_t) * y_ne, &y_size); |
| 1585 | cl_mem d_D = ggml_cl_pool_malloc(sizeof(ggml_fp16_t) * d_ne, &d_size); |
| 1586 | |
| 1587 | bool src1_cont_rows = nb10 == sizeof(float); |
| 1588 | bool src1_cont_cols = (size_t)nb11 == ne11*sizeof(float); |
| 1589 | |
| 1590 | size_t x_offset = 0; |
| 1591 | |
| 1592 | for (int64_t i03 = 0; i03 < ne03; i03++) { |
| 1593 | // TODO: copy src0 here when r3>1 |
| 1594 | for (int64_t i13 = i03 * r3, e13 = i13 + r3; i13 < e13; i13++) { |
| 1595 | for (int64_t i02 = 0; i02 < ne02; i02++) { |
| 1596 | if (src0->backend == GGML_BACKEND_GPU) { |
| 1597 | x_offset = (i03 * ne02 + i02) * x_ne; |
| 1598 | } else { |
no test coverage detected