Repository: JuliaGPU/KernelAbstractions.jl (julia)

Issue:
KA.functional(::Backend) to mimick CUDA.functional

Pull request description:
Fixes #489

Patch:
diff --git a/src/KernelAbstractions.jl b/src/KernelAbstractions.jl
index efec0c4d..c3aeb7c8 100644
--- a/src/KernelAbstractions.jl
+++ b/src/KernelAbstractions.jl
@@ -551,6 +551,22 @@ function priority!(::Backend, prio::Symbol)
     return nothing
 end
 
+"""
+    functional(::Backend)
+
+Queries if the provided backend is functional. This may mean different
+things for different backends, but generally should mean that the
+necessary drivers and a compute device are available.
+
+This function should return a `Bool` or `missing` if not implemented.
+
+!!! compat "KernelAbstractions v0.9.22"
+    This function was added in KernelAbstractions v0.9.22
+"""
+function functional(::Backend)
+    return missing
+end
+
 include("nditeration.jl")
 using .NDIteration
 import .NDIteration: get
diff --git a/src/cpu.jl b/src/cpu.jl
index 8c3e8afd..34e48d9d 100644
--- a/src/cpu.jl
+++ b/src/cpu.jl
@@ -34,6 +34,8 @@ function copyto!(backend::CPU, A, B)
     end
 end
 
+functional(::CPU) = true
+
 function (obj::Kernel{CPU})(args...; ndrange=nothing, workgroupsize=nothing, )
     ndrange, workgroupsize, iterspace, dynamic = launch_config(obj, ndrange, workgroupsize)
 


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 15c33e27..d7cca6ca 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -66,6 +66,8 @@ struct NewBackend <: KernelAbstractions.GPU end
 
     @test_throws ErrorException KernelAbstractions.priority!(backend, :middle)
 
+    @test KernelAbstractions.functional(backend) === missing
+
     kernel = my_no_cpu_kernel(backend)
     @test_throws MethodError kernel()
 end
diff --git a/test/test.jl b/test/test.jl
index 88086342..2eda66e0 100644
--- a/test/test.jl
+++ b/test/test.jl
@@ -278,4 +278,8 @@ end
     end
 end
 
+@testset "functional" begin
+    @test KernelAbstractions.functional(Backend()) isa Union{Missing, Bool}
+end
+
 end