-
Notifications
You must be signed in to change notification settings - Fork 57
Cuda casting tests #728
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
Open
CodersAcademy006
wants to merge
12
commits into
NVIDIA:main
Choose a base branch
from
CodersAcademy006:cuda-casting-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cuda casting tests #728
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5c36897
Added proper test cases for test_casting
CodersAcademy006 8868c97
CUDA: Add device-side casting tests for numeric and boolean types (#515)
CodersAcademy006 00f6265
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 c1d4517
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 29aa89e
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 01816bc
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 fa17a01
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 3dc9a44
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 afdf6aa
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 40baf2f
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 2f17d07
Update numba_cuda/numba/cuda/tests/test_casting.py
CodersAcademy006 29cddca
Optimize test_casting: use device_array and remove redundant sync
CodersAcademy006 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import numpy as np | ||
| import numpy as np | ||
|
|
||
| from numba import cuda | ||
|
|
||
| from numba import cuda | ||
| from numba.cuda.testing import CUDATestCase, skip_on_cudasim | ||
|
|
||
|
|
||
| @cuda.jit | ||
| def cast_kernel(inp, out): | ||
| i = cuda.grid(1) | ||
| if i < inp.size: | ||
| out[i] = inp[i] | ||
|
|
||
|
|
||
| @skip_on_cudasim("Casting semantics differ under cudasim") | ||
| class TestCudaCasting(CUDATestCase): | ||
|
|
||
| def _run_cast_test(self, src_dtype, dst_dtype, values): | ||
| src = np.array(values, dtype=src_dtype) | ||
| dst = np.zeros_like(src, dtype=dst_dtype) | ||
|
|
||
| d_src = cuda.to_device(src) | ||
| d_dst = cuda.to_device(dst) | ||
|
|
||
| threadsperblock = 128 | ||
| blockspergrid = (src.size + threadsperblock - 1) // threadsperblock | ||
|
|
||
CodersAcademy006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cast_kernel[blockspergrid, threadsperblock](d_src, d_dst) | ||
| cuda.synchronize() | ||
|
|
||
| cast_kernel[blockspergrid, threadsperblock](d_src, d_dst) | ||
|
|
||
| cast_kernel[blockspergrid, threadsperblock](d_src, d_dst) | ||
| cuda.synchronize() | ||
CodersAcademy006 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| result = d_dst.copy_to_host() | ||
| expected = src.astype(dst_dtype) | ||
|
|
||
| np.testing.assert_array_equal(result, expected) | ||
|
|
||
|
|
||
| def test_int32_to_int64(self): | ||
| self._run_cast_test(np.int32, np.int64, [1, 2, -3, 4]) | ||
|
|
||
|
|
||
| def test_int64_to_int32(self): | ||
| self._run_cast_test(np.int64, np.int32, [1, 2, -3, 4]) | ||
|
|
||
|
|
||
| def test_int_to_float(self): | ||
| self._run_cast_test(np.int32, np.float32, [1, -2, 3, 4]) | ||
|
|
||
|
|
||
| # CUDA follows C-style truncation toward zero | ||
| def test_float_to_int_truncation(self): | ||
| self._run_cast_test(np.float32, np.int32, [1.7, -2.2, 3.9]) | ||
|
|
||
|
|
||
| def test_float32_to_float64(self): | ||
| self._run_cast_test(np.float32, np.float64, [1.5, -2.5, 3.25]) | ||
|
|
||
|
|
||
| def test_bool_to_int(self): | ||
| self._run_cast_test(np.bool_, np.int32, [True, False, True]) | ||
|
|
||
|
|
||
| def test_int_to_bool(self): | ||
| self._run_cast_test(np.int32, np.bool_, [0, 1, 2, -1]) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.