-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat[next] Enable GPU backend tests #1357
Changes from 16 commits
5c179a1
f831491
7aecb09
393e196
5e579fa
7a65671
ff0af76
b68c320
58763d4
6169275
f7d83da
316b420
c4bf2cd
7693b70
9532a54
a989a76
7a91d27
995a4f8
65617c6
158c2e0
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -117,12 +117,19 @@ def from_case( | |||||||||||||||||
return self | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
@dataclasses.dataclass | ||||||||||||||||||
@dataclasses.dataclass(init=False) | ||||||||||||||||||
class ConstInitializer(DataInitializer): | ||||||||||||||||||
"""Initialize with a given value across the coordinate space.""" | ||||||||||||||||||
|
||||||||||||||||||
value: ScalarValue | ||||||||||||||||||
|
||||||||||||||||||
def __init__(self, value: ScalarValue): | ||||||||||||||||||
if hasattr(value, "__array__") or hasattr(value, "__getitem__"): | ||||||||||||||||||
raise ValueError( | ||||||||||||||||||
"`ConstInitializer` can not be used with non-scalars. Use `Case.as_field` instead." | ||||||||||||||||||
) | ||||||||||||||||||
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.
Suggested change
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. I changed that... |
||||||||||||||||||
self.value = value | ||||||||||||||||||
|
||||||||||||||||||
@property | ||||||||||||||||||
def scalar_value(self) -> ScalarValue: | ||||||||||||||||||
return self.value | ||||||||||||||||||
|
@@ -460,7 +467,7 @@ def verify_with_default_data( | |||||||||||||||||
``comparison(ref, <out | inout>)`` and should return a boolean. | ||||||||||||||||||
""" | ||||||||||||||||||
inps, kwfields = get_default_data(case, fieldop) | ||||||||||||||||||
ref_args = tuple(i.ndarray if hasattr(i, "ndarray") else i for i in inps) | ||||||||||||||||||
ref_args = tuple(i.__array__() if common.is_field(i) else i for i in inps) | ||||||||||||||||||
verify( | ||||||||||||||||||
case, | ||||||||||||||||||
fieldop, | ||||||||||||||||||
|
@@ -598,3 +605,7 @@ class Case: | |||||||||||||||||
offset_provider: dict[str, common.Connectivity | gtx.Dimension] | ||||||||||||||||||
default_sizes: dict[gtx.Dimension, int] | ||||||||||||||||||
grid_type: common.GridType | ||||||||||||||||||
|
||||||||||||||||||
@property | ||||||||||||||||||
def as_field(self): | ||||||||||||||||||
return constructors.as_field.partial(allocator=self.backend) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
def test_maxover_execution_(unstructured_case, strategy): | ||
if unstructured_case.backend in [ | ||
gtfn.run_gtfn, | ||
gtfn.run_gtfn_gpu, | ||
gtfn.run_gtfn_imperative, | ||
gtfn.run_gtfn_with_temporaries, | ||
]: | ||
|
@@ -137,10 +138,7 @@ def conditional_nested_tuple( | |
return where(mask, ((a, b), (b, a)), ((5.0, 7.0), (7.0, 5.0))) | ||
|
||
size = cartesian_case.default_sizes[IDim] | ||
bool_field = np.random.choice(a=[False, True], size=(size)) | ||
mask = cases.allocate(cartesian_case, conditional_nested_tuple, "mask").strategy( | ||
cases.ConstInitializer(bool_field) | ||
)() | ||
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=size)) | ||
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. could we built in to cases that boolean fields are allocated with alternating values by default? 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. maybe in a follow-up PR to get the GPU support in |
||
a = cases.allocate(cartesian_case, conditional_nested_tuple, "a")() | ||
b = cases.allocate(cartesian_case, conditional_nested_tuple, "b")() | ||
|
||
|
@@ -210,10 +208,7 @@ def conditional( | |
return where(mask, a, b) | ||
|
||
size = cartesian_case.default_sizes[IDim] | ||
bool_field = np.random.choice(a=[False, True], size=(size)) | ||
mask = cases.allocate(cartesian_case, conditional, "mask").strategy( | ||
cases.ConstInitializer(bool_field) | ||
)() | ||
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size))) | ||
a = cases.allocate(cartesian_case, conditional, "a")() | ||
b = cases.allocate(cartesian_case, conditional, "b")() | ||
out = cases.allocate(cartesian_case, conditional, cases.RETURN)() | ||
|
@@ -227,10 +222,7 @@ def conditional_promotion(mask: cases.IBoolField, a: cases.IFloatField) -> cases | |
return where(mask, a, 10.0) | ||
|
||
size = cartesian_case.default_sizes[IDim] | ||
bool_field = np.random.choice(a=[False, True], size=(size)) | ||
mask = cases.allocate(cartesian_case, conditional_promotion, "mask").strategy( | ||
cases.ConstInitializer(bool_field) | ||
)() | ||
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size))) | ||
a = cases.allocate(cartesian_case, conditional_promotion, "a")() | ||
out = cases.allocate(cartesian_case, conditional_promotion, cases.RETURN)() | ||
|
||
|
@@ -267,7 +259,7 @@ def conditional_program( | |
conditional_shifted(mask, a, b, out=out) | ||
|
||
size = cartesian_case.default_sizes[IDim] + 1 | ||
mask = gtx.as_field([IDim], np.random.choice(a=[False, True], size=(size))) | ||
mask = cartesian_case.as_field([IDim], np.random.choice(a=[False, True], size=(size))) | ||
a = cases.allocate(cartesian_case, conditional_program, "a").extend({IDim: (0, 1)})() | ||
b = cases.allocate(cartesian_case, conditional_program, "b").extend({IDim: (0, 1)})() | ||
out = cases.allocate(cartesian_case, conditional_shifted, cases.RETURN)() | ||
|
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.
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.
and remove
ScalarValue
completelyThere 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.
... but kept
ScalarValue
pointing tocore_defs.Scalar
as this seems to be the pattern that is used in this field