-
Notifications
You must be signed in to change notification settings - Fork 188
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
[FEA]: Validate cuda.parallel type matching in build and execution #2429
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1375779
Brute force experiment: Which tests fail after adding an `assert False`?
rwgk 012494a
Merge branch 'main' into cuda_parallel_type_matching
rwgk a6b9b8d
Merge branch 'main' into cuda_parallel_type_matching
rwgk d955d17
Do not include our own string.h file (#2444)
miscco 6ff4ff3
Merge branch 'main' of https://github.com/NVIDIA/cccl
rwgk 0069666
Merge branch 'main' of https://github.com/NVIDIA/cccl
rwgk 365f55a
Merge branch 'main' into cuda_parallel_type_matching
rwgk 55fb992
Add `_dtype_validation()` in python/cuda_parallel/cuda/parallel/exper…
rwgk 035970c
Add `test_device_reduce_dtype_mismatch()`. Capture `dtype`s only in …
rwgk f8485b9
Undo change in .gitignore
rwgk 4bc44b4
Merge branch 'main' of https://github.com/NVIDIA/cccl
rwgk ec18cd0
Merge branch 'main' into cuda_parallel_type_matching
rwgk 6977ac1
Merge branch 'main' of https://github.com/NVIDIA/cccl
rwgk 4425781
Merge branch 'main' into cuda_parallel_type_matching
rwgk fd33c95
Move `min_op()` back into `test_device_reduce_success()` to unbreak s…
rwgk f4c6d83
Move `test_device_reduce_dtype_mismatch()` from test_reduce_api.py to…
rwgk 063e467
Add TODO POINTER vs ITERATOR
rwgk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,19 +11,21 @@ | |
# example-end imports | ||
|
||
|
||
def test_device_reduce(): | ||
# example-begin reduce-min | ||
def op(a, b): | ||
return a if a < b else b | ||
# example-begin reduce-min | ||
def min_op(a, b): | ||
return a if a < b else b | ||
# example-end reduce-min | ||
|
||
|
||
def test_device_reduce_success(): | ||
dtype = numpy.int32 | ||
h_init = numpy.array([42], dtype) | ||
h_input = numpy.array([8, 6, 7, 5, 3, 0, 9]) | ||
h_input = numpy.array([8, 6, 7, 5, 3, 0, 9], dtype) | ||
d_output = cuda.device_array(1, dtype) | ||
d_input = cuda.to_device(h_input) | ||
|
||
# Instantiate reduction for the given operator and initial value | ||
reduce_into = cudax.reduce_into(d_output, d_output, op, h_init) | ||
reduce_into = cudax.reduce_into(d_output, d_output, min_op, h_init) | ||
|
||
# Deterrmine temporary device storage requirements | ||
temp_storage_size = reduce_into(None, d_input, d_output, h_init) | ||
|
@@ -38,3 +40,17 @@ def op(a, b): | |
# example-end reduce-min | ||
h_output = d_output.copy_to_host() | ||
assert h_output[0] == expected_output | ||
|
||
|
||
def test_device_reduce_dtype_mismatch(): | ||
dtypes = [numpy.int32, numpy.int64] | ||
h_inits = [numpy.array([], dt) for dt in dtypes] | ||
h_inputs = [numpy.array([], dt) for dt in dtypes] | ||
d_outputs = [cuda.device_array(1, dt) for dt in dtypes] | ||
d_inputs = [cuda.to_device(h_inp) for h_inp in h_inputs] | ||
|
||
reduce_into = cudax.reduce_into(d_inputs[0], d_outputs[0], min_op, h_inits[0]) | ||
|
||
for ix in range(3): | ||
with pytest.raises(TypeError, match=r"dtype mismatch: __init__=int32, __call__=int64"): | ||
reduce_into(None, d_inputs[int(ix == 0)], d_outputs[int(ix == 1)], h_inits[int(ix == 2)]) | ||
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. important: this file's purpose is testing code snippets in our docs. Let's put functionality tests into 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. Done. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
important: the
test_*_api
files are used for documentation purposes. They illustrate usage of API. Sphinx essentially copy-pastes code between theexample-begin reduce-min
andexample-begin reduce-min
labels. Here's an example how it looked like. This cange makes it so that our reference API documentation only containsmin_op
definition. Let's revert this change.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.
Done. Thanks for the explanation!
I only kept some minor changes.