Skip to content

Commit 1e56825

Browse files
committed
switch to default conv2d interface
1 parent 4b1920e commit 1e56825

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

ggml/include/ggml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,8 +1992,8 @@ extern "C" {
19921992
int p0, // padding dimension 0
19931993
int p1, // padding dimension 1
19941994
int d0, // dilation dimension 0
1995-
int d1,
1996-
int layout); // dilation dimension 1
1995+
int d1);
1996+
// int layout); // for future
19971997

19981998

19991999
GGML_API struct ggml_tensor * ggml_conv_3d_direct(

ggml/src/ggml.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,9 +4585,9 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm(
45854585
int p0, // padding dimension 0
45864586
int p1, // padding dimension 1
45874587
int d0, // dilation dimension 0
4588-
int d1,
4588+
int d1){
45894589
// 0: NHWC, 1:NCHW
4590-
int layout) {// dilation dimension 1
4590+
// int layout) {
45914591

45924592
GGML_ASSERT(a->ne[2] == b->ne[2]);
45934593
//GGML_ASSERT(a->type == b->type);
@@ -4606,12 +4606,10 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm(
46064606
ggml_set_op_params_i32(result, 3, p1);
46074607
ggml_set_op_params_i32(result, 4, d0);
46084608
ggml_set_op_params_i32(result, 5, d1);
4609-
ggml_set_op_params_i32(result, 6, layout);
46104609

46114610
struct ggml_tensor *ap, *bp;
4612-
if(layout == 0){
4613-
// ap = ggml_cont(ctx, ggml_permute(ctx, a, 1, 2, 0, 3));
4614-
// bp = ggml_cont(ctx, ggml_permute(ctx, b, 1, 2, 0, 3));
4611+
if(a->type == GGML_TYPE_F16 && (a->ne[0] > 1 || a->ne[1] > 1)){
4612+
ggml_set_op_params_i32(result, 6, 0);
46154613
ap = ggml_reshape_4d(ctx,
46164614
ggml_cont(ctx,
46174615
ggml_transpose(ctx,
@@ -4623,6 +4621,7 @@ struct ggml_tensor * ggml_conv_2d_implicitgemm(
46234621
ggml_reshape_3d(ctx, b, b->ne[0]*b->ne[1], b->ne[2], b->ne[3]))),
46244622
b->ne[2], b->ne[0], b->ne[1], b->ne[3]);
46254623
} else{
4624+
ggml_set_op_params_i32(result, 6, 1);
46264625
ap = a;
46274626
bp = b;
46284627
}

tests/test-backend-ops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4273,7 +4273,7 @@ struct test_conv_2d_implicit : public test_case {
42734273
// }
42744274

42754275
ggml_tensor * out =
4276-
ggml_conv_2d_implicitgemm(ctx, kernel, input, stride0, stride1, padding0, padding1, dilation0, dilation1, cwhn?0:1);
4276+
ggml_conv_2d_implicitgemm(ctx, kernel, input, stride0, stride1, padding0, padding1, dilation0, dilation1);
42774277
ggml_set_name(out, "out");
42784278
return out;
42794279
}

tests/test-conv2d-implicit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ struct ggml_cgraph * build_graph_2(const test_model& model) {
262262
int d1 = 1;
263263

264264

265-
266265
// recalculate for avoid fragmentation
267266
// struct ggml_tensor* conv2d_res = ggml_conv_2d(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1);
268267
// ggml_set_name(conv2d_res, "conv2d_res");
@@ -271,7 +270,7 @@ struct ggml_cgraph * build_graph_2(const test_model& model) {
271270
// printf("conv2d: (%zu, %zu, %zu, %zu) \n", ne[0], ne[1], ne[2], ne[3]);
272271

273272

274-
struct ggml_tensor* wino_res = ggml_conv_2d_implicitgemm(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1, 0);
273+
struct ggml_tensor* wino_res = ggml_conv_2d_implicitgemm(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1);
275274
// struct ggml_tensor* wino_res = ggml_conv_2d_direct(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1);
276275
ggml_set_name(wino_res, "wino_res");
277276
ggml_build_forward_expand(gf, wino_res);
@@ -353,9 +352,10 @@ int main(void)
353352
// std::make_tuple(640,640,52,76,3,3),
354353
// std::make_tuple(640,640,104,152,3,3),
355354
// std::make_tuple(960,320,104,152,3,3),
356-
std::make_tuple(1280,1280,26,38,3,3),
355+
// std::make_tuple(1280,1280,26,38,3,3),
357356
// std::make_tuple(1280,1280,26,38,1,1),
358357
// std::make_tuple(256,128,768,1024,3,3),
358+
std::make_tuple(128,3,768,1024,3,3),
359359
// std::make_tuple(256,128,768,1024,1,1),
360360
// std::make_tuple(512,256,384,512,1,1),
361361
// std::make_tuple(1280,640,52,76,3,3),
@@ -389,7 +389,7 @@ int main(void)
389389

390390

391391
struct ggml_cgraph * gf_res_0 = NULL;
392-
int iterations = 0;
392+
int iterations = 20;
393393

394394
double run_time0;
395395
std::vector<float> im2col_data = compute_graph(model, allocr, build_graph_0, iterations, &run_time0);

0 commit comments

Comments
 (0)