Skip to content

Commit

Permalink
Move dpctl event datamodel wrapper to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzEeKkAa committed Nov 28, 2023
1 parent 0c3620e commit 05aa34d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
22 changes: 3 additions & 19 deletions numba_dpex/dpctl_iface/_intrinsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import dpctl
from llvmlite.ir import IRBuilder
from numba import types
from numba.core import cgutils, imputils
from numba.core.datamodel import default_manager
from numba.extending import intrinsic, overload, overload_method, type_callable
from numba.extending import intrinsic, overload, overload_method

import numba_dpex.dpctl_iface.libsyclinterface_bindings as sycl
from numba_dpex.core import types as dpex_types
from numba_dpex.core.runtime import context as dpexrt
from numba_dpex.dpctl_iface.wrappers import wrap_event_reference


@intrinsic
Expand All @@ -33,23 +32,8 @@ def sycl_event_create(
sig = ty_event(types.void)

def codegen(context, builder: IRBuilder, sig, args: list):
pyapi = context.get_python_api(builder)

event_struct_proxy = cgutils.create_struct_proxy(ty_event)(
context, builder
)

event = sycl.dpctl_event_create(builder)
dpexrtCtx = dpexrt.DpexRTContext(context)

# Ref count after the call is equal to 1.
dpexrtCtx.eventstruct_init(
pyapi, event, event_struct_proxy._getpointer()
)

event_value = event_struct_proxy._getvalue()

return event_value
return wrap_event_reference(context, builder, event)

return sig, codegen

Expand Down
35 changes: 35 additions & 0 deletions numba_dpex/dpctl_iface/wrappers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

from numba.core import cgutils

from numba_dpex.core.runtime import context as dpexrt
from numba_dpex.core.types import DpctlSyclEvent


def wrap_event_reference(ctx, builder, eref):
"""Wrap dpctl event reference into datamodel so it can be boxed to
Python."""

ty_event = DpctlSyclEvent()

pyapi = ctx.get_python_api(builder)

event_struct_proxy = cgutils.create_struct_proxy(ty_event)(ctx, builder)

# Ref count after the call is equal to 1.
# TODO: get dpex RT from cached property once the PR is merged
# https://github.com/IntelPython/numba-dpex/pull/1027
# ctx.dpexrt.eventstruct_init( # noqa: W0621
dpexrt.DpexRTContext(ctx).eventstruct_init(
pyapi,
eref,
# calling _<method>() is by numba's design
event_struct_proxy._getpointer(), # pylint: disable=W0212
)

# calling _<method>() is by numba's design
event_value = event_struct_proxy._getvalue() # pylint: disable=W0212

return event_value

0 comments on commit 05aa34d

Please sign in to comment.