Skip to content

Commit

Permalink
Test loading of package on unsupported platforms (#509)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Besard <[email protected]>
  • Loading branch information
christiangnrd and maleadt authored Jan 7, 2025
1 parent 6ac7f3c commit aae82e4
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 6 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Loading

on:
pull_request:
branches:
- main
push:
branches:
- main
tags: '*'

# needed for julia-actions/cache to delete old caches
permissions:
actions: write
contents: read

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1' # latest stable 1.x release
os:
- 'ubuntu-latest'
- 'macOS-13'
- 'windows-latest'
arch:
- x64
include:
- os: macOS-latest
version: '1'
arch: aarch64

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}

- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1

- name: Run tests
uses: julia-actions/julia-runtest@v1
4 changes: 2 additions & 2 deletions lib/mps/ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export MPSNDArray

@objcwrapper immutable=false MPSNDArray <: NSObject

@static if Metal.macos_version() >= v"15"
@static if Metal.is_macos(v"15")
@objcproperties MPSNDArray begin
@autoproperty dataType::MPSDataType
@autoproperty dataTypeSize::Csize_t
Expand Down Expand Up @@ -116,7 +116,7 @@ function MPSNDArray(device::MTLDevice, scalar)
return obj
end

@static if Metal.macos_version() >= v"15"
@static if Metal.is_macos(v"15")
function MPSNDArray(buffer::MTLBuffer, offset::UInt, descriptor::MPSNDArrayDescriptor)
arrayaddr = @objc [MPSNDArray alloc]::id{MPSNDArray}
obj = MPSNDArray(arrayaddr)
Expand Down
8 changes: 8 additions & 0 deletions lib/mtl/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

export MTLDevice, MTLCreateSystemDefaultDevice, devices

@static if Metal.is_macos(v"14")
@objcwrapper MTLArchitecture <: NSObject

@objcproperties MTLArchitecture begin
@autoproperty architecture::id{NSString}
end
end

@objcwrapper MTLDevice <: NSObject

@objcproperties MTLDevice begin
Expand Down
2 changes: 1 addition & 1 deletion src/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function device()
get!(task_local_storage(), :MTLDevice) do
dev = MTLDevice(1)
if !supports_family(dev, MTL.MTLGPUFamilyApple7)
@warn """Metal.jl is only supported on Apple Silicon, you may run into issues.
@warn """Metal.jl is only supported on non-virtualized Apple Silicon, you may run into issues.
See https://github.com/JuliaGPU/Metal.jl/issues/22 for more details.""" maxlog=1
end
if !supports_family(dev, MTL.MTLGPUFamilyMetal3)
Expand Down
17 changes: 17 additions & 0 deletions src/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ Returns the host macOS version.
See also [`Metal.darwin_version`](@ref).
""" macos_version

"""
Metal.is_macos([ver::VersionNumber]) -> Bool
Returns whether the OS is macOS with version `ver` or newer.
See also [`Metal.macos_version`](@ref).
"""
function is_macos(ver=nothing)
if !Sys.isapple()
false
elseif ver === nothing
true
else
macos_version() >= ver
end
end


## support queries

Expand Down
28 changes: 27 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
using Distributed
using Dates
import REPL
using Metal
using Printf: @sprintf
import REPL
using Test

# Quit without erroring if Metal loaded without issues on unsupported platforms
if !Sys.isapple()
@warn """Metal.jl succesfully loaded on non-macOS system.
This system is unsupported but should still load.
Skipping tests."""
Sys.exit()
else # if Sys.isapple()
archchecker = occursin(read(`xcrun metal-arch --name`, String))
if archchecker("Paravirtual") # Virtualized graphics (probably Github Actions runners)
@warn """Metal.jl succesfully loaded on macOS system with unsupported Paravirtual graphics.
This system is unsupported but should still load.
Skipping tests."""
Sys.exit()
elseif !archchecker("applegpu") # Every other unsupported system (Intel or AMD graphics)
@warn """Metal.jl succesfully loaded on macOS system with unsupported graphics.
This system is unsupported but should still load.
Skipping tests."""
Sys.exit()
end
end

# If we ever error here, fix above
Metal.functional() || error("Metal.jl is not functional on this system. This is unexpected; please file an issue.")

# parse some command-line arguments
function extract_flag!(args, flag, default=nothing)
Expand Down
2 changes: 0 additions & 2 deletions test/setup.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Distributed, Test, Metal, Adapt, ObjectiveC, ObjectiveC.Foundation

Metal.functional() || error("Metal.jl is not functional on this system")

# GPUArrays has a testsuite that isn't part of the main package.
# Include it directly.
import GPUArrays
Expand Down

0 comments on commit aae82e4

Please sign in to comment.