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

Function ggml_compute_forward_sub_f32

ggml.c:7677–7735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7675// ggml_compute_forward_sub
7676
7677static void ggml_compute_forward_sub_f32(
7678 const struct ggml_compute_params * params,
7679 const struct ggml_tensor * src0,
7680 const struct ggml_tensor * src1,
7681 struct ggml_tensor * dst) {
7682 assert(params->ith == 0);
7683 assert(ggml_are_same_shape(src0, src1) && ggml_are_same_shape(src0, dst));
7684
7685 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
7686 return;
7687 }
7688
7689 const int nr = ggml_nrows(src0);
7690
7691 GGML_TENSOR_BINARY_OP_LOCALS
7692
7693 GGML_ASSERT( nb0 == sizeof(float));
7694 GGML_ASSERT(nb00 == sizeof(float));
7695
7696 if (nb10 == sizeof(float)) {
7697 for (int ir = 0; ir < nr; ++ir) {
7698 // src0, src1 and dst are same shape => same indices
7699 const int i3 = ir/(ne2*ne1);
7700 const int i2 = (ir - i3*ne2*ne1)/ne1;
7701 const int i1 = (ir - i3*ne2*ne1 - i2*ne1);
7702
7703#ifdef GGML_USE_ACCELERATE
7704 vDSP_vsub(
7705 (float *) ((char *) src1->data + i3*nb13 + i2*nb12 + i1*nb11), 1,
7706 (float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01), 1,
7707 (float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 ), 1,
7708 ne0);
7709#else
7710 ggml_vec_sub_f32(ne0,
7711 (float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 ),
7712 (float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01),
7713 (float *) ((char *) src1->data + i3*nb13 + i2*nb12 + i1*nb11));
7714#endif
7715 // }
7716 // }
7717 }
7718 } else {
7719 // src1 is not contiguous
7720 for (int ir = 0; ir < nr; ++ir) {
7721 // src0, src1 and dst are same shape => same indices
7722 const int i3 = ir/(ne2*ne1);
7723 const int i2 = (ir - i3*ne2*ne1)/ne1;
7724 const int i1 = (ir - i3*ne2*ne1 - i2*ne1);
7725
7726 float * dst_ptr = (float *) ((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 );
7727 float * src0_ptr = (float *) ((char *) src0->data + i3*nb03 + i2*nb02 + i1*nb01);
7728 for (int i0 = 0; i0 < ne0; i0++) {
7729 float * src1_ptr = (float *) ((char *) src1->data + i3*nb13 + i2*nb12 + i1*nb11 + i0*nb10);
7730
7731 dst_ptr[i0] = src0_ptr[i0] - *src1_ptr;
7732 }
7733 }
7734 }

Callers 1

ggml_compute_forward_subFunction · 0.85

Calls 3

ggml_are_same_shapeFunction · 0.70
ggml_nrowsFunction · 0.70
ggml_vec_sub_f32Function · 0.70

Tested by

no test coverage detected