Skip to content

Commit

Permalink
Re-enable most tests on POCL.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Jul 31, 2024
1 parent 86607db commit f15192e
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 346 deletions.
106 changes: 47 additions & 59 deletions test/behaviour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,33 @@ info(
Running Behavior Tests
======================================================================")
=#
if device[:platform][:name] == "Portable Computing Language"
@warn("Skipping OpenCL.Kernel mem/workgroup size for Portable Computing Language Platform")
else
@testset "Hello World Test" begin
hello_world_kernel = "
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
@testset "Hello World Test" begin
hello_world_kernel = "
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__constant char hw[] = \"hello world\";
__constant char hw[] = \"hello world\";
__kernel void hello(__global char *out) {
int tid = get_global_id(0);
out[tid] = hw[tid];
}"
__kernel void hello(__global char *out) {
int tid = get_global_id(0);
out[tid] = hw[tid];
}"

hello_world_str = "hello world"
hello_world_str = "hello world"


ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)
ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)

str_len = length(hello_world_str) + 1
out_buf = cl.Buffer(Cchar, ctx, sizeof(Cchar) * str_len, :w)
str_len = length(hello_world_str) + 1
out_buf = cl.Buffer(Cchar, ctx, sizeof(Cchar) * str_len, :w)

prg = cl.Program(ctx, source=hello_world_kernel) |> cl.build!
kern = cl.Kernel(prg, "hello")
prg = cl.Program(ctx, source=hello_world_kernel) |> cl.build!
kern = cl.Kernel(prg, "hello")

queue(kern, str_len, nothing, out_buf)
h = cl.read(queue, out_buf)
queue(kern, str_len, nothing, out_buf)
h = cl.read(queue, out_buf)

@test cl.CLString(h) == hello_world_str
end
@test cl.CLString(h) == hello_world_str
end

@testset "Low Level API Test" begin
Expand Down Expand Up @@ -208,35 +204,31 @@ let test_struct = "
}
"

if device[:platform][:name] == "Portable Computing Language"
@warn("Skipping OpenCL Struct Buffer Test for Portable Computing Language Platform")
else
@testset "Struct Buffer Test" begin
ctx = cl.Context(device)
q = cl.CmdQueue(ctx)
p = cl.Program(ctx, source=test_struct) |> cl.build!
@testset "Struct Buffer Test" begin
ctx = cl.Context(device)
q = cl.CmdQueue(ctx)
p = cl.Program(ctx, source=test_struct) |> cl.build!

part3 = cl.Kernel(p, "part3")
part3 = cl.Kernel(p, "part3")

X = fill(1f0, 10)
Y = fill(1f0, 10)
X = fill(1f0, 10)
Y = fill(1f0, 10)

P = [Params(0.5, 10.0, [0.0, 0.0], 3)]
P = [Params(0.5, 10.0, [0.0, 0.0], 3)]

#TODO: constructor for single immutable types.., check if passed parameter isbits
P_buf = cl.Buffer(Params, ctx, length(P), :r)
cl.write!(q, P_buf, P)
#TODO: constructor for single immutable types.., check if passed parameter isbits
P_buf = cl.Buffer(Params, ctx, length(P), :r)
cl.write!(q, P_buf, P)

X_buf = cl.Buffer(Float32, ctx, length(X), (:r, :copy), hostbuf=X)
Y_buf = cl.Buffer(Float32, ctx, length(Y), (:r, :copy), hostbuf=Y)
R_buf = cl.Buffer(Float32, ctx, length(X), :w)
X_buf = cl.Buffer(Float32, ctx, length(X), (:r, :copy), hostbuf=X)
Y_buf = cl.Buffer(Float32, ctx, length(Y), (:r, :copy), hostbuf=Y)
R_buf = cl.Buffer(Float32, ctx, length(X), :w)

global_size = size(X)
q(part3, global_size, nothing, X_buf, Y_buf, R_buf, P_buf)
global_size = size(X)
q(part3, global_size, nothing, X_buf, Y_buf, R_buf, P_buf)

r = cl.read(q, R_buf)
@test all(x -> x == 13.5, r)
end
r = cl.read(q, R_buf)
@test all(x -> x == 13.5, r)
end

end
Expand Down Expand Up @@ -265,25 +257,21 @@ let test_mutable_pointerfree = "
"


if device[:platform][:name] == "Portable Computing Language"
@warn("Skipping OpenCL Struct Buffer Test for Portable Computing Language Platform")
else
@testset "Struct Buffer Test" begin
ctx = cl.Context(device)
q = cl.CmdQueue(ctx)
p = cl.Program(ctx, source=test_mutable_pointerfree) |> cl.build!
@testset "Struct Buffer Test" begin
ctx = cl.Context(device)
q = cl.CmdQueue(ctx)
p = cl.Program(ctx, source=test_mutable_pointerfree) |> cl.build!

part3 = cl.Kernel(p, "part3")
part3 = cl.Kernel(p, "part3")

P = MutableParams(0.5, 10.0)
P_buf = cl.Buffer(Float32, ctx, 2, :w)
q(part3, 1, nothing, P_buf, P)
P = MutableParams(0.5, 10.0)
P_buf = cl.Buffer(Float32, ctx, 2, :w)
q(part3, 1, nothing, P_buf, P)

r = cl.read(q, P_buf)
r = cl.read(q, P_buf)

@test r[1] == 0.5
@test r[2] == 10.0
end
@test r[1] == 0.5
@test r[2] == 10.0
end

end
30 changes: 12 additions & 18 deletions test/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,18 @@ end
@test_throws TypeError cl.Buffer(Float32, ctx, 1, :use, hostbuf=C_NULL)
end

if device[:platform][:name] == "Portable Computing Language"
# the pocl platform claims to implement v1.2 of the spec, but does not
@warn("Skipping OpenCL.Kernel constructor for " *
"Portable Computing Language Platform")
else
@testset "fill" begin
ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)
testarray = zeros(Float32, 1000)
buf = cl.Buffer(Float32, ctx, length(testarray), (:rw, :copy), hostbuf=testarray)
@test length(buf) == length(testarray)

cl.fill!(queue, buf, 1f0)
readback = cl.read(queue, buf)
@test all(x -> x == 1.0, readback)
@test all(x -> x == 0.0, testarray)
@test buf.valid == true
end
@testset "fill" begin
ctx = cl.Context(device)
queue = cl.CmdQueue(ctx)
testarray = zeros(Float32, 1000)
buf = cl.Buffer(Float32, ctx, length(testarray), (:rw, :copy), hostbuf=testarray)
@test length(buf) == length(testarray)

cl.fill!(queue, buf, 1f0)
readback = cl.read(queue, buf)
@test all(x -> x == 1.0, readback)
@test all(x -> x == 0.0, testarray)
@test buf.valid == true
end

@testset "write!" begin
Expand Down
5 changes: 0 additions & 5 deletions test/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ end
end


if platform[:name] == "Portable Computing Language"
@warn("Skipping OpenCL.Context platform properties for " *
"Portable Computing Language Platform")
else
@testset "platform properties" begin
try
cl.Context(cl.CL_DEVICE_TYPE_CPU)
Expand Down Expand Up @@ -95,7 +91,6 @@ end
@test err.desc == :CL_DEVICE_NOT_FOUND
end
end
end

@testset "create_some_context" begin
@test cl.create_some_context() != nothing
Expand Down
108 changes: 52 additions & 56 deletions test/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,60 @@
end
end

if occursin("Portable", platform[:name])
@warn("Skipping Device Info tests for Portable Computing Language Platform")
else
@testset "Info" begin
device_info_keys = Symbol[
:driver_version,
:version,
:extensions,
:platform,
:name,
:device_type,
:has_image_support,
:queue_properties,
:has_queue_out_of_order_exec,
:has_queue_profiling,
:has_native_kernel,
:vendor_id,
:max_compute_units,
:max_work_item_size,
:max_clock_frequency,
:address_bits,
:max_read_image_args,
:max_write_image_args,
:global_mem_size,
:max_mem_alloc_size,
:max_const_buffer_size,
:local_mem_size,
:has_local_mem,
:host_unified_memory,
:available,
:compiler_available,
:max_work_group_size,
:max_parameter_size,
:profiling_timer_resolution,
:max_image2d_shape,
:max_image3d_shape,
]
@test isa(platform, cl.Platform)
@test_throws ArgumentError platform[:zjdlkf]
@testset "Info" begin
device_info_keys = Symbol[
:driver_version,
:version,
:extensions,
:platform,
:name,
:device_type,
:has_image_support,
:queue_properties,
:has_queue_out_of_order_exec,
:has_queue_profiling,
:has_native_kernel,
:vendor_id,
:max_compute_units,
:max_work_item_size,
:max_clock_frequency,
:address_bits,
:max_read_image_args,
:max_write_image_args,
:global_mem_size,
:max_mem_alloc_size,
:max_const_buffer_size,
:local_mem_size,
:has_local_mem,
:host_unified_memory,
:available,
:compiler_available,
:max_work_group_size,
:max_parameter_size,
:profiling_timer_resolution,
:max_image2d_shape,
:max_image3d_shape,
]
@test isa(platform, cl.Platform)
@test_throws ArgumentError platform[:zjdlkf]

@test isa(device, cl.Device)
@test_throws ArgumentError device[:zjdlkf]
for k in device_info_keys
@test device[k] == cl.info(device, k)
if k == :extensions
@test isa(device[k], Array)
if length(device[k]) > 0
@test isa(device[k], Array{String, 1})
end
elseif k == :platform
@test device[k] == platform
elseif k == :max_work_item_sizes
@test length(device[k]) == 3
elseif k == :max_image2d_shape
@test length(device[k]) == 2
elseif k == :max_image3d_shape
@test length(device[k]) == 3
@test isa(device, cl.Device)
@test_throws ArgumentError device[:zjdlkf]
for k in device_info_keys
@test device[k] == cl.info(device, k)
if k == :extensions
@test isa(device[k], Array)
if length(device[k]) > 0
@test isa(device[k], Array{String, 1})
end
elseif k == :platform
@test device[k] == platform
elseif k == :max_work_item_sizes
@test length(device[k]) == 3
elseif k == :max_image2d_shape
@test length(device[k]) == 2
elseif k == :max_image3d_shape
@test length(device[k]) == 3
end
end
end
Expand Down
Loading

0 comments on commit f15192e

Please sign in to comment.