Skip to content

[0.10] add get_backend for StaticArrays #622

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SPIRVIntrinsics = "71d1d633-e7e8-4a92-83a1-de8814b09ba8"
SPIRV_LLVM_Backend_jll = "4376b9bf-cff8-51b6-bb48-39421dff0d0c"
SPIRV_Tools_jll = "6ac6d60f-d740-5983-97d7-a4482c0689f4"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
pocl_jll = "627d6b7a-bbe6-5189-83e7-98cc0a5aeadd"

[weakdeps]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -29,6 +29,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
EnzymeExt = "EnzymeCore"
LinearAlgebraExt = "LinearAlgebra"
SparseArraysExt = "SparseArrays"
StaticArraysExt = "StaticArrays"

[compat]
Adapt = "0.4, 1.0, 2.0, 3.0, 4"
Expand All @@ -50,6 +51,7 @@ julia = "1.10"
pocl_jll = "7"

[extras]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Comment on lines 52 to 57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[extras]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

Since test/Porject.toml exists, I think this can be deleted and the StaticArrays entry added to that file instead

9 changes: 9 additions & 0 deletions ext/StaticArraysExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module StaticArraysExt

import KernelAbstractions: get_backend, CPU
using StaticArrays: SizedArray, MArray

get_backend(A::SizedArray) = get_backend(A.data)
get_backend(::MArray) = CPU()

end
1 change: 0 additions & 1 deletion src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import PrecompileTools
import Atomix: @atomic, @atomicswap, @atomicreplace

using MacroTools
using StaticArrays
using Adapt

"""
Expand Down
13 changes: 13 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using InteractiveUtils
using LinearAlgebra
using SparseArrays
using Adapt
using StaticArrays

identity(x) = x

Expand Down Expand Up @@ -95,6 +96,18 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
@test @inferred(KernelAbstractions.get_backend(sparse(A))) isa backendT
end

@conditional_testset "StaticArrays" skip_tests begin
backend = Backend()
backendT = typeof(backend).name.wrapper # To look through CUDABackend{true, false}
@test backend isa backendT

@test KernelAbstractions.get_backend(@MMatrix [1.0]) isa CPU
@test_throws ArgumentError KernelAbstractions.get_backend(@SMatrix [1.0])

A = allocate(backend, Float32, 5, 5)
@test @inferred(KernelAbstractions.get_backend(SizedMatrix{5, 5}(A))) isa backendT
end

@conditional_testset "adapt" skip_tests begin
backend = Backend()
x = allocate(backend, Float32, 5)
Expand Down
Loading