Skip to content

Commit 7892d2b

Browse files
Merge pull request #468 from JuliaArrays/fix-metal-lu-instance
Add Metal.jl support for lu_instance
2 parents e4068ff + d7d7b7b commit 7892d2b

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
- Core
1616
version:
1717
- '1'
18+
os:
19+
- ubuntu-latest
20+
- macos-latest
21+
- windows-latest
1822
steps:
1923
- uses: actions/checkout@v5
2024
- uses: julia-actions/setup-julia@v1
@@ -37,4 +41,4 @@ jobs:
3741
- uses: julia-actions/julia-processcoverage@v1
3842
- uses: codecov/codecov-action@v5
3943
with:
40-
file: lcov.info
44+
file: lcov.info

Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CUDSS = "45b445bb-4962-46a0-9369-b4df9d0f772e"
1414
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
1515
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1616
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
17+
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
1718
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
1819
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1920
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
@@ -27,6 +28,7 @@ ArrayInterfaceCUDSSExt = "CUDSS"
2728
ArrayInterfaceChainRulesCoreExt = "ChainRulesCore"
2829
ArrayInterfaceChainRulesExt = "ChainRules"
2930
ArrayInterfaceGPUArraysCoreExt = "GPUArraysCore"
31+
ArrayInterfaceMetalExt = "Metal"
3032
ArrayInterfaceReverseDiffExt = "ReverseDiff"
3133
ArrayInterfaceSparseArraysExt = "SparseArrays"
3234
ArrayInterfaceStaticArraysCoreExt = "StaticArraysCore"
@@ -43,6 +45,7 @@ ChainRulesCore = "1"
4345
ChainRulesTestUtils = "1"
4446
GPUArraysCore = "0.1, 0.2"
4547
LinearAlgebra = "1.10"
48+
Metal = "1"
4649
ReverseDiff = "1"
4750
SparseArrays = "1.10"
4851
StaticArraysCore = "1"
@@ -59,6 +62,8 @@ ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
5962
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
6063
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
6164
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
65+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
66+
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
6267
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
6368
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6469
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"

ext/ArrayInterfaceMetalExt.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ArrayInterfaceMetalExt
2+
3+
using ArrayInterface
4+
using Metal
5+
using LinearAlgebra
6+
7+
function ArrayInterface.lu_instance(A::MtlMatrix{T}) where {T}
8+
ipiv = MtlVector{Int32}(undef, 0)
9+
info = zero(Int)
10+
return LinearAlgebra.LU(similar(A, 0, 0), ipiv, info)
11+
end
12+
13+
ArrayInterface.device(::Type{<:Metal.MtlArray}) = ArrayInterface.GPU()
14+
15+
end # module

test/gpu/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2-
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
2+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3+
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"

test/gpu/metal.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Metal
2+
using ArrayInterface
3+
using LinearAlgebra
4+
5+
using Test
6+
7+
# Test that lu_instance works with Metal.jl gpu arrays
8+
@test isa(ArrayInterface.lu_instance(MtlArray([1.f0 1.f0; 1.f0 1.f0])), LU)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ end
2121
if GROUP == "GPU"
2222
activate_gpu_env()
2323
@time @safetestset "CUDA" begin include("gpu/cuda.jl") end
24+
if Sys.isapple()
25+
@time @safetestset "Metal" begin include("gpu/metal.jl") end
26+
end
2427
end
2528
end

0 commit comments

Comments
 (0)