a: [OC,IC, KH, KW] b: [N, IC, IH, IW] result: [N, OC, OH, OW]
| 4509 | // b: [N, IC, IH, IW] |
| 4510 | // result: [N, OC, OH, OW] |
| 4511 | struct ggml_tensor * ggml_conv_2d( |
| 4512 | struct ggml_context * ctx, |
| 4513 | struct ggml_tensor * a, |
| 4514 | struct ggml_tensor * b, |
| 4515 | int s0, |
| 4516 | int s1, |
| 4517 | int p0, |
| 4518 | int p1, |
| 4519 | int d0, |
| 4520 | int d1) { |
| 4521 | struct ggml_tensor * im2col = ggml_im2col(ctx, a, b, s0, s1, p0, p1, d0, d1, true, a->type); // [N, OH, OW, IC * KH * KW] |
| 4522 | |
| 4523 | struct ggml_tensor * result = |
| 4524 | ggml_mul_mat(ctx, |
| 4525 | ggml_reshape_2d(ctx, im2col, im2col->ne[0], im2col->ne[3] * im2col->ne[2] * im2col->ne[1]), // [N, OH, OW, IC * KH * KW] => [N*OH*OW, IC * KH * KW] |
| 4526 | ggml_reshape_2d(ctx, a, (a->ne[0] * a->ne[1] * a->ne[2]), a->ne[3])); // [OC,IC, KH, KW] => [OC, IC * KH * KW] |
| 4527 | |
| 4528 | result = ggml_reshape_4d(ctx, result, im2col->ne[1], im2col->ne[2], im2col->ne[3], a->ne[3]); // [OC, N, OH, OW] |
| 4529 | result = ggml_cont(ctx, ggml_permute(ctx, result, 0, 1, 3, 2)); // [N, OC, OH, OW] |
| 4530 | |
| 4531 | |
| 4532 | return result; |
| 4533 | } |
| 4534 | |
| 4535 | // a: [OC*IC, KD, KH, KW] |
| 4536 | // b: [N*IC, ID, IH, IW] |
no test coverage detected