Skip to content
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

Test loading of package on unsupported platforms #509

Merged
merged 8 commits into from
Jan 7, 2025
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
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
maleadt marked this conversation as resolved.
Show resolved Hide resolved
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
Loading