Skip to content

Commit

Permalink
replace (gpu) boolean_indicator with AK.jl version
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale-Black committed Dec 26, 2024
1 parent 3381c43 commit ceccac5
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using KernelAbstractions
using GPUArraysCore: AbstractGPUArray
import AcceleratedKernels as AK

export boolean_indicator

"""
## `boolean_indicator`
Expand Down Expand Up @@ -46,25 +49,17 @@ function boolean_indicator(f)
end

function boolean_indicator(f::BitArray)
f_new = similar(f, Float32)
for i in CartesianIndices(f_new)
@inbounds f_new[i] = f[i] ? 0.0f0 : 1.0f10
end
return f_new
end

@kernel function boolean_indicator_kernel(f, output)
i = @index(Global)
output[i] = ifelse(f[i] == 0, 1.0f10, 0.0f0)
f_new = similar(f, Float32)
for i in eachindex(f)
@inbounds f_new[i] = f[i] ? 0.0f0 : 1.0f10
end
return f_new
end

function boolean_indicator(f::AbstractGPUArray)
backend = get_backend(f)
output = similar(f, Float32)
kernel = boolean_indicator_kernel(backend)
kernel(f, output, ndrange=size(f))
KernelAbstractions.synchronize(backend)
return output
end

export boolean_indicator
f_new = similar(f, Float32)
AK.foreachindex(f) do i
@inbounds f_new[i] = f[i] == false ? 1.0f10 : 0.0f0
end
return f_new
end

0 comments on commit ceccac5

Please sign in to comment.