Skip to content

Commit d32fdc2

Browse files
committed
Make Metal availability check static and platform-aware
- Updated usemetal() to be a static check that returns false on non-Apple platforms - Modified MetalLUFactorization constructor to check platform with @static - Updated test files to skip Metal tests on non-Apple platforms - This fixes CI failures on Linux where Metal is not available Following the same pattern as AppleAccelerateLUFactorization for consistency. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 104aae0 commit d32fdc2

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

src/LinearSolve.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,13 @@ appleaccelerate_isavailable() = HAS_APPLE_ACCELERATE[]
410410
# Extension availability checking functions
411411
useblis() = Base.get_extension(@__MODULE__, :LinearSolveBLISExt) !== nothing
412412
usecuda() = Base.get_extension(@__MODULE__, :LinearSolveCUDAExt) !== nothing
413-
usemetal() = Base.get_extension(@__MODULE__, :LinearSolveMetalExt) !== nothing
413+
414+
# Metal is only available on Apple platforms
415+
@static if !Sys.isapple()
416+
usemetal() = false
417+
else
418+
usemetal() = Base.get_extension(@__MODULE__, :LinearSolveMetalExt) !== nothing
419+
end
414420

415421
PrecompileTools.@compile_workload begin
416422
A = rand(4, 4)

src/extension_algs.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,19 @@ sol = solve(prob, alg)
633633
"""
634634
struct MetalLUFactorization <: AbstractFactorization
635635
function MetalLUFactorization(; throwerror = true)
636-
ext = Base.get_extension(@__MODULE__, :LinearSolveMetalExt)
637-
if ext === nothing && throwerror
638-
error("MetalLUFactorization requires that Metal.jl is loaded, i.e. `using Metal`")
636+
@static if !Sys.isapple()
637+
if throwerror
638+
error("MetalLUFactorization is only available on Apple platforms")
639+
else
640+
return new()
641+
end
639642
else
640-
return new()
643+
ext = Base.get_extension(@__MODULE__, :LinearSolveMetalExt)
644+
if ext === nothing && throwerror
645+
error("MetalLUFactorization requires that Metal.jl is loaded, i.e. `using Metal`")
646+
else
647+
return new()
648+
end
641649
end
642650
end
643651
end

test/nopre/jet.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ end
6363

6464
# CUDA/Metal factorizations (only test if CUDA/Metal are loaded)
6565
# CudaOffloadFactorization requires CUDA to be loaded, skip if not available
66-
if @isdefined(MetalLUFactorization)
66+
# Metal is only available on Apple platforms
67+
if Sys.isapple() && @isdefined(MetalLUFactorization)
6768
JET.@test_opt solve(prob, MetalLUFactorization()) broken=true
6869
end
6970
if @isdefined(BLISLUFactorization)

test_new_solvers.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,27 @@ end
3535
alg2 = LinearSolve.CudaOffloadLUFactorization(throwerror=false)
3636
@test alg2 isa LinearSolve.CudaOffloadLUFactorization
3737

38-
alg3 = LinearSolve.MetalLUFactorization(throwerror=false)
39-
@test alg3 isa LinearSolve.MetalLUFactorization
38+
# Metal is only available on Apple platforms
39+
if Sys.isapple()
40+
alg3 = LinearSolve.MetalLUFactorization(throwerror=false)
41+
@test alg3 isa LinearSolve.MetalLUFactorization
42+
else
43+
# On non-Apple platforms, it should still not error with throwerror=false
44+
alg3 = LinearSolve.MetalLUFactorization(throwerror=false)
45+
@test alg3 isa LinearSolve.MetalLUFactorization
46+
end
4047

4148
# These should throw errors with throwerror=true (default)
4249
@test_throws ErrorException LinearSolve.BLISLUFactorization()
4350
@test_throws ErrorException LinearSolve.CudaOffloadLUFactorization()
44-
@test_throws ErrorException LinearSolve.MetalLUFactorization()
51+
52+
# Metal error message depends on platform
53+
if Sys.isapple()
54+
@test_throws ErrorException LinearSolve.MetalLUFactorization()
55+
else
56+
# On non-Apple platforms, should error with platform message
57+
@test_throws ErrorException LinearSolve.MetalLUFactorization()
58+
end
4559
end
4660

4761
# Test that preferences system recognizes the new algorithms

0 commit comments

Comments
 (0)