-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add normalizer tests for @dim
attributes.
#14
base: devel
Are you sure you want to change the base?
Changes from all commits
c85a46f
64dff81
c518a59
178dfbf
d485bca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the same attribute applied to both variables, it must be positioned at the beginning before type. |
||
int [[okl::dim("(x,y)")]] arr2_1[12], arr2_2[12]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attribute type must be applied only to the first definition. |
||
int [[okl::dim("(x,y)")]] arr3_1[12], [[okl::dim("(y,x)")]] arr3_2[12]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two different attributes on single multi-definition. |
||
}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
typedef [[okl::dim("(4,5)")]] int *iPtr45; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type attribute must be placed before the type itself. |
||
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is expected that
type
attributes are added just before the type itself by defaultThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the main purpose of normalizer is to unify using of attribute in terms of location.
[[okl::dim("(4,4)")]] typedef float *mat4;
is completely valid syntax without changing semantic.
Multivar declarations is the corner case and is broken by design regarding standard attributes.
To address this special case the multivar will be splitted into single var using clang-tidy with readability-isolate-declaration fixit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above statement is totally wrong.
typedefs
can define multiple 'aliases' to the same base type.By definition, they are part of one.
Here we have a few solutions:
type
:typedef [[]] int A, *B
typedef int A [[]], *B [[]]
typedef [[]] int A, *B
The second one duplicates the attribute changing it's nature from
type
attribute todecl
attribute.The last one works fine for most cases because we treat special case attributes as
type
attributes anyway.