|
| 1 | +const std = @import("std"); |
| 2 | + |
1 | 3 | const cl = @import("cl.zig"); |
2 | 4 | const opencl = cl.opencl; |
3 | | -const std = @import("std"); |
4 | 5 |
|
5 | | -pub const enums = @import("enums/command_queue.zig"); |
6 | 6 | const errors = @import("errors.zig"); |
| 7 | +pub const OpenCLError = errors.OpenCLError; |
| 8 | + |
| 9 | +pub const Property = struct { |
| 10 | + pub const out_of_order_exec_mode_enable = opencl.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; |
| 11 | + pub const profiling_enable = opencl.CL_QUEUE_PROFILING_ENABLE; |
| 12 | +}; |
| 13 | +pub const Properties = opencl.cl_command_queue_properties; |
| 14 | + |
| 15 | +pub const QueueProperty = struct { |
| 16 | + pub const properties = opencl.CL_QUEUE_PROPERTIES; |
| 17 | + pub const size = opencl.CL_QUEUE_SIZE; |
| 18 | +}; |
| 19 | +pub const QueueProperties = opencl.cl_queue_properties; |
7 | 20 |
|
8 | | -pub const cl_command_queue_properties = opencl.cl_command_queue_properties; |
9 | | -pub const cl_queue_properties = opencl.cl_queue_properties; |
10 | | -pub const cl_command_queue = *opaque {}; |
| 21 | +pub const CommandQueue = *opaque {}; |
11 | 22 |
|
12 | 23 | const cl_context = @import("context.zig").cl_context; |
13 | 24 | const cl_device_id = @import("device.zig").cl_device_id; |
14 | 25 |
|
15 | | -pub inline fn create_with_properties( |
16 | | - context: cl_context, device: cl_device_id, |
17 | | - properties: ?[]const cl_queue_properties |
18 | | -) errors.opencl_error!cl_command_queue { |
19 | | - if (cl.opencl_version < 200) unreachable; |
| 26 | +pub fn create_with_properties( |
| 27 | + context: cl_context, |
| 28 | + device: cl_device_id, |
| 29 | + properties: ?[]const QueueProperties, |
| 30 | +) OpenCLError!CommandQueue { |
| 31 | + if (cl.opencl_version < 200) unreachable; |
20 | 32 |
|
21 | | - var properties_ptr: ?[*]const cl_queue_properties = null; |
| 33 | + var properties_ptr: ?[*]const QueueProperties = null; |
22 | 34 | if (properties) |v| { |
23 | 35 | properties_ptr = v.ptr; |
24 | 36 | } |
25 | 37 |
|
26 | 38 | var ret: i32 = undefined; |
27 | | - const command_queue: ?cl_command_queue = @ptrCast(opencl.clCreateCommandQueueWithProperties( |
28 | | - @ptrCast(context), @ptrCast(device), properties_ptr, &ret |
| 39 | + const command_queue: ?CommandQueue = @ptrCast(opencl.clCreateCommandQueueWithProperties( |
| 40 | + @ptrCast(context), |
| 41 | + @ptrCast(device), |
| 42 | + properties_ptr, |
| 43 | + &ret, |
29 | 44 | )); |
30 | 45 | if (ret == opencl.CL_SUCCESS) return command_queue.?; |
31 | 46 |
|
32 | 47 | const errors_arr = .{ |
33 | | - "invalid_value", "invalid_context", "invalid_device", "invalid_queue_properties", |
34 | | - "out_of_resources", "out_of_host_memory" |
| 48 | + "invalid_value", "invalid_context", |
| 49 | + "invalid_device", "invalid_queue_properties", |
| 50 | + "out_of_resources", "out_of_host_memory", |
35 | 51 | }; |
36 | | - return errors.translate_opencl_error(errors_arr, ret); |
| 52 | + return errors.translateOpenCLError(errors_arr, ret); |
37 | 53 | } |
38 | 54 |
|
39 | | -pub inline fn create( |
40 | | - context: cl_context, device: cl_device_id, |
41 | | - properties: cl_command_queue_properties |
42 | | -) errors.opencl_error!cl_command_queue { |
| 55 | +pub fn create( |
| 56 | + context: cl_context, |
| 57 | + device: cl_device_id, |
| 58 | + properties: Properties, |
| 59 | +) OpenCLError!CommandQueue { |
43 | 60 | var ret: i32 = undefined; |
44 | | - const command_queue: ?cl_command_queue = @ptrCast(opencl.clCreateCommandQueue( |
45 | | - @ptrCast(context), @ptrCast(device), properties, &ret |
| 61 | + const command_queue: ?CommandQueue = @ptrCast(opencl.clCreateCommandQueue( |
| 62 | + @ptrCast(context), |
| 63 | + @ptrCast(device), |
| 64 | + properties, |
| 65 | + &ret, |
46 | 66 | )); |
47 | 67 | if (ret == opencl.CL_SUCCESS) return command_queue.?; |
48 | 68 |
|
49 | 69 | const errors_arr = .{ |
50 | | - "invalid_value", "invalid_context", "invalid_device", "invalid_queue_properties", |
51 | | - "out_of_resources", "out_of_host_memory" |
| 70 | + "invalid_value", "invalid_context", |
| 71 | + "invalid_device", "invalid_queue_properties", |
| 72 | + "out_of_resources", "out_of_host_memory", |
52 | 73 | }; |
53 | | - return errors.translate_opencl_error(errors_arr, ret); |
| 74 | + return errors.translateOpenCLError(errors_arr, ret); |
54 | 75 | } |
55 | 76 |
|
56 | | -pub inline fn flush(command_queue: cl_command_queue) errors.opencl_error!void { |
| 77 | +pub fn flush(command_queue: CommandQueue) OpenCLError!void { |
57 | 78 | const ret: i32 = opencl.clFlush(@ptrCast(command_queue)); |
58 | 79 | if (ret == opencl.CL_SUCCESS) return; |
59 | 80 |
|
60 | 81 | const errors_arr = .{ |
61 | | - "out_of_host_memory", "invalid_command_queue", "out_of_resources" |
| 82 | + "out_of_host_memory", "invalid_command_queue", "out_of_resources", |
62 | 83 | }; |
63 | | - return errors.translate_opencl_error(errors_arr, ret); |
| 84 | + return errors.translateOpenCLError(errors_arr, ret); |
64 | 85 | } |
65 | 86 |
|
66 | | -pub inline fn finish(command_queue: cl_command_queue) errors.opencl_error!void { |
| 87 | +pub fn finish(command_queue: CommandQueue) OpenCLError!void { |
67 | 88 | const ret: i32 = opencl.clFinish(@ptrCast(command_queue)); |
68 | 89 | if (ret == opencl.CL_SUCCESS) return; |
69 | 90 |
|
70 | 91 | const errors_arr = .{ |
71 | | - "out_of_host_memory", "invalid_command_queue", "out_of_resources" |
| 92 | + "out_of_host_memory", "invalid_command_queue", "out_of_resources", |
72 | 93 | }; |
73 | | - return errors.translate_opencl_error(errors_arr, ret); |
| 94 | + return errors.translateOpenCLError(errors_arr, ret); |
74 | 95 | } |
75 | 96 |
|
76 | | -pub inline fn retain(command_queue: cl_command_queue) errors.opencl_error!void { |
| 97 | +pub fn retain(command_queue: CommandQueue) OpenCLError!void { |
77 | 98 | const ret: i32 = opencl.clRetainCommandQueue(@ptrCast(command_queue)); |
78 | 99 | if (ret == opencl.CL_SUCCESS) return; |
79 | 100 |
|
80 | 101 | const errors_arr = .{ |
81 | | - "out_of_host_memory", "invalid_command_queue", "out_of_resources" |
| 102 | + "out_of_host_memory", "invalid_command_queue", "out_of_resources", |
82 | 103 | }; |
83 | | - return errors.translate_opencl_error(errors_arr, ret); |
| 104 | + return errors.translateOpenCLError(errors_arr, ret); |
84 | 105 | } |
85 | 106 |
|
86 | | -pub inline fn release(command_queue: cl_command_queue) void { |
| 107 | +pub fn release(command_queue: CommandQueue) void { |
87 | 108 | const ret: i32 = opencl.clReleaseCommandQueue(@ptrCast(command_queue)); |
88 | 109 | if (ret == opencl.CL_SUCCESS) return; |
89 | 110 |
|
90 | 111 | const errors_arr = .{ |
91 | | - "out_of_host_memory", "invalid_command_queue", "out_of_resources" |
| 112 | + "out_of_host_memory", "invalid_command_queue", "out_of_resources", |
92 | 113 | }; |
93 | | - std.debug.panic("Unexpected error while releasing OpenCL command queue: {s}", .{ |
94 | | - @errorName(errors.translate_opencl_error(errors_arr, ret))} |
| 114 | + std.debug.panic( |
| 115 | + "Unexpected error while releasing OpenCL command queue: {s}", |
| 116 | + .{@errorName(errors.translateOpenCLError(errors_arr, ret))}, |
95 | 117 | ); |
96 | 118 | } |
0 commit comments