Skip to content

Commit 3f1f039

Browse files
committed
Fix context construction by property.
1 parent ee8036d commit 3f1f039

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

lib/cl/context.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function Context(devs::Vector{Device};
6666
ArgumentError("No devices specified for context")
6767
end
6868
if properties !== nothing
69-
ctx_properties = _parse_properties(properties)
69+
ctx_properties = encode_properties(properties)
7070
else
7171
ctx_properties = C_NULL
7272
end
@@ -95,7 +95,7 @@ Context(d::Device; properties=nothing, callback=nothing) =
9595

9696
function Context(dev_type; properties = nothing, callback = nothing)
9797
if properties !== nothing
98-
ctx_properties = _parse_properties(properties)
98+
ctx_properties = encode_properties(properties)
9999
else
100100
ctx_properties = C_NULL
101101
end
@@ -178,11 +178,9 @@ function Base.getproperty(ctx::Context, s::Symbol)
178178
end
179179
end
180180

181-
#Note: properties list needs to be terminated with a NULL value!
182-
function _parse_properties(props)
183-
if isempty(props)
184-
return C_NULL
185-
end
181+
function encode_properties(props)
182+
isempty(props) && return C_NULL
183+
186184
cl_props = cl_context_properties[]
187185
for prop_tuple in props
188186
if length(prop_tuple) != 2
@@ -195,18 +193,21 @@ function _parse_properties(props)
195193
push!(cl_props, cl_context_properties(val))
196194
elseif prop == CL_WGL_HDC_KHR
197195
push!(cl_props, cl_context_properties(val))
198-
elseif Sys.isapple() ? (prop == CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) : false
196+
elseif Sys.isapple() && prop == CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
199197
push!(cl_props, cl_context_properties(val))
200198
elseif prop == CL_GL_CONTEXT_KHR ||
201199
prop == CL_EGL_DISPLAY_KHR ||
202200
prop == CL_GLX_DISPLAY_KHR ||
203201
prop == CL_CGL_SHAREGROUP_KHR
204202
push!(cl_props, cl_context_properties(val))
205203
else
206-
throw(OpenCLException("Invalid OpenCL Context property"))
204+
throw(OpenCLException("Invalid OpenCL context property '$prop'"))
207205
end
208206
end
207+
208+
# terminate with NULL
209209
push!(cl_props, cl_context_properties(C_NULL))
210+
210211
return cl_props
211212
end
212213

lib/cl/libopencl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ macro CL_MAKE_VERSION(major, minor, patch)
2626
end
2727
end
2828

29-
const intptr_t = Clong
29+
const intptr_t = Cssize_t
3030

3131
const cl_int = Int32
3232

res/opencl.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ print_using_CEnum = false
77
output_ignorelist = [
88
"CL_PARTITION_BY_NAMES_LIST_END_EXT",
99
"CL_IMPORT_MEMORY_WHOLE_ALLOCATION_ARM",
10+
"intptr_t"
1011
]
1112

1213

res/opencl_prologue.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ macro CL_MAKE_VERSION(major, minor, patch)
2222
VersionNumber($major, $minor, $patch)
2323
end
2424
end
25+
26+
const intptr_t = Cssize_t

test/context.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
if !cl.has_device_type(cl.platform(), sym_dev_type)
5959
continue
6060
end
61-
@test cl.Context(sym_dev_type, properties=properties) != nothing
62-
@test cl.Context(cl_dev_type, properties=properties) != nothing
63-
ctx = cl.Context(cl_dev_type, properties=properties)
61+
@test cl.Context(sym_dev_type; properties) != nothing
62+
@test cl.Context(cl_dev_type; properties) != nothing
63+
ctx = cl.Context(cl_dev_type; properties)
6464
@test !isempty(ctx.properties)
6565
test_properties = ctx.properties
6666

@@ -78,22 +78,10 @@
7878
@test platform_in_properties
7979
end
8080
try
81-
ctx2 = cl.Context(cl.CL_DEVICE_TYPE_ACCELERATOR,
82-
properties=properties)
81+
ctx2 = cl.Context(cl.CL_DEVICE_TYPE_ACCELERATOR; properties)
8382
catch err
8483
@test typeof(err) == cl.CLError
8584
@test err.desc == :CL_DEVICE_NOT_FOUND
8685
end
8786
end
88-
89-
@testset "parsing" begin
90-
properties = [(cl.CL_CONTEXT_PLATFORM, cl.platform())]
91-
parsed_properties = cl._parse_properties(properties)
92-
93-
@test isodd(length(parsed_properties))
94-
@test parsed_properties[end] == 0
95-
@test parsed_properties[1] == cl.cl_context_properties(cl.CL_CONTEXT_PLATFORM)
96-
@test parsed_properties[2] == cl.cl_context_properties(cl.platform().id)
97-
end
98-
9987
end

0 commit comments

Comments
 (0)