diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..8a3d4cb1c --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/lib/mps/ndarray.jl b/lib/mps/ndarray.jl index 4384ff1e5..2c52bab95 100644 --- a/lib/mps/ndarray.jl +++ b/lib/mps/ndarray.jl @@ -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 @@ -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) diff --git a/lib/mtl/device.jl b/lib/mtl/device.jl index fccbebc1e..db7feecd2 100644 --- a/lib/mtl/device.jl +++ b/lib/mtl/device.jl @@ -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 diff --git a/src/state.jl b/src/state.jl index 2208f739e..3a0512e52 100644 --- a/src/state.jl +++ b/src/state.jl @@ -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) diff --git a/src/version.jl b/src/version.jl index 0d2c4ffec..87b778c34 100644 --- a/src/version.jl +++ b/src/version.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 187b5b9b8..f93c638c2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) diff --git a/test/setup.jl b/test/setup.jl index 4694234c9..4d56bcf20 100644 --- a/test/setup.jl +++ b/test/setup.jl @@ -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