From c85a46f5c65dfb8ad47b32e71080f183159d4f36 Mon Sep 17 00:00:00 2001 From: Kristian Chaba Date: Wed, 31 Jan 2024 16:53:33 +0100 Subject: [PATCH 1/4] Add normalizer tests for `@dim` attributes. --- .../test_suite_normalize/dim_normalize.json | 16 ++++++++++++ .../configs/test_suite_normalize/suite.json | 3 ++- .../data/normalize/dim/attr_placement.cpp | 21 +++++++++++++++ .../data/normalize/dim/attr_placement_ref.cpp | 23 ++++++++++++++++ .../data/normalize/dim/attr_use.cpp | 23 ++++++++++++++++ .../data/normalize/dim/attr_use_ref.cpp | 26 +++++++++++++++++++ tests/functional/main.cpp | 2 ++ 7 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/functional/configs/test_suite_normalize/dim_normalize.json create mode 100644 tests/functional/data/normalize/dim/attr_placement.cpp create mode 100644 tests/functional/data/normalize/dim/attr_placement_ref.cpp create mode 100644 tests/functional/data/normalize/dim/attr_use.cpp create mode 100644 tests/functional/data/normalize/dim/attr_use_ref.cpp diff --git a/tests/functional/configs/test_suite_normalize/dim_normalize.json b/tests/functional/configs/test_suite_normalize/dim_normalize.json new file mode 100644 index 00000000..6a2ce7f1 --- /dev/null +++ b/tests/functional/configs/test_suite_normalize/dim_normalize.json @@ -0,0 +1,16 @@ +[ + { + "action": "normalizer", + "action_config": { + "source": "normalize/dim/attr_placement.cpp" + }, + "reference": "normalize/dim/attr_placement_ref.cpp" + }, + { + "action": "normalizer", + "action_config": { + "source": "normalize/dim/attr_use.cpp" + }, + "reference": "normalize/dim/attr_use_ref.cpp" + } +] \ No newline at end of file diff --git a/tests/functional/configs/test_suite_normalize/suite.json b/tests/functional/configs/test_suite_normalize/suite.json index b4e8a951..04484b6f 100644 --- a/tests/functional/configs/test_suite_normalize/suite.json +++ b/tests/functional/configs/test_suite_normalize/suite.json @@ -1,3 +1,4 @@ [ - "simple_normalize.json" + "simple_normalize.json", + "dim_normalize.json" ] \ No newline at end of file diff --git a/tests/functional/data/normalize/dim/attr_placement.cpp b/tests/functional/data/normalize/dim/attr_placement.cpp new file mode 100644 index 00000000..96a3328d --- /dev/null +++ b/tests/functional/data/normalize/dim/attr_placement.cpp @@ -0,0 +1,21 @@ +typedef float* mat4 @dim(4, 4); + +@kernel void addVectors(const int entries, @dim(x,y) const float *a, const float *b @dim(y,x), float *ab) { + @tile(4, @outer, @inner) + for (int i = 0; i < 4; ++i) { + // Single + { + mat4 @dimOrder(1, 0) arr1 = ab; + arr1(1, 1) = 0; + int @dim(x,y) arr2[12]; + int arr3[12] @dim(x,y) = { 0 }; + }; + + // Multiple + { + @dim(x,y) int arr1_1[12], arr1_2[12]; + int @dim(x,y) arr2_1[12], arr2_2[12]; + int arr3_1[12] @dim(x,y), arr3_2[12] @dim(y,x); + }; + }; +} diff --git a/tests/functional/data/normalize/dim/attr_placement_ref.cpp b/tests/functional/data/normalize/dim/attr_placement_ref.cpp new file mode 100644 index 00000000..077b3ab5 --- /dev/null +++ b/tests/functional/data/normalize/dim/attr_placement_ref.cpp @@ -0,0 +1,23 @@ +typedef [[okl::dim("(4,4)")]] float *mat4; + +[[okl::kernel("(void)")]] void addVectors(const int entries, + [[okl::dim("(x,y)")]] const float *a, + [[okl::dim("(y,x)")]] const float *b, + float *ab) { + [[okl::tile("(4,@outer,@inner)")]] for (int i = 0; i < 4; ++i) { + // Single + { + [[okl::dimOrder("(1,0)")]] mat4 arr1 = ab; + arr1(1, 1) = 0; + [[okl::dim("(x,y)")]] int arr2[12]; + [[okl::dim("(x,y)")]] int arr3[12] = {0}; + }; + + // Multiple + { + [[okl::dim("(x,y)")]] int arr1_1[12], arr1_2[12]; + [[okl::dim("(x,y)")]] int arr2_1[12], arr2_2[12]; + int [[okl::dim("(x,y)")]] arr3_1[12], [[okl::dim("(y,x)")]] arr3_2[12]; + }; + }; +} diff --git a/tests/functional/data/normalize/dim/attr_use.cpp b/tests/functional/data/normalize/dim/attr_use.cpp new file mode 100644 index 00000000..15d8ec27 --- /dev/null +++ b/tests/functional/data/normalize/dim/attr_use.cpp @@ -0,0 +1,23 @@ +typedef int* iPtr45 @dim(4, 5); +typedef int iMat455[4*5*5] @dim(4, 5, 5); + +struct sMat24 { + int* a @dim(2, 4); +}; + +@kernel void test(iPtr45 a @dimOrder(1, 0), sMat24 *b, iMat455 &ab @dimOrder(2, 1, 0), float *ac @dim(4,5) @dimOrder(0, 1)) { + for (int i = 0; i < 4; ++i; @outer) { + @shared int cc[5*4] @dim(4, 5) @dimOrder(0, 1); + for (int j = 0; j < 5; ++j; @inner) { + cc(j, i) = 0; + + for (int k = 0; k < j; ++k) { + ab(k, j, i) = a(j, i); + ab(k, j, i) += b->a(i, j); + } + + ac(j, i) = a(j, i); + ac(j, i) += b->a(i, j); + } + } +} \ No newline at end of file diff --git a/tests/functional/data/normalize/dim/attr_use_ref.cpp b/tests/functional/data/normalize/dim/attr_use_ref.cpp new file mode 100644 index 00000000..39e36241 --- /dev/null +++ b/tests/functional/data/normalize/dim/attr_use_ref.cpp @@ -0,0 +1,26 @@ +typedef [[okl::dim("(4,5)")]] int *iPtr45; +typedef [[okl::dim("(4,5,5)")]] int iMat455[4 * 5 * 5]; + +struct sMat24 { + [[okl::dim("(2,4)")]] int *a; +}; + +[[okl::kernel("(void)")]] void +test([[okl::dimOrder("(1,0)")]] iPtr45 a, sMat24 *b, + [[okl::dimOrder("(2,1,0)")]] iMat455 &ab, + [[okl::dimOrder("(0,1)")]] [[okl::dim("(4,5)")]] float *ac) { + [[okl::outer("(void)")]] for (int i = 0; i < 4; ++i) { + [[okl::shared("(void)")]] [[okl::dim("(4,5)")]] [[okl::dimOrder("(0,1)")]] int cc[5 * 4]; + [[okl::inner("(void)")]] for (int j = 0; j < 5; ++j) { + cc(j, i) = 0; + + for (int k = 0; k < j; ++k) { + ab(k, j, i) = a(j, i); + ab(k, j, i) += b->a(i, j); + } + + ac(j, i) = a(j, i); + ac(j, i) += b->a(i, j); + } + } +} \ No newline at end of file diff --git a/tests/functional/main.cpp b/tests/functional/main.cpp index 0e145cea..242f4a3c 100644 --- a/tests/functional/main.cpp +++ b/tests/functional/main.cpp @@ -11,6 +11,8 @@ int main(int argc, char* argv[]) { argparse::ArgumentParser program("occa-transpiler-tests"); program.add_argument("-s", "--suite").default_value("").help("set suite path"); program.add_argument("-d", "--data_root").default_value("").help("set data root folder"); + program.add_argument("--gtest_filter").default_value("*"); + program.add_argument("--gtest_color").default_value("no"); try { program.parse_args(argc, argv); auto suite = program.get("--suite"); From 64dff81ce3238fd032fa0df0d0b660edb28e064f Mon Sep 17 00:00:00 2001 From: Kristian Chaba Date: Wed, 31 Jan 2024 17:00:37 +0100 Subject: [PATCH 2/4] Fix Multi var definition attribution. --- tests/functional/data/normalize/dim/attr_placement_ref.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/data/normalize/dim/attr_placement_ref.cpp b/tests/functional/data/normalize/dim/attr_placement_ref.cpp index 077b3ab5..b1af3803 100644 --- a/tests/functional/data/normalize/dim/attr_placement_ref.cpp +++ b/tests/functional/data/normalize/dim/attr_placement_ref.cpp @@ -16,7 +16,7 @@ typedef [[okl::dim("(4,4)")]] float *mat4; // Multiple { [[okl::dim("(x,y)")]] int arr1_1[12], arr1_2[12]; - [[okl::dim("(x,y)")]] int arr2_1[12], arr2_2[12]; + int [[okl::dim("(x,y)")]] arr2_1[12], arr2_2[12]; int [[okl::dim("(x,y)")]] arr3_1[12], [[okl::dim("(y,x)")]] arr3_2[12]; }; }; From c518a590fdfdbdd2593a8fe0a4f530e3afdec6a7 Mon Sep 17 00:00:00 2001 From: Kristian Chaba Date: Wed, 31 Jan 2024 18:38:22 +0100 Subject: [PATCH 3/4] Fix Attribute sequence. --- tests/functional/data/normalize/dim/attr_use_ref.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/data/normalize/dim/attr_use_ref.cpp b/tests/functional/data/normalize/dim/attr_use_ref.cpp index 39e36241..a526a998 100644 --- a/tests/functional/data/normalize/dim/attr_use_ref.cpp +++ b/tests/functional/data/normalize/dim/attr_use_ref.cpp @@ -8,7 +8,7 @@ struct sMat24 { [[okl::kernel("(void)")]] void test([[okl::dimOrder("(1,0)")]] iPtr45 a, sMat24 *b, [[okl::dimOrder("(2,1,0)")]] iMat455 &ab, - [[okl::dimOrder("(0,1)")]] [[okl::dim("(4,5)")]] float *ac) { + [[okl::dim("(4,5)")]] [[okl::dimOrder("(0,1)")]] float *ac) { [[okl::outer("(void)")]] for (int i = 0; i < 4; ++i) { [[okl::shared("(void)")]] [[okl::dim("(4,5)")]] [[okl::dimOrder("(0,1)")]] int cc[5 * 4]; [[okl::inner("(void)")]] for (int j = 0; j < 5; ++j) { From 178dfbfa378a3991ec096d0d62f8075b09d5b557 Mon Sep 17 00:00:00 2001 From: Kristian Chaba Date: Wed, 31 Jan 2024 19:58:25 +0100 Subject: [PATCH 4/4] Fix GTest integration. --- tests/functional/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/functional/main.cpp b/tests/functional/main.cpp index 242f4a3c..a267546c 100644 --- a/tests/functional/main.cpp +++ b/tests/functional/main.cpp @@ -11,22 +11,20 @@ int main(int argc, char* argv[]) { argparse::ArgumentParser program("occa-transpiler-tests"); program.add_argument("-s", "--suite").default_value("").help("set suite path"); program.add_argument("-d", "--data_root").default_value("").help("set data root folder"); - program.add_argument("--gtest_filter").default_value("*"); - program.add_argument("--gtest_color").default_value("no"); try { - program.parse_args(argc, argv); + program.parse_known_args(argc, argv); auto suite = program.get("--suite"); std::filesystem::path suitePath(suite); if (!fs::exists(suitePath)) { std::cerr << "Can't find suite folder path" << std::endl; - return 1; + return 0; } DataRootHolder::instance().suitePath = suitePath; auto dataPath = program.get("--data_root"); std::filesystem::path p(dataPath); if (!fs::exists(p) && fs::is_directory(p)) { std::cerr << "Provided invalid data_root" << std::endl; - return 1; + return 0; } DataRootHolder::instance().dataRoot = p; } catch (const std::exception& err) {