Skip to content

Commit 170bfc0

Browse files
authored
Implement functional (#490)
1 parent 4285051 commit 170bfc0

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/KernelAbstractions.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,22 @@ function priority!(::Backend, prio::Symbol)
551551
return nothing
552552
end
553553

554+
"""
555+
functional(::Backend)
556+
557+
Queries if the provided backend is functional. This may mean different
558+
things for different backends, but generally should mean that the
559+
necessary drivers and a compute device are available.
560+
561+
This function should return a `Bool` or `missing` if not implemented.
562+
563+
!!! compat "KernelAbstractions v0.9.22"
564+
This function was added in KernelAbstractions v0.9.22
565+
"""
566+
function functional(::Backend)
567+
return missing
568+
end
569+
554570
include("nditeration.jl")
555571
using .NDIteration
556572
import .NDIteration: get

src/cpu.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function copyto!(backend::CPU, A, B)
3434
end
3535
end
3636

37+
functional(::CPU) = true
38+
3739
function (obj::Kernel{CPU})(args...; ndrange=nothing, workgroupsize=nothing, )
3840
ndrange, workgroupsize, iterspace, dynamic = launch_config(obj, ndrange, workgroupsize)
3941

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct NewBackend <: KernelAbstractions.GPU end
6666

6767
@test_throws ErrorException KernelAbstractions.priority!(backend, :middle)
6868

69+
@test KernelAbstractions.functional(backend) === missing
70+
6971
kernel = my_no_cpu_kernel(backend)
7072
@test_throws MethodError kernel()
7173
end

test/test.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,8 @@ end
278278
end
279279
end
280280

281+
@testset "functional" begin
282+
@test KernelAbstractions.functional(Backend()) isa Union{Missing, Bool}
283+
end
284+
281285
end

0 commit comments

Comments
 (0)