Skip to content

Commit 9247b80

Browse files
authored
Merge pull request #313 from JuliaGPU/tb/windows
Windows support
2 parents ee8036d + 9143b04 commit 9247b80

File tree

9 files changed

+49
-29
lines changed

9 files changed

+49
-29
lines changed

.github/workflows/Test.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,28 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
version: ['1.10', '1.11']
26-
os: [ubuntu-24.04, ubuntu-24.04-arm, macOS-13, macOS-15]
26+
os: [ubuntu-24.04, ubuntu-24.04-arm, macOS-13, macOS-15, windows-2025]
2727
arch: [x64, arm64]
2828
pocl: [jll, local]
2929
exclude:
3030
- os: ubuntu-24.04
3131
arch: arm64
32+
- os: windows-2025
33+
arch: arm64
3234
- os: ubuntu-24.04-arm
3335
arch: x64
3436
# macOS 13 is Intel-only, while macOS 14+ only support Apple Silicon
3537
- os: macOS-15
3638
arch: x64
3739
- os: macOS-13
3840
arch: arm64
39-
# we only tested building PoCL on Linux
41+
# we only test building PoCL on Linux
4042
- os: macOS-13
4143
pocl: local
4244
- os: macOS-15
4345
pocl: local
46+
- os: windows-2025
47+
pocl: local
4448
steps:
4549
- name: Checkout OpenCL.jl
4650
uses: actions/checkout@v4
@@ -132,9 +136,22 @@ jobs:
132136
133137
- name: Test OpenCL.jl
134138
uses: julia-actions/julia-runtest@v1
139+
if: runner.os != 'Windows'
135140
with:
136141
test_args: '--platform=pocl'
137142

143+
- name: Setup BusyBox
144+
if: runner.os == 'Windows'
145+
run: |
146+
Invoke-WebRequest https://frippery.org/files/busybox/busybox64.exe -OutFile C:\Windows\drop.exe
147+
- name: Test OpenCL.jl (de-escalated)
148+
if: runner.os == 'Windows'
149+
shell: drop -c "julia '{0}'"
150+
run: |
151+
using Pkg
152+
Pkg.activate(".")
153+
Pkg.test(; test_args=`--platform=pocl`)
154+
138155
- uses: julia-actions/julia-processcoverage@v1
139156
- uses: codecov/codecov-action@v5
140157
with:

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

src/compiler/compilation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ end
5353
end
5454

5555
# compile to executable machine code
56+
const compilations = Threads.Atomic{Int}(0)
5657
function compile(@nospecialize(job::CompilerJob))
5758
# TODO: this creates a context; cache those.
5859
obj, meta = JuliaContext() do ctx
5960
GPUCompiler.compile(:obj, job)
6061
end
62+
compilations[] += 1
6163

6264
(obj, entry=LLVM.name(meta.entry))
6365
end

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

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ try
280280
p = recycle_worker(p)
281281
else
282282
print_testworker_stats(test, wrkr, resp)
283+
284+
compilations = resp[7]
285+
if Sys.iswindows() && compilations > 100
286+
# XXX: restart to avoid handle exhaustion
287+
# (see pocl/pocl#1941)
288+
@warn "Restarting worker $wrkr to avoid handle exhaustion"
289+
p = recycle_worker(p)
290+
end
283291
end
284292
end
285293

test/setup.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function runtests(f, name, platform_filter)
114114

115115
# process results
116116
cpu_rss = Sys.maxrss()
117+
compilations = OpenCL.compilations[]
117118
if VERSION >= v"1.11.0-DEV.1529"
118119
tc = Test.get_test_counts(data[1])
119120
passes,fails,error,broken,c_passes,c_fails,c_errors,c_broken =
@@ -130,7 +131,7 @@ function runtests(f, name, platform_filter)
130131
data[4],
131132
data[5])
132133
end
133-
res = vcat(collect(data), cpu_rss)
134+
res = vcat(collect(data), cpu_rss, compilations)
134135

135136
GC.gc(true)
136137
res

0 commit comments

Comments
 (0)