From 01cfa1141bc38dbbdfdd850d35f6aff8a1357714 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:30:34 -0400 Subject: [PATCH 1/5] Typo --- lib/mps/matrixrandom.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mps/matrixrandom.jl b/lib/mps/matrixrandom.jl index e4d80ae35..cca50a95a 100644 --- a/lib/mps/matrixrandom.jl +++ b/lib/mps/matrixrandom.jl @@ -16,7 +16,7 @@ export MPSMatrixRandomDistributionDescriptor @autoproperty distributionType::MPSMatrixRandomDistribution @autoproperty maximum::Float32 setter=setMaximum @autoproperty mean::Float32 setter=setMean - @autoproperty minimum::Float32 setter=setMimimum + @autoproperty minimum::Float32 setter=setMinimum @autoproperty standardDeviation::Float32 setter=setStandardDeviation end From d45fcb544e58dd53b92f70ffb7241f0f974ad65c Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:05:07 -0400 Subject: [PATCH 2/5] Add `is_m4` --- lib/mtl/device.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mtl/device.jl b/lib/mtl/device.jl index 9297fe344..2931597fc 100644 --- a/lib/mtl/device.jl +++ b/lib/mtl/device.jl @@ -122,3 +122,4 @@ is_m1(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple7) && is_m2(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple8) && !supports_family(dev, MTLGPUFamilyApple9) is_m3(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) +is_m4(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) From 5db2e6d60adcc6cd3cb99cfbf577d5c68798cab0 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:13:12 -0400 Subject: [PATCH 3/5] Typo [skip benchmarks] --- lib/mps/matrix.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mps/matrix.jl b/lib/mps/matrix.jl index c971a3218..a9d18fee6 100644 --- a/lib/mps/matrix.jl +++ b/lib/mps/matrix.jl @@ -211,7 +211,7 @@ function encode!(cmdbuf::MTLCommandBuffer, matmul::MPSMatrixMultiplication, left end """ - matMulMPS(a::MtlMatrix, b::MtlMatrix, c::MtlMatrix, alpha=1, beta=1, + matmul!(a::MtlMatrix, b::MtlMatrix, c::MtlMatrix, alpha=1, beta=1, transpose_left=false, transpose_right=false) A `MPSMatrixMultiplication` kernel thay computes: `c = alpha * op(a) * beta * op(b) + beta * C` From bbfb3631feb7f8c2cedf62bb1d9b626316c64d44 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:04:16 -0400 Subject: [PATCH 4/5] Check device string [skip benchmarks] --- lib/mtl/device.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mtl/device.jl b/lib/mtl/device.jl index 2931597fc..0747006e4 100644 --- a/lib/mtl/device.jl +++ b/lib/mtl/device.jl @@ -91,7 +91,7 @@ MTLDevice(i::Integer) = devices()[i] # family # -export supports_family, is_m3, is_m2, is_m1 +export supports_family, is_m4, is_m3, is_m2, is_m1 @cenum MTLGPUFamily::NSInteger begin MTLGPUFamilyMetal3 = 5001 # Metal 3 support @@ -121,5 +121,7 @@ is_m1(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple7) && !supports_family(dev, MTLGPUFamilyApple8) is_m2(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple8) && !supports_family(dev, MTLGPUFamilyApple9) -is_m3(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) -is_m4(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) +is_m3(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) && + occursin("M3", String(dev.name)) +is_m4(dev::MTLDevice) = supports_family(dev, MTLGPUFamilyApple9) && + occursin("M4", String(dev.name)) From bcf2d39fb8d8834d991d70038513fd0a970f2148 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:15:34 -0400 Subject: [PATCH 5/5] Small MPSNDArray fixes --- lib/mps/ndarray.jl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/mps/ndarray.jl b/lib/mps/ndarray.jl index d55b87600..2bdeec285 100644 --- a/lib/mps/ndarray.jl +++ b/lib/mps/ndarray.jl @@ -82,7 +82,7 @@ end end function MPSTemporaryNDArray(cmdbuf::MTLCommandBuffer, descriptor::MPSNDArrayDescriptor) - @objc [MPSNDTemporaryNDArray temporaryNDArrayWithCommandBuffer:cmdbuf::id{MTLCommandBuffer} + @objc [MPSTemporaryNDArray temporaryNDArrayWithCommandBuffer:cmdbuf::id{MTLCommandBuffer} descriptor:descriptor::id{MPSNDArrayDescriptor}]::id{MPSTemporaryNDArray} return obj end @@ -123,7 +123,7 @@ end return obj end else - function MPSNDArray(buffer::MTLBuffer, offset::UInt, descriptor::MPSNDArrayDescriptor) + function MPSNDArray(_::MTLBuffer, _::UInt, _::MPSNDArrayDescriptor) @assert false "Creating an MPSNDArray that shares data with user-provided MTLBuffer is only supported in macOS v15+" end end @@ -135,20 +135,18 @@ function MPSNDArray(arr::MtlArray{T,N}) where {T,N} return MPSNDArray(arr.data[], UInt(arr.offset), desc) end -function Metal.MtlArray(ndarr::MPSNDArray; storage = Metal.DefaultStorageMode) +function Metal.MtlArray(ndarr::MPSNDArray; storage = Metal.DefaultStorageMode, async = false) ndims = Int(ndarr.numberOfDimensions) arrsize = [lengthOfDimension(ndarr,i) for i in 0:ndims-1] T = convert(DataType, ndarr.dataType) arr = MtlArray{T,ndims,storage}(undef, reverse(arrsize)...) dev = device(arr) - cmdBuf = MTLCommandBuffer(global_queue(dev)) - - exportDataWithCommandBuffer(ndarr, cmdBuf, arr.data[], T, 0, collect(sizeof(T) .* reverse(strides(arr)))) - - commit!(cmdBuf) - wait_completed(cmdBuf) + cmdBuf = MTLCommandBuffer(global_queue(dev)) do cmdBuf + exportDataWithCommandBuffer(ndarr, cmdBuf, arr.data[], T, 0, collect(sizeof(T) .* reverse(strides(arr)))) + end + async || wait_completed(cmdBuf) return arr end