Skip to content

Commit

Permalink
follow github bot and run runic (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
VarLad committed Jan 20, 2025
1 parent 58a0f4a commit 1e5ae72
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 247 deletions.
2 changes: 1 addition & 1 deletion lib/cl/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Base.getproperty(mem::AbstractMemory, s::Symbol)
if s == :context
param = Ref{cl_context}()
clGetMemObjectInfo(mem, CL_MEM_CONTEXT, sizeof(cl_context), param, C_NULL)
return Context(param[], retain=true)
return Context(param[], retain = true)
elseif s == :mem_type
result = Ref{cl_mem_object_type}()
clGetMemObjectInfo(mem, CL_MEM_TYPE, sizeof(cl_mem_object_type), result, C_NULL)
Expand Down
42 changes: 23 additions & 19 deletions lib/cl/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,32 @@ function queue_properties(d::Device, type=:host)
result = Ref{cl_command_queue_properties}()
if type === :host
clGetDeviceInfo(d, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES,
sizeof(cl_command_queue_properties), result, C_NULL)
sizeof(cl_command_queue_properties), result, C_NULL
)
elseif type === :device
clGetDeviceInfo(d, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES,
sizeof(cl_command_queue_properties), result, C_NULL)
sizeof(cl_command_queue_properties), result, C_NULL
)
else
throw(ArgumentError("Unknown queue type: $type"))
end
mask = result[]

return (;
out_of_order_exec=mask & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE != 0,
profiling=mask & CL_QUEUE_PROFILING_ENABLE != 0
out_of_order_exec = mask & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE != 0,
profiling = mask & CL_QUEUE_PROFILING_ENABLE != 0,
)
end

function exec_capabilities(d::Device)
result = Ref{cl_device_exec_capabilities}()
clGetDeviceInfo(d, CL_DEVICE_EXECUTION_CAPABILITIES,
sizeof(cl_device_exec_capabilities), result, C_NULL)
sizeof(cl_device_exec_capabilities), result, C_NULL
)
mask = result[]

return (;
native_kernel=mask & CL_EXEC_NATIVE_KERNEL != 0,
native_kernel = mask & CL_EXEC_NATIVE_KERNEL != 0,
)
end

Expand Down Expand Up @@ -226,19 +229,19 @@ function usm_capabilities(d::Device)

function retmask(m)
return (;
usm_access=m & CL_UNIFIED_SHARED_MEMORY_ACCESS_INTEL != 0,
usm_atomic_access=m & CL_UNIFIED_SHARED_MEMORY_ATOMIC_ACCESS_INTEL != 0,
usm_concurrent_access=m & CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ACCESS_INTEL != 0,
usm_concurrent_atomic_acces=m & CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ATOMIC_ACCESS_INTEL != 0,
usm_access = m & CL_UNIFIED_SHARED_MEMORY_ACCESS_INTEL != 0,
usm_atomic_access = m & CL_UNIFIED_SHARED_MEMORY_ATOMIC_ACCESS_INTEL != 0,
usm_concurrent_access = m & CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ACCESS_INTEL != 0,
usm_concurrent_atomic_acces = m & CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ATOMIC_ACCESS_INTEL != 0,
)
end

(;
usm_host_capabilities=retmask(mask[1]),
usm_device_capabilities=retmask(mask[2]),
usm_single_device_capabilities=retmask(mask[3]),
usm_shared_capabilities=retmask(mask[4]),
usm_cross_device_capabilities=retmask(mask[5]),
usm_host_capabilities = retmask(mask[1]),
usm_device_capabilities = retmask(mask[2]),
usm_single_device_capabilities = retmask(mask[3]),
usm_shared_capabilities = retmask(mask[4]),
usm_cross_device_capabilities = retmask(mask[5]),
)
catch e
nothing
Expand All @@ -258,13 +261,14 @@ end
function svm_capabilities(d::Device)
result = Ref{cl_device_svm_capabilities}()
clGetDeviceInfo(d, CL_DEVICE_SVM_CAPABILITIES,
sizeof(cl_device_svm_capabilities), result, C_NULL)
sizeof(cl_device_svm_capabilities), result, C_NULL
)
mask = result[]

return (;
coarse_grain_buffer=mask & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER != 0,
fine_grain_buffer=mask & CL_DEVICE_SVM_FINE_GRAIN_BUFFER != 0,
fine_grain_system=mask & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM != 0,
coarse_grain_buffer = mask & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER != 0,
fine_grain_buffer = mask & CL_DEVICE_SVM_FINE_GRAIN_BUFFER != 0,
fine_grain_system = mask & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM != 0,
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/cl/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ end

# Abstract Buffers
## when passing using `cl.call`
function set_arg!(k::Kernel, idx::Integer, backend::Type{<:CLBackend}, arg::T) where T <: AbstractBuffer
function set_arg!(k::Kernel, idx::Integer, backend::Type{<:CLBackend}, arg::T) where {T <: AbstractBuffer}
set_kernel_arg_abstract_pointer(backend)(k, cl_uint(idx - 1), arg.ptr)
return k
end

## when passing with `clcall`, which has pre-converted the buffer
function set_arg!(k::Kernel, idx::Integer, backend::Type{<:CLBackend}, arg::CLPtr{T}) where T
function set_arg!(k::Kernel, idx::Integer, backend::Type{<:CLBackend}, arg::CLPtr{T}) where {T}
arg = reinterpret(Ptr{Cvoid}, arg)
if arg != C_NULL
# XXX: this assumes that the receiving argument is pointer-typed, which is not the
# case with Julia's `Ptr` ABI. Instead, one should reinterpret the pointer as a
# `Core.LLVMPtr`, which _is_ pointer-valued. We retain this handling for `Ptr`
# for users passing pointers to OpenCL C, and because `Ptr` is pointer-valued
# starting with Julia 1.12.
set_kernel_arg_abstract_pointer(backend)(k, cl_uint(idx-1), arg)
set_kernel_arg_abstract_pointer(backend)(k, cl_uint(idx - 1), arg)
end
return k
end
Expand Down
10 changes: 5 additions & 5 deletions lib/cl/memory/backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ end
end

function get_backend_from_buffer(x::Type{<:AbstractBuffer})
if x == SVMBuffer
return if x == SVMBuffer
SVMBackend
else
USMBackend
end
end

function abstract_kernel_exec_info_ptrs(backend::Type{<:CLBackend})
if backend == SVMBackend
return if backend == SVMBackend
CL_KERNEL_EXEC_INFO_SVM_PTRS
else
CL_KERNEL_EXEC_INFO_USM_PTRS_INTEL
end
end

function set_kernel_arg_abstract_pointer(backend::Type{<:CLBackend})
if backend == SVMBackend
return if backend == SVMBackend
ext_clSetKernelArgSVMPointer
else
ext_clSetKernelArgMemPointerINTEL
end
end
end

function set_kernel_arg_abstract_pointer(backend::Type{<:AbstractBuffer})
if backend == SVMBuffer
return if backend == SVMBuffer
ext_clSetKernelArgSVMPointer
else
ext_clSetKernelArgMemPointerINTEL
Expand Down
22 changes: 12 additions & 10 deletions lib/cl/memory/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export device_alloc, host_alloc, shared_alloc, svm_alloc, free

abstract type AbstractBuffer end

Base.convert(T::Type{<:Union{Ptr,CLPtr}}, buf::AbstractBuffer) =
Base.convert(T::Type{<:Union{Ptr, CLPtr}}, buf::AbstractBuffer) =
throw(ArgumentError("Illegal conversion of a $(typeof(buf)) to a $T"))

# ccall integration
#
# taking the pointer of a buffer means returning the underlying pointer,
# and not the pointer of the buffer object itself.
Base.unsafe_convert(P::Type{<:Union{Ptr,CLPtr}}, buf::AbstractBuffer) = convert(P, buf)
Base.unsafe_convert(P::Type{<:Union{Ptr, CLPtr}}, buf::AbstractBuffer) = convert(P, buf)

include("usm_buffer.jl")
include("svm_buffer.jl")
Expand All @@ -25,12 +25,12 @@ include("backend.jl")

# free function for different buffers

function free(buf::AbstractBuffer; blocking=false)
function free(buf::AbstractBuffer; blocking = false)
ctx = context(buf)
ptr = Ptr{Nothing}(UInt(buf.ptr))
return if typeof(buf) == SVMBuffer
ext_clSVMFree(ctx, ptr);
if blocking
ext_clSVMFree(ctx, ptr)
if blocking
finish(queue())
end
nothing
Expand All @@ -50,17 +50,19 @@ end

# generic memory operations for different buffers

function enqueue_abstract_memcpy(dst::Union{Ptr, CLPtr}, src::Union{Ptr, CLPtr}, nbytes::Integer; queu::CmdQueue=queue(), blocking::Bool=false,
wait_for::Vector{Event}=Event[], backend = select_backend())
if backend == USMBackend
function enqueue_abstract_memcpy(
dst::Union{Ptr, CLPtr}, src::Union{Ptr, CLPtr}, nbytes::Integer; queu::CmdQueue = queue(), blocking::Bool = false,
wait_for::Vector{Event} = Event[], backend = select_backend()
)
return if backend == USMBackend
enqueue_usm_memcpy(dst, src, nbytes; queu = queu, blocking = blocking, wait_for = wait_for)
elseif backend == SVMBackend
enqueue_svm_memcpy(dst, src, nbytes; queu = queu, blocking = blocking, wait_for = wait_for)
end
end

function enqueue_abstract_fill(ptr::Union{Ptr, CLPtr}, pattern::Union{Ptr, CLPtr}, pattern_size::Integer, nbytes::Integer; queu::CmdQueue=queue(), wait_for::Vector{Event}=Event[], backend = select_backend())
if backend == USMBackend
function enqueue_abstract_fill(ptr::Union{Ptr, CLPtr}, pattern::Union{Ptr, CLPtr}, pattern_size::Integer, nbytes::Integer; queu::CmdQueue = queue(), wait_for::Vector{Event} = Event[], backend = select_backend())
return if backend == USMBackend
enqueue_usm_memfill(ptr, pattern, pattern_size, nbytes; queu = queu, wait_for = wait_for)
elseif backend == SVMBackend
enqueue_svm_fill(ptr, pattern, pattern_size, nbytes; queu = queu, wait_for = wait_for)
Expand Down
38 changes: 23 additions & 15 deletions lib/cl/memory/svm_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ struct SVMBuffer <: AbstractBuffer
end

function svm_alloc(
ctx::Context, bytesize::Integer;
alignment::Integer=0, access::Symbol=:rw, fine_grained=false
)
ctx::Context, bytesize::Integer;
alignment::Integer = 0, access::Symbol = :rw, fine_grained = false
)
flags = if access == :rw
CL_MEM_READ_WRITE
elseif access == :r
Expand Down Expand Up @@ -55,20 +55,24 @@ Base.convert(::Type{CLPtr{T}}, buf::SVMBuffer) where {T} =
# fine-grained buffers can just be used directly.

# copy from and to SVM buffers
function enqueue_svm_memcpy(dst::Union{Ptr, CLPtr}, src::Union{Ptr, CLPtr}, nbytes::Integer; queu::CmdQueue=queue(), blocking::Bool=false,
wait_for::Vector{Event}=Event[])
function enqueue_svm_memcpy(
dst::Union{Ptr, CLPtr}, src::Union{Ptr, CLPtr}, nbytes::Integer; queu::CmdQueue = queue(), blocking::Bool = false,
wait_for::Vector{Event} = Event[]
)
n_evts = length(wait_for)
evt_ids = isempty(wait_for) ? C_NULL : [pointer(evt) for evt in wait_for]
GC.@preserve wait_for begin
return GC.@preserve wait_for begin
ret_evt = Ref{cl_event}()
ext_clEnqueueSVMMemcpy(queu, blocking, dst, src, nbytes, n_evts, evt_ids, ret_evt)
@return_event ret_evt[]
end
end

# map an SVM buffer into the host address space, returning an event
function enqueue_svm_map(ptr::Union{Ptr, CLPtr}, nbytes::Integer, flags=:rw; queu::CmdQueue = queue(), blocking::Bool=false,
wait_for::Vector{Event}=Event[])
function enqueue_svm_map(
ptr::Union{Ptr, CLPtr}, nbytes::Integer, flags = :rw; queu::CmdQueue = queue(), blocking::Bool = false,
wait_for::Vector{Event} = Event[]
)
flags = if flags == :rw
CL_MAP_READ | CL_MAP_WRITE
elseif flags == :r
Expand All @@ -82,15 +86,17 @@ function enqueue_svm_map(ptr::Union{Ptr, CLPtr}, nbytes::Integer, flags=:rw; que
evt_ids = isempty(wait_for) ? C_NULL : [pointer(evt) for evt in wait_for]
GC.@preserve wait_for begin
ret_evt = Ref{cl_event}()
ext_clEnqueueSVMMap(queu, blocking, flags, ptr, nbytes,
n_evts, evt_ids, ret_evt)
ext_clEnqueueSVMMap(
queu, blocking, flags, ptr, nbytes,
n_evts, evt_ids, ret_evt
)

return Event(ret_evt[])
end
end

# unmap a buffer, returning an event
function enqueue_svm_unmap(ptr::Union{Ptr, CLPtr}; queu::CmdQueue=queue(), wait_for::Vector{Event}=Event[])
function enqueue_svm_unmap(ptr::Union{Ptr, CLPtr}; queu::CmdQueue = queue(), wait_for::Vector{Event} = Event[])
n_evts = length(wait_for)
evt_ids = isempty(wait_for) ? C_NULL : [pointer(evt) for evt in wait_for]
GC.@preserve wait_for begin
Expand All @@ -101,15 +107,17 @@ function enqueue_svm_unmap(ptr::Union{Ptr, CLPtr}; queu::CmdQueue=queue(), wait_
end

# fill a buffer with a pattern, returning an event
function enqueue_svm_fill(ptr::Union{Ptr, CLPtr}, pattern::Union{Ptr{T}, CLPtr{T}}, pattern_size::Integer, nbytes::Integer; queu::CmdQueue=queue(), wait_for::Vector{Event}=Event[]) where {T}
function enqueue_svm_fill(ptr::Union{Ptr, CLPtr}, pattern::Union{Ptr{T}, CLPtr{T}}, pattern_size::Integer, nbytes::Integer; queu::CmdQueue = queue(), wait_for::Vector{Event} = Event[]) where {T}
@assert pattern_size > 0
n_evts = length(wait_for)
evt_ids = isempty(wait_for) ? C_NULL : [pointer(evt) for evt in wait_for]
GC.@preserve wait_for begin
return GC.@preserve wait_for begin
ret_evt = Ref{cl_event}()
ext_clEnqueueSVMMemFill(queu, ptr, pattern,
ext_clEnqueueSVMMemFill(
queu, ptr, pattern,
pattern_size, nbytes,
n_evts, evt_ids, ret_evt)
n_evts, evt_ids, ret_evt
)
@return_event ret_evt[]
end
end
Expand Down
Loading

0 comments on commit 1e5ae72

Please sign in to comment.