| 7564 | // ggml_compute_forward_acc |
| 7565 | |
| 7566 | static void ggml_compute_forward_acc_f32( |
| 7567 | const struct ggml_compute_params * params, |
| 7568 | const struct ggml_tensor * src0, |
| 7569 | const struct ggml_tensor * src1, |
| 7570 | struct ggml_tensor * dst) { |
| 7571 | GGML_ASSERT(ggml_are_same_shape(src0, dst)); |
| 7572 | GGML_ASSERT(ggml_is_contiguous(dst) && ggml_is_contiguous(src0)); |
| 7573 | |
| 7574 | // view src0 and dst with these strides and data offset inbytes during acc |
| 7575 | // nb0 is implicitely element_size because src0 and dst are contiguous |
| 7576 | size_t nb1 = ((int32_t *) dst->op_params)[0]; |
| 7577 | size_t nb2 = ((int32_t *) dst->op_params)[1]; |
| 7578 | size_t nb3 = ((int32_t *) dst->op_params)[2]; |
| 7579 | size_t offset = ((int32_t *) dst->op_params)[3]; |
| 7580 | bool inplace = (bool) ((int32_t *) dst->op_params)[4]; |
| 7581 | |
| 7582 | if (!inplace && (params->type == GGML_TASK_INIT)) { |
| 7583 | // memcpy needs to be synchronized across threads to avoid race conditions. |
| 7584 | // => do it in INIT phase |
| 7585 | memcpy( |
| 7586 | ((char *) dst->data), |
| 7587 | ((char *) src0->data), |
| 7588 | ggml_nbytes(dst)); |
| 7589 | } |
| 7590 | |
| 7591 | if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) { |
| 7592 | return; |
| 7593 | } |
| 7594 | |
| 7595 | const int ith = params->ith; |
| 7596 | const int nth = params->nth; |
| 7597 | |
| 7598 | const int nr = ggml_nrows(src1); |
| 7599 | const int nc = src1->ne[0]; |
| 7600 | |
| 7601 | GGML_TENSOR_LOCALS(int64_t, ne1, src1, ne) |
| 7602 | GGML_TENSOR_LOCALS(size_t, nb1, src1, nb) |
| 7603 | |
| 7604 | // src0 and dst as viewed during acc |
| 7605 | const size_t nb0 = ggml_element_size(src0); |
| 7606 | |
| 7607 | const size_t nb00 = nb0; |
| 7608 | const size_t nb01 = nb1; |
| 7609 | const size_t nb02 = nb2; |
| 7610 | const size_t nb03 = nb3; |
| 7611 | |
| 7612 | GGML_ASSERT(offset + (ne10 == 0 ? 0 : ne10-1)*nb0 + (ne11 == 0 ? 0 : ne11-1)*nb1 + (ne12 == 0 ? 0 : ne12-1)*nb2 + (ne13 == 0 ? 0 : ne13-1)*nb3 < ggml_nbytes(dst)); |
| 7613 | GGML_ASSERT(offset + (ne10 == 0 ? 0 : ne10-1)*nb00 + (ne11 == 0 ? 0 : ne11-1)*nb01 + (ne12 == 0 ? 0 : ne12-1)*nb02 + (ne13 == 0 ? 0 : ne13-1)*nb03 < ggml_nbytes(src0)); |
| 7614 | |
| 7615 | GGML_ASSERT(nb10 == sizeof(float)); |
| 7616 | |
| 7617 | // rows per thread |
| 7618 | const int dr = (nr + nth - 1)/nth; |
| 7619 | |
| 7620 | // row range for this thread |
| 7621 | const int ir0 = dr*ith; |
| 7622 | const int ir1 = MIN(ir0 + dr, nr); |
| 7623 |
no test coverage detected