@@ -5847,26 +5847,46 @@ struct test_acc : public test_case {
58475847 const ggml_type type;
58485848 const std::array<int64_t , 4 > ne_a;
58495849 const std::array<int64_t , 4 > ne_b;
5850+ const int64_t stride_dim;
58505851
58515852 std::string vars () override {
5852- return VARS_TO_STR3 (type, ne_a, ne_b);
5853+ return VARS_TO_STR4 (type, ne_a, ne_b, stride_dim );
58535854 }
58545855
58555856 test_acc (ggml_type type = GGML_TYPE_F32,
5856- std::array<int64_t , 4 > ne_a = {256 , 17 , 1 , 1 },
5857- std::array<int64_t , 4 > ne_b = {256 , 16 , 1 , 1 })
5858- : type(type), ne_a(ne_a), ne_b(ne_b) {}
5857+ std::array<int64_t , 4 > ne_a = {256 , 17 , 2 , 3 },
5858+ std::array<int64_t , 4 > ne_b = {256 , 16 , 2 , 3 },
5859+ uint64_t stride_dim = -1 )
5860+ : type(type), ne_a(ne_a), ne_b(ne_b), stride_dim(stride_dim) {}
58595861
58605862 ggml_tensor * build_graph (ggml_context * ctx) override {
58615863 ggml_tensor * a = ggml_new_tensor (ctx, type, 4 , ne_a.data ());
58625864 ggml_set_param (a);
58635865 ggml_set_name (a, " a" );
58645866
5865- ggml_tensor * b = ggml_new_tensor (ctx, type, 4 , ne_b.data ());
5866- ggml_set_param (b);
5867+ ggml_tensor * b;
5868+ if (stride_dim == 1 || stride_dim == 2 || stride_dim == 3 ) {
5869+ // Create a larger tensor and take a view at a non-zero offset.
5870+ // This tests that the backend correctly handles b's data offset
5871+ std::array<int64_t , 4 > ne_b_pad = {ne_b[0 ], ne_b[1 ], ne_b[2 ], ne_b[3 ]};
5872+ ne_b_pad[stride_dim] += 1 ;
5873+ ggml_tensor * b_pad = ggml_new_tensor (ctx, type, 4 , ne_b_pad.data ());
5874+ ggml_set_param (b_pad);
5875+ ggml_set_name (b_pad, " b_pad" );
5876+ // View that skips the first row, so b has a non-zero byte offset
5877+ b = ggml_view_4d (ctx, b_pad,
5878+ ne_b[0 ], ne_b[1 ], ne_b[2 ], ne_b[3 ],
5879+ b_pad->nb [1 ], b_pad->nb [2 ], b_pad->nb [3 ],
5880+ b_pad->nb [1 ]);
5881+ } else {
5882+ b = ggml_new_tensor (ctx, type, 4 , ne_b.data ());
5883+ ggml_set_param (b);
5884+ }
58675885 ggml_set_name (b, " b" );
58685886
5869- ggml_tensor * out = ggml_acc (ctx, a, b, a->nb [1 ], a->nb [2 ], a->nb [3 ], b->nb [1 ]);
5887+ // When ne_b[0] < ne_a[0], a->nb[1] != b->nb[1], so the stride
5888+ // parameters to ggml_acc don't match b's natural stride.
5889+ ggml_tensor * out = ggml_acc (ctx, a, b, a->nb [1 ], a->nb [2 ], a->nb [3 ], 0 );
58705890 ggml_set_name (out, " out" );
58715891
58725892 return out;
@@ -8170,7 +8190,12 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
81708190 test_cases.emplace_back (new test_group_norm (GGML_TYPE_F32, {9 , 9 , 1280 , 1 }));
81718191 test_cases.emplace_back (new test_group_norm_mul_add (GGML_TYPE_F32, {64 , 64 , 320 , 1 }));
81728192 test_cases.emplace_back (new test_group_norm_mul_add (GGML_TYPE_F32, {9 , 9 , 1280 , 1 }));
8173- test_cases.emplace_back (new test_acc ());
8193+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 1 , 1 }, {256 , 16 , 1 , 1 }, -1 ));
8194+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {256 , 16 , 2 , 3 }, -1 ));
8195+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {128 , 16 , 2 , 3 }, -1 ));
8196+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {256 , 16 , 2 , 3 }, 1 ));
8197+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {128 , 16 , 2 , 3 }, 2 ));
8198+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {64 , 16 , 2 , 3 }, 3 ));
81748199 test_cases.emplace_back (new test_pad ());
81758200 test_cases.emplace_back (new test_pad (GGML_TYPE_F32, {33 , 17 , 2 , 1 }, 4 , 3 , true )); // circular
81768201 test_cases.emplace_back (new test_pad_ext ());
@@ -8605,6 +8630,14 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
86058630 test_cases.emplace_back (new test_ssm_scan (GGML_TYPE_F32, 128 , 64 , 48 , 1 , 512 , 1 )); // prefill
86068631 test_cases.emplace_back (new test_ssm_scan (GGML_TYPE_F32, 128 , 64 , 48 , 1 , 1 , 1 )); // generate
86078632
8633+ // acc
8634+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 1 , 1 }, {256 , 16 , 1 , 1 }, -1 ));
8635+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {256 , 16 , 2 , 3 }, -1 ));
8636+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {128 , 16 , 2 , 3 }, -1 ));
8637+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {256 , 16 , 2 , 3 }, 1 ));
8638+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {128 , 16 , 2 , 3 }, 2 ));
8639+ test_cases.emplace_back (new test_acc (GGML_TYPE_F32, {256 , 17 , 2 , 3 }, {64 , 16 , 2 , 3 }, 3 ));
8640+
86088641 return test_cases;
86098642}
86108643
0 commit comments