44
55from dpctl import SyclQueue
66from numba import types
7- from numba .extending import NativeValue , box , type_callable , unbox
7+ from numba .core import cgutils
8+ from numba .extending import (
9+ NativeValue ,
10+ as_numba_type ,
11+ box ,
12+ type_callable ,
13+ typeof_impl ,
14+ unbox ,
15+ )
816
17+ from numba_dpex .core .exceptions import UnreachableError
18+ from numba_dpex .core .runtime import context as dpxrtc
919
10- class DpctlSyclQueue (types .Type ):
20+
21+ class SyclQueueType (types .Type ):
1122 """A Numba type to represent a dpctl.SyclQueue PyObject.
1223
1324 For now, a dpctl.SyclQueue is represented as a Numba opaque type that allows
@@ -16,25 +27,99 @@ class DpctlSyclQueue(types.Type):
1627 """
1728
1829 def __init__ (self ):
19- super ().__init__ (name = "DpctlSyclQueueType" )
30+ super (SyclQueueType , self ).__init__ (name = "SyclQueue" )
31+
32+
33+ # sycl_queue_type = SyclQueueType()
2034
2135
22- sycl_queue_ty = DpctlSyclQueue ()
36+ # @typeof_impl.register(SyclQueue)
37+ # def typeof_index(val, c):
38+ # return sycl_queue_type
39+
40+
41+ # as_numba_type.register(SyclQueue, sycl_queue_type)
2342
2443
2544@type_callable (SyclQueue )
26- def type_interval (context ):
27- def typer ():
28- return sycl_queue_ty
45+ def type_sycl_queue (context ):
46+ def typer (args ):
47+ if isinstance (args , types .Tuple ):
48+ if len (args ) > 0 :
49+ if (
50+ isinstance (args [0 ], types .PyObject )
51+ and isinstance (args [1 ], types .StringLiteral )
52+ and isinstance (args [2 ], types .PyObject )
53+ ):
54+ return SyclQueueType ()
55+ else :
56+ return SyclQueueType ()
57+ elif isinstance (args , types .NoneType ):
58+ return SyclQueueType ()
59+ else :
60+ raise ValueError ("Couldn't do type inference for 'SycleQueue'." )
2961
3062 return typer
3163
3264
33- @unbox (DpctlSyclQueue )
65+ # @lower_builtin(SyclQueue, types.PyObject, types.StringLiteral, types.PyObject)
66+ # def impl_interval(context, builder, sig, args):
67+ # typ = sig.return_type
68+ # if len(args) > 0:
69+ # ctx, dev, property = args
70+ # sycl_queue = cgutils.create_struct_proxy(typ)(context, builder)
71+ # sycl_queue.ctx = ctx
72+ # sycl_queue.dev = dev
73+ # sycl_queue.property = property
74+ # else:
75+ # sycl_queue = cgutils.create_struct_proxy(typ)(context, builder)
76+ # return sycl_queue._getvalue()
77+
78+
79+ @unbox (SyclQueueType )
3480def unbox_sycl_queue (typ , obj , c ):
35- return NativeValue (obj )
81+ """
82+ Convert a SyclQueue object to a native structure.
83+ """
84+ qstruct = cgutils .create_struct_proxy (typ )(c .context , c .builder )
85+ qptr = qstruct ._getpointer ()
86+ ptr = c .builder .bitcast (qptr , c .pyapi .voidptr )
87+ if c .context .enable_nrt :
88+ dpexrtCtx = dpxrtc .DpexRTContext (c .context )
89+ errcode = dpexrtCtx .queuestruct_from_python (c .pyapi , obj , ptr )
90+ else :
91+ raise UnreachableError
92+
93+ is_error = cgutils .is_not_null (c .builder , errcode )
94+ # Handle error
95+ with c .builder .if_then (is_error , likely = False ):
96+ c .pyapi .err_set_string (
97+ "PyExc_TypeError" ,
98+ "can't unbox array from PyObject into "
99+ "native value. The object maybe of a "
100+ "different type" ,
101+ )
102+
103+ return NativeValue (c .builder .load (qptr ), is_error = is_error )
36104
37105
38- @box (DpctlSyclQueue )
39- def box_pyobject (typ , val , c ):
40- return val
106+ # @box(SyclQueueType)
107+ # def box_sycl_queue_(typ, val, c):
108+ # """
109+ # Convert a native interval structure to an Interval object.
110+ # """
111+ # sycl_queue = cgutils.create_struct_proxy(typ)(
112+ # c.context, c.builder, value=val
113+ # )
114+ # ctx_obj = sycl_queue.ctx
115+ # dev_obj = sycl_queue.dev
116+ # property_obj = sycl_queue.property
117+ # class_obj = c.pyapi.unserialize(c.pyapi.serialize_object(SyclQueue))
118+ # res = c.pyapi.call_function_objargs(
119+ # class_obj, (ctx_obj, dev_obj, property_obj)
120+ # )
121+ # c.pyapi.decref(ctx_obj)
122+ # c.pyapi.decref(dev_obj)
123+ # c.pyapi.decref(property_obj)
124+ # c.pyapi.decref(class_obj)
125+ # return res
0 commit comments