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

Function ggml_cl_mul_mat_use_f16

ggml-opencl.cpp:1823–1841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1821}
1822
1823static 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
1843void 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));

Callers 2

ggml_cl_mul_matFunction · 0.85

Calls 2

ggml_nbytesFunction · 0.70
ggml_nelementsFunction · 0.70

Tested by

no test coverage detected