-
Notifications
You must be signed in to change notification settings - Fork 81
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
Showing
3 changed files
with
159 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
import numpy as np # noqa: F401 | ||
import pytest # noqa: F401 | ||
|
||
import awkward as ak # noqa: F401 | ||
|
||
numba = pytest.importorskip("numba") | ||
|
||
from numba.extending import overload_method | ||
from numba import cuda, types | ||
|
||
from numba import config | ||
config.CUDA_LOW_OCCUPANCY_WARNINGS = False | ||
config.CUDA_WARN_ON_IMPLICIT_COPY = False | ||
|
||
@overload_method(types.Array, 'sum', target='cuda') | ||
def array_sum(arr): | ||
if arr.ndim != 1: | ||
# Only implement 1D for this quick example | ||
return None | ||
|
||
def sum_impl(arr): | ||
res = 0 | ||
for i in range(len(arr)): | ||
res += arr[i] | ||
return res | ||
return sum_impl | ||
|
||
@cuda.jit | ||
def f(arr): | ||
print("Sum is", arr.sum()) | ||
|
||
|
||
def test_overload_method(): | ||
f[1, 1](np.arange(5)) | ||
f[1, 1](np.arange(10)) | ||
cuda.synchronize() |
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