Skip to content

Commit

Permalink
Merge pull request #169 from JuliaGPU/sd-1.0
Browse files Browse the repository at this point in the history
Sd 1.0
  • Loading branch information
SimonDanisch authored Oct 18, 2018
2 parents c535f37 + 6f26d02 commit fa0268f
Show file tree
Hide file tree
Showing 36 changed files with 411 additions and 402 deletions.
32 changes: 14 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
language: julia
sudo: false

os:
#- linux
- osx

julia:
- 0.6
- 1.0
- nightly
matrix:
allow_failures:
- julia: nightly

notifications:
email: false

# before_install:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - if [ $TRAVIS_OS_NAME = "linux" ]; then
Expand All @@ -29,19 +25,19 @@ notifications:
# chmod +x ${AMDAPPSDK}/bin/x86_64/clinfo;
# ${AMDAPPSDK}/bin/x86_64/clinfo;
# fi;
script:
- julia -e 'Pkg.init(); Pkg.clone(pwd())'
- julia -e 'using OpenCL'
#script:
#- julia -e 'Pkg.init(); Pkg.clone(pwd())'
#- julia -e 'using OpenCL'

- julia --color=yes --depwarn=error -e "Pkg.test(\"OpenCL\")"
#- julia --color=yes --depwarn=error -e "Pkg.test(\"OpenCL\")"

- julia examples/demo.jl
- julia examples/performance.jl
- julia examples/hands_on_opencl/ex04/vadd_chain.jl
- julia examples/hands_on_opencl/ex05/vadd_abc.jl
- julia examples/hands_on_opencl/ex06/matmul.jl
- julia examples/hands_on_opencl/ex07/matmul.jl
- julia examples/hands_on_opencl/ex08/matmul.jl
#- julia examples/demo.jl
#- julia examples/performance.jl
#- julia examples/hands_on_opencl/ex04/vadd_chain.jl
#- julia examples/hands_on_opencl/ex05/vadd_abc.jl
#- julia examples/hands_on_opencl/ex06/matmul.jl
#- julia examples/hands_on_opencl/ex07/matmul.jl
#- julia examples/hands_on_opencl/ex08/matmul.jl

# - if [ $TRAVIS_OS_NAME = "linux" ]; then
# julia examples/hands_on_opencl/ex09/pi_ocl.jl;
Expand All @@ -55,6 +51,6 @@ script:
# - if [ $TRAVIS_OS_NAME = "linux" ]; then
# julia examples/hands_on_opencl/exA/pi_vocl.jl 8;
# fi;

after_success:
- julia -e 'Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; fi
- julia -e 'using Pkg; Pkg.add("Coverage")'
- julia -e 'using Coverage; Coveralls.submit(process_folder())'
5 changes: 5 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name = "OpenCL"
uuid = "08131aa3-fb12-5dee-8b74-c09406e224a2"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 1.0
2 changes: 1 addition & 1 deletion examples/hands_on_opencl/ex07/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ prg = cl.Program(ctx, source=kernel_source) |> cl.build!
mmul = cl.Kernel(prg, "mmul")
wk_size = cl.info(first(cl.devices(ctx)), :max_work_group_size)
if Ndim * (ORDER ÷ 16) >= wk_size
warn("Specified work_size is bigger than $wk_size")
@warn("Specified work_size is bigger than $wk_size")
else

info("=== OpenCL, matrix mult, C row, A row in priv mem, order $Ndim ====")
Expand Down
4 changes: 2 additions & 2 deletions examples/hands_on_opencl/ex08/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ prg = cl.Program(ctx, source=kernel_source) |> cl.build!
mmul = cl.Kernel(prg, "mmul")
wk_size = cl.info(first(cl.devices(ctx)), :max_work_group_size)
if Ndim * (ORDER ÷ 16) >= wk_size
warn("Specified work_size is bigger than $wk_size")
@warn("Specified work_size is bigger than $wk_size")
else

info("=== OpenCL, matrix mult, C row, priv A, B, cols loc, order $Ndim ====")
Expand Down Expand Up @@ -176,7 +176,7 @@ prg = cl.Program(ctx, source=kernel_source) |> cl.build!
mmul = cl.Kernel(prg, "mmul")
wk_size = cl.info(first(cl.devices(ctx)), :max_work_group_size)
if Ndim * (ORDER ÷ 16) >= wk_size
warn("Specified work_size is bigger than $wk_size")
@warn("Specified work_size is bigger than $wk_size")
else

info("=== OpenCL, matrix mult, A and B in block form in local memory, order $Ndim ====")
Expand Down
2 changes: 1 addition & 1 deletion examples/hands_on_opencl/exA/pi_vocl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ elseif vector_size == 8
ITERS = 32768 # (262144/8)
WGS = 64
else
warn("Invalid vector size")
@warn("Invalid vector size")
exit(1)
end

Expand Down
10 changes: 5 additions & 5 deletions examples/performance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function cl_performance(ndatapts::Integer, nworkers::Integer)
for platform in cl.platforms()

if platform[:name] == "Portable Computing Language"
warn("Portable Computing Language platform not yet supported")
@warn("Portable Computing Language platform not yet supported")
continue
end

Expand All @@ -65,14 +65,14 @@ function cl_performance(ndatapts::Integer, nworkers::Integer)
@printf("Device max work item size: %s\n", device[:max_work_item_size])

if device[:max_mem_alloc_size] < sizeof(Float32) * ndatapts
warn("Requested buffer size exceeds device max alloc size!")
warn("Skipping device $(device[:name])...")
@warn("Requested buffer size exceeds device max alloc size!")
@warn("Skipping device $(device[:name])...")
continue
end

if device[:max_work_group_size] < nworkers
warn("Number of workers exceeds the device's max work group size!")
warn("Skipping device $(device[:name])...")
@warn("Number of workers exceeds the device's max work group size!")
@warn("Skipping device $(device[:name])...")
continue
end

Expand Down
1 change: 0 additions & 1 deletion src/OpenCL.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__precompile__(true)
module OpenCL

export cl
Expand Down
15 changes: 8 additions & 7 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ module api

include("types.jl")

const paths = is_apple() ? String["/System/Library/Frameworks/OpenCL.framework"] : String[]
const paths = Sys.isapple() ? String["/System/Library/Frameworks/OpenCL.framework"] : String[]

import Libdl

const libopencl = Libdl.find_library(["libOpenCL", "OpenCL"], paths)
@assert libopencl != ""

function _ocl_func(func, ret_type, arg_types)
local args_in = Symbol[Symbol("arg$i::$T")
local args_in = Symbol[Symbol("arg$i")
for (i, T) in enumerate(arg_types.args)]

esc(quote
function $func($(args_in...))
ccall(($(string(func)), libopencl),
Expand All @@ -24,17 +27,15 @@ macro ocl_func(func, ret_type, arg_types)
_ocl_func(func, ret_type, arg_types)
end

const CL_callback = Ptr{Void}
const CL_callback = Ptr{Nothing}

abstract type CL_user_data_tag end
const CL_user_data = Ptr{CL_user_data_tag}

Base.cconvert(::Type{Ptr{CL_user_data_tag}}, obj::T) where {T} = Ref{T}(obj)
Base.unsafe_convert(::Type{Ptr{CL_user_data_tag}}, ref::Ref{T}) where {T} =
Ptr{CL_user_data_tag}(isbits(T) ? pointer_from_objref(ref) : pointer_from_objref(ref[]))

Base.cconvert(::Type{Ptr{CL_user_data_tag}}, ptr::Ptr) = ptr
Base.unsafe_convert(::Type{Ptr{CL_user_data_tag}}, ptr::Ptr) = Ptr{CL_user_data_tag}(ptr)
Base.unsafe_convert(P::Type{Ptr{CL_user_data_tag}}, ptr::Ref) = P(Base.unsafe_convert(Ptr{Cvoid}, ptr))
Base.unsafe_convert(P::Type{Ptr{CL_user_data_tag}}, ptr::Ptr) = P(Base.unsafe_convert(Ptr{Cvoid}, ptr))

include("api/opencl_1.0.0.jl")
include("api/opencl_1.1.0.jl")
Expand Down
54 changes: 27 additions & 27 deletions src/api/opencl_1.0.0.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
(CL_uint, Ptr{CL_platform_id}, Ptr{CL_uint}))

@ocl_func(clGetPlatformInfo,
CL_int, (CL_platform_id, CL_platform_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
CL_int, (CL_platform_id, CL_platform_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== device apis ===#
@ocl_func(clGetDeviceIDs, CL_int,
(CL_platform_id, CL_device_type, CL_uint, Ptr{CL_device_id}, Ptr{CL_uint}))

@ocl_func(clGetDeviceInfo, CL_int,
(CL_device_id, CL_device_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_device_id, CL_device_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== context apis ===#
#TODO: pass user data as Any type
@ocl_func(clCreateContext, CL_context,
(Ptr{CL_context_properties}, CL_uint, Ptr{CL_device_id}, CL_callback, CL_user_data, Ptr{CL_int}))
(Ptr{CL_context_properties}, CL_uint, Ptr{CL_device_id}, CL_callback, CL_callback, Ptr{CL_int}))

@ocl_func(clCreateContextFromType, CL_context,
(Ptr{CL_context_properties}, CL_device_type, CL_callback, CL_user_data, Ptr{CL_int}))
(Ptr{CL_context_properties}, CL_device_type, CL_callback, CL_callback, Ptr{CL_int}))

@ocl_func(clRetainContext, CL_int, (CL_context,))

@ocl_func(clReleaseContext, CL_int, (CL_context,))

@ocl_func(clGetContextInfo, CL_int,
(CL_context, CL_context_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_context, CL_context_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== command queue apis ===#
@ocl_func(clCreateCommandQueue, CL_command_queue,
Expand All @@ -36,11 +36,11 @@
@ocl_func(clReleaseCommandQueue, CL_int, (CL_command_queue,))

@ocl_func(clGetCommandQueueInfo, CL_int,
(CL_command_queue, CL_command_queue_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_command_queue, CL_command_queue_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== memory object apis ===#
@ocl_func(clCreateBuffer, CL_mem,
(CL_context, CL_mem_flags, Csize_t, Ptr{Void}, Ptr{CL_int}))
(CL_context, CL_mem_flags, Csize_t, Ptr{Nothing}, Ptr{CL_int}))

@ocl_func(clRetainMemObject, CL_int, (CL_mem,))

Expand All @@ -50,10 +50,10 @@
(CL_context, CL_mem_flags, CL_mem_object_type, CL_uint, Ptr{CL_image_format}, Ptr{CL_uint}))

@ocl_func(clGetMemObjectInfo, CL_mem,
(CL_mem, CL_mem_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_mem, CL_mem_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

@ocl_func(clGetImageInfo, CL_mem,
(CL_mem, CL_image_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_mem, CL_image_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== sampler apis ===#
@ocl_func(clCreateSampler, CL_sampler,
Expand All @@ -64,7 +64,7 @@
@ocl_func(clReleaseSampler, CL_int, (CL_sampler,))

@ocl_func(clGetSamplerInfo, CL_int,
(CL_sampler, CL_sampler_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_sampler, CL_sampler_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== program object apis ===#
@ocl_func(clCreateProgramWithSource, CL_program,
Expand All @@ -79,10 +79,10 @@
@ocl_func(clReleaseProgram, CL_int, (CL_program,))

@ocl_func(clBuildProgram, CL_int,
(CL_program, CL_uint, Ptr{CL_device_id}, Ptr{Cchar}, CL_callback, Ptr{Void}))
(CL_program, CL_uint, Ptr{CL_device_id}, Ptr{Cchar}, CL_callback, Ptr{Nothing}))

@ocl_func(clGetProgramBuildInfo, CL_int,
(CL_program, CL_device_id, CL_program_build_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_program, CL_device_id, CL_program_build_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== kernel object apis ===#
@ocl_func(clCreateKernel, CL_kernel,
Expand All @@ -96,28 +96,28 @@
@ocl_func(clReleaseKernel, CL_int, (CL_kernel,))

@ocl_func(clSetKernelArg, CL_int,
(CL_kernel, CL_uint, Csize_t, Ptr{Void}))
(CL_kernel, CL_uint, Csize_t, Ptr{Nothing}))

@ocl_func(clGetKernelInfo, CL_int,
(CL_kernel, CL_kernel_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_kernel, CL_kernel_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

@ocl_func(clGetKernelWorkGroupInfo, CL_int,
(CL_kernel, CL_device_id, CL_kernel_work_group_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_kernel, CL_device_id, CL_kernel_work_group_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== event object apis ===#
@ocl_func(clWaitForEvents, CL_int,
(CL_uint, Ptr{CL_event_info}))

@ocl_func(clGetEventInfo, CL_int,
(CL_event, CL_event_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_event, CL_event_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

@ocl_func(clRetainEvent, CL_int, (CL_event,))

@ocl_func(clReleaseEvent, CL_int, (CL_event,))

#=== profiling apis ===#
@ocl_func(clGetEventProfilingInfo, CL_int,
(CL_event, CL_profiling_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_event, CL_profiling_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))

#=== flush and finish apis ===#
@ocl_func(clFlush, CL_int, (CL_command_queue,))
Expand All @@ -126,12 +126,12 @@

#=== enqueued commands apis ===#
@ocl_func(clEnqueueReadBuffer, CL_int,
(CL_command_queue, CL_mem, CL_bool, Csize_t, Csize_t, Ptr{Void},
(CL_command_queue, CL_mem, CL_bool, Csize_t, Csize_t, Ptr{Nothing},
CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueWriteBuffer, CL_int,
(CL_command_queue, CL_mem, CL_bool,
Csize_t, Csize_t, Ptr{Void}, CL_uint,
Csize_t, Csize_t, Ptr{Nothing}, CL_uint,
Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueCopyBuffer, CL_int,
Expand All @@ -141,11 +141,11 @@
@ocl_func(clEnqueueReadImage, CL_int,
(CL_command_queue, CL_mem, CL_bool,
Ptr{Csize_t}, Ptr{Csize_t}, Csize_t, Csize_t,
Ptr{Void}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))
Ptr{Nothing}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueWriteImage, CL_int,
(CL_command_queue, CL_mem, CL_bool, Ptr{Csize_t}, Ptr{Csize_t},
Csize_t, Csize_t, Ptr{Void}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))
Csize_t, Csize_t, Ptr{Nothing}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueCopyImage, CL_int,
(CL_command_queue, CL_mem, CL_mem, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t},
Expand All @@ -159,17 +159,17 @@
(CL_command_queue, CL_mem, CL_mem, Csize_t, Ptr{Csize_t}, Ptr{Csize_t},
CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueMapBuffer, Ptr{Void},
@ocl_func(clEnqueueMapBuffer, Ptr{Nothing},
(CL_command_queue, CL_mem, CL_bool, CL_map_flags, Csize_t, Csize_t,
CL_uint, Ptr{CL_event}, Ptr{CL_event}, Ptr{CL_int}))

@ocl_func(clEnqueueMapImage, Ptr{Void},
@ocl_func(clEnqueueMapImage, Ptr{Nothing},
(CL_command_queue, CL_mem, CL_bool, CL_map_flags,
Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t}, Ptr{Csize_t},
CL_uint, Ptr{CL_event}, Ptr{CL_event}, Ptr{CL_int}))

@ocl_func(clEnqueueUnmapMemObject, CL_int,
(CL_command_queue, CL_mem, Ptr{Void}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))
(CL_command_queue, CL_mem, Ptr{Nothing}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueNDRangeKernel, CL_int,
(CL_command_queue, CL_kernel, CL_uint,
Expand All @@ -180,8 +180,8 @@
(CL_command_queue, CL_kernel, CL_uint, Ptr{CL_event}, Ptr{CL_event}))

@ocl_func(clEnqueueNativeKernel, CL_int,
(CL_command_queue, Ptr{Void}, Csize_t, CL_uint,
Ptr{CL_mem}, Ptr{Ptr{Void}}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))
(CL_command_queue, Ptr{Nothing}, Csize_t, CL_uint,
Ptr{CL_mem}, Ptr{Ptr{Nothing}}, CL_uint, Ptr{CL_event}, Ptr{CL_event}))

#== opengl interop functions ==#

Expand All @@ -207,4 +207,4 @@
(CL_mem, Ptr{CL_GL_object_type}, Ptr{GL_uint}))

@ocl_func(clGetGLTextureInfo, CL_int,
(CL_mem, CL_GL_texture_info, Csize_t, Ptr{Void}, Ptr{Csize_t}))
(CL_mem, CL_GL_texture_info, Csize_t, Ptr{Nothing}, Ptr{Csize_t}))
Loading

0 comments on commit fa0268f

Please sign in to comment.