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 c3737e9f..1d425629 100644 --- a/tests/functional/configs/test_suite_normalize/suite.json +++ b/tests/functional/configs/test_suite_normalize/suite.json @@ -1,5 +1,6 @@ [ "simple_normalize.json", + "dim_normalize.json", "directive.json", "macro_expansion.json", "atomic_test_case.json", 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..b1af3803 --- /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]; + 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]; + }; + }; +} 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..a526a998 --- /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::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) { + 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