Skip to content

Commit

Permalink
Merge pull request #1174 from IntelPython/refactor/dpctl_iface
Browse files Browse the repository at this point in the history
Refactor the dpctl_iface module.
  • Loading branch information
Diptorup Deb authored Oct 15, 2023
2 parents 524495f + 922055a commit 6e6e6e3
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 920 deletions.
19 changes: 4 additions & 15 deletions numba_dpex/core/parfors/reduction_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from numba_dpex import utils
from numba_dpex.core.utils.kernel_launcher import KernelLaunchIRBuilder
from numba_dpex.dpctl_iface import DpctlCAPIFnBuilder
from numba_dpex.dpctl_iface import libsyclinterface_bindings as sycl

from ..types.dpnp_ndarray_type import DpnpNdArray

Expand Down Expand Up @@ -408,16 +408,6 @@ def copy_final_sum_to_host(self, parfor_kernel):
builder = lowerer.builder
context = lowerer.context

memcpy_fn = DpctlCAPIFnBuilder.get_dpctl_queue_memcpy(
builder=builder, context=context
)
event_del_fn = DpctlCAPIFnBuilder.get_dpctl_event_delete(
builder=builder, context=context
)
event_wait_fn = DpctlCAPIFnBuilder.get_dpctl_event_wait(
builder=builder, context=context
)

for i, redvar in enumerate(self.parfor_redvars):
srcVar = self.final_sum_names[i]

Expand Down Expand Up @@ -453,9 +443,8 @@ def copy_final_sum_to_host(self, parfor_kernel):
builder.load(item_size),
]

event_ref = builder.call(memcpy_fn, args)

builder.call(event_wait_fn, [event_ref])
builder.call(event_del_fn, [event_ref])
event_ref = sycl.dpctl_queue_memcpy(builder, *args)
sycl.dpctl_event_wait(builder, event_ref)
sycl.dpctl_event_delete(builder, event_ref)

ir_builder.free_queue(sycl_queue_val=curr_queue)
24 changes: 0 additions & 24 deletions numba_dpex/core/runtime/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,27 +402,3 @@ def submit_ndrange(
)

return ret

def copy_queue(self, builder, queue_ref):
"""Calls DPCTLQueue_Copy to create a copy of the DpctlSyclQueueRef
pointer passed in to the function.
Args:
builder: The llvmlite.IRBuilder used to generate the LLVM IR for the
call.
queue_ref: An LLVM value for a DpctlSyclQueueRef pointer that will
be passed to the DPCTLQueue_Copy function.
Returns: A DPCTLSyclQueueRef pointer.
"""
mod = builder.module
fnty = llvmir.FunctionType(
cgutils.voidptr_t,
[cgutils.voidptr_t],
)
fn = cgutils.get_or_insert_function(mod, fnty, "DPCTLQueue_Copy")
fn.return_value.add_attribute("noalias")

ret = builder.call(fn, [queue_ref])

return ret
8 changes: 3 additions & 5 deletions numba_dpex/core/utils/kernel_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from numba_dpex import utils
from numba_dpex.core.runtime.context import DpexRTContext
from numba_dpex.core.types import DpnpNdArray
from numba_dpex.dpctl_iface import DpctlCAPIFnBuilder
from numba_dpex.dpctl_iface import libsyclinterface_bindings as sycl
from numba_dpex.dpctl_iface._helpers import numba_type_to_dpctl_typenum


Expand Down Expand Up @@ -283,10 +283,8 @@ def free_queue(self, sycl_queue_val):
Args:
sycl_queue_val: The SYCL queue pointer to be freed.
"""
fn = DpctlCAPIFnBuilder.get_dpctl_queue_delete(
builder=self.builder, context=self.context
)
self.builder.call(fn, [self.builder.load(sycl_queue_val)])
qref = self.builder.load(sycl_queue_val)
sycl.dpctl_queue_delete(self.builder, qref)

def allocate_kernel_arg_array(self, num_kernel_args):
"""Allocates an array to store the LLVM Value for every kernel argument.
Expand Down
26 changes: 2 additions & 24 deletions numba_dpex/dpctl_iface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
# SPDX-License-Identifier: Apache-2.0

"""
The ``dpctl_iface`` module implements Numba's interface to the dpctl library
that provides Python and C bindings to DPC++'s SYCL runtime API. The module
includes:
- LLVM IR builders for dpctl C API functions to be called directly from a Numba
generated LLVM module.
- Functions to launch kernels on the dpctl "current queue".
The ``dpctl_iface`` module implements Numba's interface to the libsyclinterface
library that provides C bindings to DPC++'s SYCL runtime API.
"""
import numba_dpex.dpctl_iface.dpctl_function_types as dpctl_fn_ty
from numba_dpex.dpctl_iface.dpctl_capi_fn_builder import DpctlCAPIFnBuilder
from numba_dpex.dpctl_iface.legacy_kernel_launch_ops import KernelLaunchOps

__all__ = [
DpctlCAPIFnBuilder,
KernelLaunchOps,
]

get_current_queue = dpctl_fn_ty.dpctl_get_current_queue()
malloc_shared = dpctl_fn_ty.dpctl_malloc_shared()
queue_memcpy = dpctl_fn_ty.dpctl_queue_memcpy()
free_with_queue = dpctl_fn_ty.dpctl_free_with_queue()
event_wait = dpctl_fn_ty.dpctl_event_wait()
event_delete = dpctl_fn_ty.dpctl_event_delete()
queue_wait = dpctl_fn_ty.dpctl_queue_wait()
Loading

0 comments on commit 6e6e6e3

Please sign in to comment.