@@ -476,6 +476,10 @@ const cl_kernel_work_group_info = cl_uint
476
476
477
477
const cl_kernel_sub_group_info = cl_uint
478
478
479
+ const cl_device_svm_capabilities = cl_bitfield
480
+
481
+ const cl_command_queue_properties = cl_bitfield
482
+
479
483
@checked function clGetPlatformIDs (num_entries, platforms, num_platforms)
480
484
@ccall libopencl. clGetPlatformIDs (num_entries:: cl_uint , platforms:: Ptr{cl_platform_id} ,
481
485
num_platforms:: Ptr{cl_uint} ):: cl_int
589
593
event:: Ptr{cl_event} ):: cl_int
590
594
end
591
595
596
+ function clCreateCommandQueue (context, device, properties, errcode_ret)
597
+ @ccall libopencl. clCreateCommandQueue (context:: cl_context , device:: cl_device_id ,
598
+ properties:: cl_command_queue_properties ,
599
+ errcode_ret:: Ptr{cl_int} ):: cl_command_queue
600
+ end
601
+
602
+ @checked function clReleaseCommandQueue (command_queue)
603
+ @ccall libopencl. clReleaseCommandQueue (command_queue:: cl_command_queue ):: cl_int
604
+ end
605
+
606
+ @checked function clFinish (command_queue)
607
+ @ccall libopencl. clFinish (command_queue:: cl_command_queue ):: cl_int
608
+ end
609
+
592
610
# Init
593
611
594
612
# lazy initialization
@@ -886,16 +904,6 @@ function Context(device::Device)
886
904
return Context (ctx_id)
887
905
end
888
906
889
- mutable struct Event
890
- const id:: cl_event
891
-
892
- function Event (evt_id)
893
- evt = new (evt_id)
894
- finalizer (clReleaseEvent, evt)
895
- return evt
896
- end
897
- end
898
-
899
907
mutable struct Program
900
908
const id:: cl_program
901
909
@@ -1138,7 +1146,7 @@ function set_args!(k::Kernel, args...)
1138
1146
end
1139
1147
1140
1148
function enqueue_kernel (k:: Kernel , global_work_size, local_work_size= nothing ;
1141
- global_work_offset= nothing , wait_on :: Vector{Event} = Event[] )
1149
+ global_work_offset= nothing )
1142
1150
max_work_dim = device (). max_work_item_dims
1143
1151
work_dim = length (global_work_size)
1144
1152
if work_dim > max_work_dim
@@ -1181,29 +1189,24 @@ function enqueue_kernel(k::Kernel, global_work_size, local_work_size=nothing;
1181
1189
# null local size means OpenCL decides
1182
1190
end
1183
1191
1184
- if ! isempty (wait_on)
1185
- n_events = cl_uint (length (wait_on))
1186
- wait_event_ids = [evt. id for evt in wait_on]
1187
- else
1188
- n_events = cl_uint (0 )
1189
- wait_event_ids = C_NULL
1190
- end
1192
+ n_events = cl_uint (0 )
1193
+ wait_event_ids = C_NULL
1194
+ ret_event = C_NULL
1191
1195
1192
- ret_event = Ref {cl_event} ()
1193
1196
clEnqueueNDRangeKernel (queue (), k, cl_uint (work_dim), goffset, gsize, lsize,
1194
1197
n_events, wait_event_ids, ret_event)
1195
- return Event (ret_event[], retain = false )
1198
+ return nothing
1196
1199
end
1197
1200
1198
1201
function call (k:: Kernel , args... ; global_size= (1 ,), local_size= nothing ,
1199
- global_work_offset= nothing , wait_on :: Vector{Event} = Event[],
1202
+ global_work_offset= nothing ,
1200
1203
svm_pointers:: Vector{Ptr{Cvoid}} = Ptr{Cvoid}[])
1201
1204
set_args! (k, args... )
1202
1205
if ! isempty (svm_pointers)
1203
1206
clSetKernelExecInfo (k, CL_KERNEL_EXEC_INFO_SVM_PTRS,
1204
1207
sizeof (svm_pointers), svm_pointers)
1205
1208
end
1206
- enqueue_kernel (k, global_size, local_size; global_work_offset, wait_on )
1209
+ enqueue_kernel (k, global_size, local_size; global_work_offset)
1207
1210
end
1208
1211
1209
1212
# convert the argument values to match the kernel's signature (specified by the user)
@@ -1272,4 +1275,36 @@ function Base.getproperty(ki::KernelWorkGroupInfo, s::Symbol)
1272
1275
end
1273
1276
end
1274
1277
1278
+ mutable struct CmdQueue
1279
+ const id:: cl_command_queue
1280
+
1281
+ function CmdQueue (q_id:: cl_command_queue )
1282
+ q = new (q_id)
1283
+ finalizer (q) do _
1284
+ clReleaseCommandQueue (q)
1285
+ end
1286
+ return q
1287
+ end
1288
+ end
1289
+
1290
+ Base. unsafe_convert (:: Type{cl_command_queue} , q:: CmdQueue ) = q. id
1291
+
1292
+ function CmdQueue ()
1293
+ flags= cl_command_queue_properties (0 )
1294
+ err_code = Ref {Cint} ()
1295
+ queue_id = clCreateCommandQueue (context (), device (), flags, err_code)
1296
+ if err_code[] != CL_SUCCESS
1297
+ if queue_id != C_NULL
1298
+ clReleaseCommandQueue (queue_id)
1299
+ end
1300
+ throw (CLError (err_code[]))
1301
+ end
1302
+ return CmdQueue (queue_id)
1303
+ end
1304
+
1305
+ function finish (q:: CmdQueue )
1306
+ clFinish (q)
1307
+ return q
1308
+ end
1309
+
1275
1310
end
0 commit comments