Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-zdnn/mmf.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-zdnn / mmf.cpp` 89 lines ยท 3959 bytes Raw Blame History 1 #include "ggml.h" 2 #include "mmf.hpp" 3 #include "utils.hpp" 4 5 void ggml_zdnn_mul_mat_f( 6 const ggml_backend_zdnn_context * ctx, 7 const ggml_tensor * src0, 8 const ggml_tensor * src1, 9 ggml_tensor * dst) { 10 GGML_TENSOR_BINARY_OP_LOCALS; 11 12 const enum ggml_type type = src0->type; 13 14 GGML_ASSERT(ne0 == ne01); 15 GGML_ASSERT(ne1 == ne11); 16 GGML_ASSERT(ne2 == ne12); 17 GGML_ASSERT(ne3 == ne13); 18 19 // we don't support permuted src0 or src1 20 GGML_ASSERT(nb00 == ggml_type_size(type)); 21 GGML_ASSERT(nb10 == ggml_type_size(src1->type)); 22 23 // dst cannot be transposed or permuted 24 GGML_ASSERT(nb0 == sizeof(float)); 25 GGML_ASSERT(nb0 <= nb1); 26 GGML_ASSERT(nb1 <= nb2); 27 GGML_ASSERT(nb2 <= nb3); 28 29 const ggml_tensor * weights = src0; 30 const ggml_tensor * inputs = src1; 31 ggml_tensor * output = dst; 32 33 ggml_backend_zdnn_buffer * weights_extra = (ggml_backend_zdnn_buffer *)weights->extra; 34 ggml_backend_zdnn_buffer * inputs_extra = (ggml_backend_zdnn_buffer *)inputs->extra; 35 ggml_backend_zdnn_buffer * output_extra = (ggml_backend_zdnn_buffer *)output->extra; 36 ggml_backend_zdnn_buffer * bias_extra = (ggml_backend_zdnn_buffer *)output_extra->extra; 37 38 const int64_t weights_rows = ne01; 39 const int64_t weights_cols = ne00; 40 const int64_t inputs_rows = ne11; 41 const int64_t inputs_cols = ne10; 42 43 assert(inputs_cols == weights_cols); 44 45 const int64_t output_rows = ne1; 46 const int64_t output_cols = ne0; 47 48 // GGML_LOG_INFO("%s: tensor '%s' tensor dimensions: [%ld, %ld, %ld, %ld] pre_tfm_desc dimensions: [%ld, %ld, %ld, %ld]\n", 49 // __func__, weights_extra->name, 50 // weights->ne[3], weights->ne[2], weights->ne[1], weights->ne[0], 51 // weights_extra->pre_tfm_desc.dim1, 52 // weights_extra->pre_tfm_desc.dim2, 53 // weights_extra->pre_tfm_desc.dim3, 54 // weights_extra->pre_tfm_desc.dim4); 55 56 // GGML_LOG_INFO("%s: tensor '%s' tensor dimensions: [%ld, %ld, %ld, %ld] pre_tfm_desc dimensions: [%ld, %ld, %ld, %ld]\n", 57 // __func__, inputs_extra->name, 58 // inputs->ne[3], inputs->ne[2], inputs->ne[1], inputs->ne[0], 59 // inputs_extra->pre_tfm_desc.dim1, 60 // inputs_extra->pre_tfm_desc.dim2, 61 // inputs_extra->pre_tfm_desc.dim3, 62 // inputs_extra->pre_tfm_desc.dim4); 63 64 GGML_ASSERT(weights_extra->pre_tfm_desc.dim1 == weights->ne[0] && "weights_extra->pre_tfm_desc.dim1 must match weights->ne[0]"); 65 GGML_ASSERT(weights_extra->pre_tfm_desc.dim2 == weights->ne[1] && "weights_extra->pre_tfm_desc.dim2 must match weights->ne[1]"); 66 GGML_ASSERT(inputs_extra->pre_tfm_desc.dim1 == inputs->ne[0] && "inputs_extra->pre_tfm_desc.dim1 must match inputs->ne[0]"); 67 GGML_ASSERT(inputs_extra->pre_tfm_desc.dim2 == inputs->ne[1] && "inputs_extra->pre_tfm_desc.dim2 must match inputs->ne[1]"); 68 69 // compute tensors are transformed on first use 70 if (!weights_extra->ztensor.is_transformed) { 71 ggml_zdnn_load_tensor(weights_extra->ztensor, weights->data); 72 } 73 if (!inputs_extra->ztensor.is_transformed) { 74 ggml_zdnn_load_tensor(inputs_extra->ztensor, inputs->data); 75 } 76 77 ZDNN_CHECK(zdnn_matmul_transpose_op(&inputs_extra->ztensor, &weights_extra->ztensor, &bias_extra->ztensor, 78 false, true, MATMUL_OP_ADDITION, &output_extra->ztensor)); 79 // TODO: Remove in the future as we are currently DLF16 -> FP32 then in the next op, FP32 -> DLF16 again. Inefficient. 80 ZDNN_CHECK(zdnn_transform_origtensor(&output_extra->ztensor, output->data)); 81 82 GGML_UNUSED(ctx); 83 GGML_UNUSED(weights_rows); 84 GGML_UNUSED(weights_cols); 85 GGML_UNUSED(inputs_rows); 86 GGML_UNUSED(inputs_cols); 87 GGML_UNUSED(output_rows); 88 GGML_UNUSED(output_cols); 89 }