-
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
Showing
8 changed files
with
250 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _EXPERIMENTAL_H_ | ||
#define _EXPERIMENTAL_H_ | ||
|
||
#include "dpctl_capi.h" | ||
#include "numba/core/runtime/nrt_external.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
DPCTLSyclEventRef | ||
DPEXRT_schedule_nrt_meminfo_release(NRT_api_functions *nrt, | ||
DPCTLSyclQueueRef QRef, | ||
NRT_MemInfo **meminfo_array, | ||
size_t meminfo_array_size, | ||
DPCTLSyclEventRef *depERefs, | ||
size_t nDepERefs, | ||
int *status); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _EXPERIMENTAL_H_ */ |
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,55 @@ | ||
#include "experimental.h" | ||
|
||
#include "_dbg_printer.h" | ||
#include "syclinterface/dpctl_sycl_type_casters.hpp" | ||
#include <CL/sycl.hpp> | ||
|
||
extern "C" | ||
{ | ||
DPCTLSyclEventRef | ||
DPEXRT_schedule_nrt_meminfo_release(NRT_api_functions *nrt, | ||
DPCTLSyclQueueRef QRef, | ||
NRT_MemInfo **meminfo_array, | ||
size_t meminfo_array_size, | ||
DPCTLSyclEventRef *depERefs, | ||
size_t nDepERefs, | ||
int *status) | ||
{ | ||
using dpctl::syclinterface::unwrap; | ||
using dpctl::syclinterface::wrap; | ||
|
||
sycl::queue *q = unwrap<sycl::queue>(QRef); | ||
|
||
std::vector<NRT_MemInfo *> meminfo_vec( | ||
meminfo_array, meminfo_array + meminfo_array_size); | ||
|
||
try { | ||
sycl::event ht_ev = q->submit([&](sycl::handler &cgh) { | ||
for (size_t ev_id = 0; ev_id < nDepERefs; ++ev_id) { | ||
cgh.depends_on(*(unwrap<sycl::event>(depERefs[ev_id]))); | ||
} | ||
cgh.host_task([meminfo_array_size, meminfo_vec, nrt]() { | ||
for (size_t i = 0; i < meminfo_array_size; ++i) { | ||
nrt->release(meminfo_vec[i]); | ||
} | ||
}); | ||
}); | ||
|
||
constexpr int result_ok = 0; | ||
|
||
*status = result_ok; | ||
auto e_ptr = new sycl::event(ht_ev); | ||
return wrap<sycl::event>(e_ptr); | ||
} catch (const std::exception &e) { | ||
constexpr int result_std_exception = 1; | ||
|
||
*status = result_std_exception; | ||
return nullptr; | ||
} | ||
|
||
constexpr int result_other_abnormal = 2; | ||
|
||
*status = result_other_abnormal; | ||
return nullptr; | ||
} | ||
} |
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,63 @@ | ||
import time | ||
|
||
import dpnp | ||
|
||
import numba_dpex as dpex | ||
import numba_dpex.experimental as exp_dpex | ||
from numba_dpex import Range | ||
|
||
|
||
@exp_dpex.kernel( | ||
release_gil=False, | ||
no_compile=True, | ||
no_cpython_wrapper=True, | ||
no_cfunc_wrapper=True, | ||
) | ||
def add(a, b, c): | ||
i = dpex.get_global_id(0) | ||
c[i] = b[i] + a[i] | ||
|
||
|
||
@exp_dpex.kernel( | ||
release_gil=False, | ||
no_compile=True, | ||
no_cpython_wrapper=True, | ||
no_cfunc_wrapper=True, | ||
) | ||
def count_of_two(a, count): | ||
i = dpex.get_global_id(0) | ||
# if a[i]==2: | ||
dpex.atomic.add(count, a[i], 1) | ||
|
||
|
||
def test_async_add(): | ||
size = 1000_000_000 | ||
# size = 1000 | ||
a = dpnp.ones(size) | ||
b = dpnp.ones(size) | ||
c = dpnp.zeros(size) | ||
count = dpnp.zeros(10) | ||
print(a) | ||
print(b) | ||
print(c) | ||
|
||
r = Range(size) | ||
r2 = Range(480) | ||
|
||
event_ref = exp_dpex.call_kernel(add, r, a, b, c) | ||
print(event_ref) | ||
event_ref.wait() | ||
|
||
# time.sleep(3) | ||
|
||
event_ref2 = exp_dpex.call_kernel(count_of_two, r2, b, count) | ||
event_ref2.wait() | ||
print(count) | ||
|
||
count[0] = 0 | ||
|
||
print(c) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_async_add() |