From 1e568252b568fd9b220b2255c348136deca28631 Mon Sep 17 00:00:00 2001 From: bssrdf Date: Wed, 29 Oct 2025 12:11:26 -0400 Subject: [PATCH] switch to default conv2d interface --- ggml/include/ggml.h | 4 ++-- ggml/src/ggml.c | 11 +++++------ tests/test-backend-ops.cpp | 2 +- tests/test-conv2d-implicit.cpp | 8 ++++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 3999acbd4e..26d6f3332c 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -1992,8 +1992,8 @@ extern "C" { int p0, // padding dimension 0 int p1, // padding dimension 1 int d0, // dilation dimension 0 - int d1, - int layout); // dilation dimension 1 + int d1); + // int layout); // for future GGML_API struct ggml_tensor * ggml_conv_3d_direct( diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 0e172e7216..bfe772697e 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -4585,9 +4585,9 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm( int p0, // padding dimension 0 int p1, // padding dimension 1 int d0, // dilation dimension 0 - int d1, + int d1){ // 0: NHWC, 1:NCHW - int layout) {// dilation dimension 1 + // int layout) { GGML_ASSERT(a->ne[2] == b->ne[2]); //GGML_ASSERT(a->type == b->type); @@ -4606,12 +4606,10 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm( ggml_set_op_params_i32(result, 3, p1); ggml_set_op_params_i32(result, 4, d0); ggml_set_op_params_i32(result, 5, d1); - ggml_set_op_params_i32(result, 6, layout); struct ggml_tensor *ap, *bp; - if(layout == 0){ - // ap = ggml_cont(ctx, ggml_permute(ctx, a, 1, 2, 0, 3)); - // bp = ggml_cont(ctx, ggml_permute(ctx, b, 1, 2, 0, 3)); + if(a->type == GGML_TYPE_F16 && (a->ne[0] > 1 || a->ne[1] > 1)){ + ggml_set_op_params_i32(result, 6, 0); ap = ggml_reshape_4d(ctx, ggml_cont(ctx, ggml_transpose(ctx, @@ -4623,6 +4621,7 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm( ggml_reshape_3d(ctx, b, b->ne[0]*b->ne[1], b->ne[2], b->ne[3]))), b->ne[2], b->ne[0], b->ne[1], b->ne[3]); } else{ + ggml_set_op_params_i32(result, 6, 1); ap = a; bp = b; } diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index e564485894..e5f80fe909 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -4273,7 +4273,7 @@ struct test_conv_2d_implicit : public test_case { // } ggml_tensor * out = - ggml_conv_2d_implicitgemm(ctx, kernel, input, stride0, stride1, padding0, padding1, dilation0, dilation1, cwhn?0:1); + ggml_conv_2d_implicitgemm(ctx, kernel, input, stride0, stride1, padding0, padding1, dilation0, dilation1); ggml_set_name(out, "out"); return out; } diff --git a/tests/test-conv2d-implicit.cpp b/tests/test-conv2d-implicit.cpp index 5ad8f2d274..98b8b0e449 100644 --- a/tests/test-conv2d-implicit.cpp +++ b/tests/test-conv2d-implicit.cpp @@ -262,7 +262,6 @@ struct ggml_cgraph * build_graph_2(const test_model& model) { int d1 = 1; - // recalculate for avoid fragmentation // struct ggml_tensor* conv2d_res = ggml_conv_2d(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1); // ggml_set_name(conv2d_res, "conv2d_res"); @@ -271,7 +270,7 @@ struct ggml_cgraph * build_graph_2(const test_model& model) { // printf("conv2d: (%zu, %zu, %zu, %zu) \n", ne[0], ne[1], ne[2], ne[3]); - struct ggml_tensor* wino_res = ggml_conv_2d_implicitgemm(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1, 0); + struct ggml_tensor* wino_res = ggml_conv_2d_implicitgemm(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1); // struct ggml_tensor* wino_res = ggml_conv_2d_direct(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1); ggml_set_name(wino_res, "wino_res"); ggml_build_forward_expand(gf, wino_res); @@ -353,9 +352,10 @@ int main(void) // std::make_tuple(640,640,52,76,3,3), // std::make_tuple(640,640,104,152,3,3), // std::make_tuple(960,320,104,152,3,3), - std::make_tuple(1280,1280,26,38,3,3), + // std::make_tuple(1280,1280,26,38,3,3), // std::make_tuple(1280,1280,26,38,1,1), // std::make_tuple(256,128,768,1024,3,3), + std::make_tuple(128,3,768,1024,3,3), // std::make_tuple(256,128,768,1024,1,1), // std::make_tuple(512,256,384,512,1,1), // std::make_tuple(1280,640,52,76,3,3), @@ -389,7 +389,7 @@ int main(void) struct ggml_cgraph * gf_res_0 = NULL; - int iterations = 0; + int iterations = 20; double run_time0; std::vector im2col_data = compute_graph(model, allocr, build_graph_0, iterations, &run_time0);