-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f5a240
commit 5e467c5
Showing
5 changed files
with
257 additions
and
16 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import dpnp as np | ||
import numpy | ||
|
||
import numba_dpex as ndpex | ||
from numba_dpex import float32, int32, int64 | ||
|
||
# Array size | ||
N = 10 | ||
|
||
|
||
# A device callable function that can be invoked from | ||
# ``kernel`` and other device functions | ||
@ndpex.func | ||
def a_device_function(a): | ||
return a + 1 | ||
|
||
|
||
# A device callable function with signature that can be invoked | ||
# from ``kernel`` and other device functions | ||
@ndpex.func(int32(int32)) | ||
def a_device_function_int32(a): | ||
return a + 1 | ||
|
||
|
||
# A device callable function with list signature that can be invoked | ||
# from ``kernel`` and other device functions | ||
@ndpex.func([int32(int32), float32(float32)]) | ||
def a_device_function_int32_float32(a): | ||
return a + 1 | ||
|
||
|
||
# A device callable function can call another device function | ||
@ndpex.func | ||
def another_device_function(a): | ||
return a_device_function(a * 2) | ||
|
||
|
||
# A kernel function that calls the device function | ||
@ndpex.kernel | ||
def a_kernel_function(a, b): | ||
i = ndpex.get_global_id(0) | ||
b[i] = a_device_function(a[i]) | ||
|
||
|
||
# A kernel function that calls the device function | ||
@ndpex.kernel | ||
def a_kernel_function_nested(a, b): | ||
i = ndpex.get_global_id(0) | ||
b[i] = another_device_function(a[i]) | ||
|
||
|
||
# A kernel function that calls the device function | ||
@ndpex.kernel | ||
def a_kernel_function_int32(a, b): | ||
i = ndpex.get_global_id(0) | ||
b[i] = a_device_function_int32(a[i]) | ||
|
||
|
||
# A kernel function that calls the device function | ||
@ndpex.kernel | ||
def a_kernel_function_int32_float32(a, b): | ||
i = ndpex.get_global_id(0) | ||
b[i] = a_device_function_int32_float32(a[i]) | ||
|
||
|
||
def test_basic(): | ||
a = np.ones(N) | ||
b = np.ones(N) | ||
|
||
a_kernel_function[N](a, b) | ||
|
||
b = np.asnumpy(b) | ||
expected = numpy.ones(N) + 1 | ||
|
||
assert numpy.array_equal(b, expected) | ||
|
||
|
||
def test_nested(): | ||
a = np.ones(N) | ||
b = np.ones(N) | ||
|
||
a_kernel_function_nested[N](a, b) | ||
|
||
b = np.asnumpy(b) | ||
expected = numpy.ones(N) * 3 | ||
|
||
assert numpy.array_equal(b, expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_basic() | ||
test_nested() |