@@ -20,20 +20,20 @@ def _check_null_result(func):
20
20
@functools .wraps (func )
21
21
def wrap (self , builder , * args , ** kwargs ):
22
22
memptr = func (self , builder , * args , ** kwargs )
23
- msg = "USM allocation failed. Check the usm_type and filter "
24
- "string values."
23
+ msg = "USM allocation failed. Check the usm_type and queue."
25
24
cgutils .guard_memory_error (self ._context , builder , memptr , msg = msg )
26
25
return memptr
27
26
28
27
return wrap
29
28
30
29
@_check_null_result
31
- def meminfo_alloc (self , builder , size , usm_type , device ):
30
+ def meminfo_alloc (self , builder , size , usm_type , queue_ref ):
32
31
"""
33
32
Wrapper to call :func:`~context.DpexRTContext.meminfo_alloc_unchecked`
34
33
with null checking of the returned value.
35
34
"""
36
- return self .meminfo_alloc_unchecked (builder , size , usm_type , device )
35
+
36
+ return self .meminfo_alloc_unchecked (builder , size , usm_type , queue_ref )
37
37
38
38
@_check_null_result
39
39
def meminfo_fill (
@@ -44,7 +44,7 @@ def meminfo_fill(
44
44
dest_is_float ,
45
45
value_is_float ,
46
46
value ,
47
- device ,
47
+ queue_ref ,
48
48
):
49
49
"""
50
50
Wrapper to call :func:`~context.DpexRTContext.meminfo_fill_unchecked`
@@ -57,28 +57,34 @@ def meminfo_fill(
57
57
dest_is_float ,
58
58
value_is_float ,
59
59
value ,
60
- device ,
60
+ queue_ref ,
61
61
)
62
62
63
- def meminfo_alloc_unchecked (self , builder , size , usm_type , device ):
63
+ def meminfo_alloc_unchecked (self , builder , size , usm_type , queue_ref ):
64
64
"""Allocate a new MemInfo with a data payload of `size` bytes.
65
65
66
66
The result of the call is checked and if it is NULL, i.e. allocation
67
67
failed, then a MemoryError is raised. If the allocation succeeded then
68
68
a pointer to the MemInfo is returned.
69
69
70
70
Args:
71
- builder (_type_): LLVM IR builder
72
- size (_type_): LLVM uint64 Value specifying the size in bytes for
73
- the data payload.
74
- usm_type (_type_): An LLVM Constant Value specifying the type of the
75
- usm allocator. The constant value should match the values in
76
- ``dpctl's`` ``libsyclinterface::DPCTLSyclUSMType`` enum.
77
- device (_type_): An LLVM ArrayType storing a const string for a
78
- DPC++ filter selector string.
79
-
80
- Returns: A pointer to the MemInfo is returned.
71
+ builder (`llvmlite.ir.builder.IRBuilder`): LLVM IR builder.
72
+ size (`llvmlite.ir.values.Argument`): LLVM uint64 value specifying
73
+ the size in bytes for the data payload, i.e. i64 %"arg.allocsize"
74
+ usm_type (`llvmlite.ir.values.Argument`): An LLVM Argument object
75
+ specifying the type of the usm allocator. The constant value
76
+ should match the values in
77
+ ``dpctl's`` ``libsyclinterface::DPCTLSyclUSMType`` enum,
78
+ i.e. i64 %"arg.usm_type".
79
+ queue_ref (`llvmlite.ir.values.Argument`): An LLVM argument value storing
80
+ the pointer to the address of the queue object, the object can be
81
+ `dpctl.SyclQueue()`, i.e. i8* %"arg.queue".
82
+
83
+ Returns:
84
+ ret (`llvmlite.ir.instructions.CallInstr`): A pointer to the `MemInfo`
85
+ is returned from the `DPEXRT_MemInfo_alloc` C function call.
81
86
"""
87
+
82
88
mod = builder .module
83
89
u64 = llvmir .IntType (64 )
84
90
fnty = llvmir .FunctionType (
@@ -87,7 +93,7 @@ def meminfo_alloc_unchecked(self, builder, size, usm_type, device):
87
93
fn = cgutils .get_or_insert_function (mod , fnty , "DPEXRT_MemInfo_alloc" )
88
94
fn .return_value .add_attribute ("noalias" )
89
95
90
- ret = builder .call (fn , [size , usm_type , device ])
96
+ ret = builder .call (fn , [size , usm_type , queue_ref ])
91
97
92
98
return ret
93
99
@@ -99,7 +105,7 @@ def meminfo_fill_unchecked(
99
105
dest_is_float ,
100
106
value_is_float ,
101
107
value ,
102
- device ,
108
+ queue_ref ,
103
109
):
104
110
"""Fills an allocated `MemInfo` with the value specified.
105
111
@@ -108,17 +114,29 @@ def meminfo_fill_unchecked(
108
114
is succeeded then a pointer to the `MemInfo` is returned.
109
115
110
116
Args:
111
- builder (llvmlite.ir.builder.IRBuilder): LLVM IR builder
112
- meminfo (llvmlite.ir.instructions.LoadInstr): LLVM uint64 value
117
+ builder (` llvmlite.ir.builder.IRBuilder` ): LLVM IR builder.
118
+ meminfo (` llvmlite.ir.instructions.LoadInstr` ): LLVM uint64 value
113
119
specifying the size in bytes for the data payload.
114
- itemsize (llvmlite.ir.values.Constant): An LLVM Constant value
120
+ itemsize (` llvmlite.ir.values.Constant` ): An LLVM Constant value
115
121
specifying the size of the each data item allocated by the
116
122
usm allocator.
117
- device (llvmlite.ir.values.FormattedConstant): An LLVM ArrayType
118
- storing a const string for a DPC++ filter selector string.
123
+ dest_is_float (`llvmlite.ir.values.Constant`): An LLVM Constant
124
+ value specifying if the destination array type is floating
125
+ point.
126
+ value_is_float (`llvmlite.ir.values.Constant`): An LLVM Constant
127
+ value specifying if the input value is a floating point.
128
+ value (`llvmlite.ir.values.Constant`): An LLVM Constant value
129
+ specifying if the input value that will be used to fill
130
+ the array.
131
+ queue_ref (`llvmlite.ir.instructions.ExtractValue`): An LLVM ExtractValue
132
+ instruction object to extract the pointer to the queue from the
133
+ DpctlSyclQueue type, i.e. %".74" = extractvalue {i8*, i8*} %".73", 1.
119
134
120
- Returns: A pointer to the `MemInfo` is returned.
135
+ Returns:
136
+ ret (`llvmlite.ir.instructions.CallInstr`): A pointer to the `MemInfo`
137
+ is returned from the `DPEXRT_MemInfo_fill` C function call.
121
138
"""
139
+
122
140
mod = builder .module
123
141
u64 = llvmir .IntType (64 )
124
142
b = llvmir .IntType (1 )
@@ -131,7 +149,14 @@ def meminfo_fill_unchecked(
131
149
132
150
ret = builder .call (
133
151
fn ,
134
- [meminfo , itemsize , dest_is_float , value_is_float , value , device ],
152
+ [
153
+ meminfo ,
154
+ itemsize ,
155
+ dest_is_float ,
156
+ value_is_float ,
157
+ value ,
158
+ queue_ref ,
159
+ ],
135
160
)
136
161
137
162
return ret
@@ -154,7 +179,6 @@ def arraystruct_from_python(self, pyapi, obj, ptr):
154
179
155
180
def queuestruct_from_python (self , pyapi , obj , ptr ):
156
181
"""Calls the c function DPEXRT_sycl_queue_from_python"""
157
-
158
182
fnty = llvmir .FunctionType (
159
183
llvmir .IntType (32 ), [pyapi .pyobj , pyapi .voidptr ]
160
184
)
@@ -164,7 +188,6 @@ def queuestruct_from_python(self, pyapi, obj, ptr):
164
188
fn .args [1 ].add_attribute ("nocapture" )
165
189
166
190
self .error = pyapi .builder .call (fn , (obj , ptr ))
167
-
168
191
return self .error
169
192
170
193
def queuestruct_to_python (self , pyapi , val ):
@@ -258,7 +281,7 @@ def submit_range(
258
281
"""Calls DPEXRTQueue_CreateFromFilterString to create a new sycl::queue
259
282
from a given filter string.
260
283
261
- Returns: A LLVM IR call inst .
284
+ Returns: A DPCTLSyclQueueRef pointer .
262
285
"""
263
286
mod = builder .module
264
287
fnty = llvmir .FunctionType (
@@ -353,3 +376,27 @@ def submit_ndrange(
353
376
)
354
377
355
378
return ret
379
+
380
+ def copy_queue (self , builder , queue_ref ):
381
+ """Calls DPCTLQueue_Copy to create a copy of the DpctlSyclQueueRef
382
+ pointer passed in to the function.
383
+
384
+ Args:
385
+ builder: The llvmlite.IRBuilder used to generate the LLVM IR for the
386
+ call.
387
+ queue_ref: An LLVM value for a DpctlSyclQueueRef pointer that will
388
+ be passed to the DPCTLQueue_Copy function.
389
+
390
+ Returns: A DPCTLSyclQueueRef pointer.
391
+ """
392
+ mod = builder .module
393
+ fnty = llvmir .FunctionType (
394
+ cgutils .voidptr_t ,
395
+ [cgutils .voidptr_t ],
396
+ )
397
+ fn = cgutils .get_or_insert_function (mod , fnty , "DPCTLQueue_Copy" )
398
+ fn .return_value .add_attribute ("noalias" )
399
+
400
+ ret = builder .call (fn , [queue_ref ])
401
+
402
+ return ret
0 commit comments