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

Function ggml_compute_forward_repeat_back_f32

ggml.c:8451–8506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8449// ggml_compute_forward_repeat_back
8450
8451static void ggml_compute_forward_repeat_back_f32(
8452 const struct ggml_compute_params * params,
8453 const struct ggml_tensor * src0,
8454 struct ggml_tensor * dst) {
8455 GGML_ASSERT(params->ith == 0);
8456 GGML_ASSERT(ggml_can_repeat(dst, src0));
8457
8458 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
8459 return;
8460 }
8461
8462 GGML_TENSOR_UNARY_OP_LOCALS
8463
8464 // guaranteed to be an integer due to the check in ggml_can_repeat
8465 const int nr0 = (int)(ne00/ne0);
8466 const int nr1 = (int)(ne01/ne1);
8467 const int nr2 = (int)(ne02/ne2);
8468 const int nr3 = (int)(ne03/ne3);
8469
8470 // TODO: support for transposed / permuted tensors
8471 GGML_ASSERT(nb0 == sizeof(float));
8472 GGML_ASSERT(nb00 == sizeof(float));
8473
8474 if (ggml_is_contiguous(dst)) {
8475 ggml_vec_set_f32(ne0*ne1*ne2*ne3, dst->data, 0);
8476 } else {
8477 for (int k3 = 0; k3 < ne3; k3++) {
8478 for (int k2 = 0; k2 < ne2; k2++) {
8479 for (int k1 = 0; k1 < ne1; k1++) {
8480 ggml_vec_set_f32(ne0,
8481 (float *) ((char *) dst->data + k1*nb1 + k2*nb2 + k3*nb3),
8482 0);
8483 }
8484 }
8485 }
8486 }
8487
8488 // TODO: maybe this is not optimal?
8489 for (int i3 = 0; i3 < nr3; i3++) {
8490 for (int k3 = 0; k3 < ne3; k3++) {
8491 for (int i2 = 0; i2 < nr2; i2++) {
8492 for (int k2 = 0; k2 < ne2; k2++) {
8493 for (int i1 = 0; i1 < nr1; i1++) {
8494 for (int k1 = 0; k1 < ne1; k1++) {
8495 for (int i0 = 0; i0 < nr0; i0++) {
8496 ggml_vec_acc_f32(ne0,
8497 (float *) ((char *) dst->data + ( k3)*nb3 + ( k2)*nb2 + ( k1)*nb1),
8498 (float *) ((char *) src0->data + (i3*ne3 + k3)*nb03 + (i2*ne2 + k2)*nb02 + (i1*ne1 + k1)*nb01 + (i0*ne0)*nb00));
8499 }
8500 }
8501 }
8502 }
8503 }
8504 }
8505 }
8506}
8507
8508static void ggml_compute_forward_repeat_back(

Callers 1

Calls 4

ggml_can_repeatFunction · 0.70
ggml_is_contiguousFunction · 0.70
ggml_vec_set_f32Function · 0.70
ggml_vec_acc_f32Function · 0.70

Tested by

no test coverage detected