Skip to content

prevent get_backend from overflowing the stack #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ Get a [`Backend`](@ref) instance suitable for array `A`.
function get_backend end

# Should cover SubArray, ReshapedArray, ReinterpretArray, Hermitian, AbstractTriangular, etc.:
get_backend(A::AbstractArray) = get_backend(parent(A))
function get_backend(A::AbstractArray)
P = parent(A)
if P isa typeof(A)
throw(ArgumentError("Implement `KernelAbstractions.get_backend(::$(typeof(A)))`"))
end
return get_backend(P)
end

# Define:
# adapt_storage(::Backend, a::Array) = adapt(BackendArray, a)
Expand Down
4 changes: 4 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using Adapt

identity(x) = x

struct UnknownAbstractVector <: AbstractVector{Float32} # issue #588
end

function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; skip_tests = Set{String}())
@conditional_testset "partition" skip_tests begin
backend = Backend()
Expand Down Expand Up @@ -80,6 +83,7 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
@test @inferred(KernelAbstractions.get_backend(view(A, 2:4, 1:3))) isa backendT
@test @inferred(KernelAbstractions.get_backend(Diagonal(x))) isa backendT
@test @inferred(KernelAbstractions.get_backend(Tridiagonal(A))) isa backendT
@test_throws ArgumentError KernelAbstractions.get_backend(UnknownAbstractVector()) # issue #588
end

@conditional_testset "sparse" skip_tests begin
Expand Down
Loading