| 1821 | } |
| 1822 | |
| 1823 | static bool ggml_cl_mul_mat_use_f16(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * /* dst */) { |
| 1824 | // If device doesn't support FP16 |
| 1825 | if (!fp16_support) { |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
| 1829 | size_t src0_sz = ggml_nbytes(src0); |
| 1830 | size_t src1_sz = ggml_nbytes(src1); |
| 1831 | |
| 1832 | // mul_mat_q: src0 is converted to fp32 on device |
| 1833 | size_t mul_mat_q_transfer = src0_sz + src1_sz; |
| 1834 | |
| 1835 | // mul_mat_f16: src1 is converted to fp16 on cpu |
| 1836 | size_t mul_mat_f16_transfer = src0_sz + sizeof(ggml_fp16_t) * ggml_nelements(src1); |
| 1837 | |
| 1838 | // choose the smaller one to transfer to the device |
| 1839 | // TODO: this is not always the best choice due to the overhead of converting to fp16 |
| 1840 | return mul_mat_f16_transfer < mul_mat_q_transfer; |
| 1841 | } |
| 1842 | |
| 1843 | void ggml_cl_mul_mat(const struct ggml_tensor * src0, const struct ggml_tensor * src1, struct ggml_tensor * dst, void * wdata, size_t wsize) { |
| 1844 | GGML_ASSERT(ggml_cl_can_mul_mat(src0, src1, dst)); |
no test coverage detected