Skip to content

Commit

Permalink
fixup! yank CPU backend
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Feb 5, 2025
1 parent ba30695 commit a61ac84
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ After releasing the memory of an array, it should no longer be accessed.
"""
function unsafe_free! end

unsafe_free!(::AbstractArray) = return

###
# Kernel language
# - @localmem
Expand Down
1 change: 0 additions & 1 deletion src/cpu.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
unsafe_free!(::AbstractArray) = return
synchronize(::CPU) = nothing

allocate(::CPU, ::Type{T}, dims::Tuple) where {T} = Array{T}(undef, dims)
Expand Down
51 changes: 36 additions & 15 deletions src/pocl/backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,46 @@ export POCLBackend
struct POCLBackend <: KA.GPU
end

# KA.allocate(::POCLBackend, ::Type{T}, dims::Tuple) where T = CLArray{T}(undef, dims)
# KA.zeros(::POCLBackend, ::Type{T}, dims::Tuple) where T = OpenCL.zeros(T, dims)
# KA.ones(::POCLBackend, ::Type{T}, dims::Tuple) where T = OpenCL.ones(T, dims)

# KA.get_backend(::CLArray) = POCLBackend()
# KA.synchronize(::POCLBackend) = cl.finish(cl.queue())
# KA.supports_float64(::POCLBackend) = false # XXX: this is platform/device dependent

# Adapt.adapt_storage(::POCLBackend, a::Array) = Adapt.adapt(CLArray, a)
# Adapt.adapt_storage(::POCLBackend, a::CLArray) = a
# Adapt.adapt_storage(::KA.CPU, a::CLArray) = convert(Array, a)
## Memory Operations

KA.allocate(::POCLBackend, ::Type{T}, dims::Tuple) where {T} = Array{T}(undef, dims)

function KA.zeros(backend::POCLBackend, ::Type{T}, dims::Tuple) where {T}
arr = allocate(backend, T, dims)
kernel = init_kernel(backend)
kernel(arr, zero, T, ndrange = length(arr))
return arr
end
function KA.ones(backend::POCLBackend, ::Type{T}, dims::Tuple) where {T}
arr = allocate(backend, T, dims)
kernel = init_kernel(backend)
kernel(arr, one, T; ndrange = length(arr))
return arr
end

function KA.copyto!(backend::POCLBackend, A, B)
if get_backend(A) == get_backend(B) && get_backend(A) isa POCLBackend
if length(A) != length(B)
error("Arrays must match in length")
end
if Base.mightalias(A, B)
error("Arrays may not alias")
end
kernel = copy_kernel(backend)
kernel(A, B, ndrange = length(A))
return A
else
return Base.copyto!(A, B)
end
end

## Memory Operations
KA.functional(::POCLBackend) = true
KA.pagelock!(::POCLBackend, x) = nothing

# function KA.copyto!(::POCLBackend, A, B)
# copyto!(A, B)
# # TODO: Address device to host copies in jl being synchronizing
# end
KA.get_backend(::Array) = POCLBackend()
KA.synchronize(::POCLBackend) = nothing
KA.supports_float64(::POCLBackend) = true


## Kernel Launch
Expand Down
1 change: 0 additions & 1 deletion src/pocl/pocl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import .POCLKernels: POCLBackend
export POCLBackend

import KernelAbstractions as KA
KA.get_backend(::Array) = POCLBackend()

Adapt.adapt_storage(::POCLBackend, a::Array) = a

Expand Down

0 comments on commit a61ac84

Please sign in to comment.