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 Jan 28, 2025
1 parent 8bfe8de commit 198f5cd
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

Check warning on line 190 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L190

Added line #L190 was not covered by tests

###
# 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)

Check warning on line 24 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L24

Added line #L24 was not covered by tests

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

Check warning on line 30 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L26-L30

Added lines #L26 - L30 were not covered by tests
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

Check warning on line 36 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L32-L36

Added lines #L32 - L36 were not covered by tests
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")

Check warning on line 42 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L39-L42

Added lines #L39 - L42 were not covered by tests
end
if Base.mightalias(A, B)
error("Arrays may not alias")

Check warning on line 45 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L44-L45

Added lines #L44 - L45 were not covered by tests
end
kernel = copy_kernel(backend)
kernel(A, B, ndrange = length(A))
return A

Check warning on line 49 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L47-L49

Added lines #L47 - L49 were not covered by tests
else
return Base.copyto!(A, B)

Check warning on line 51 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L51

Added line #L51 was not covered by tests
end
end

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

Check warning on line 56 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L55-L56

Added lines #L55 - L56 were not covered by tests

# 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

Check warning on line 60 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L58-L60

Added lines #L58 - L60 were not covered by tests


## 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

Check warning on line 71 in src/pocl/pocl.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/pocl.jl#L71

Added line #L71 was not covered by tests

Expand Down

0 comments on commit 198f5cd

Please sign in to comment.