Comments (3)
I can reproduce on M2 Max Julia 1.10 and 1.11.
Take between 350 and 23000 iterations to reproduce using the code below.
count = 0
for _ in 1:50000
for typ in [Float16, Float32]
function kernel(a::MtlDeviceArray{T}, b::MtlDeviceArray{T}) where {T}
pos = thread_position_in_threadgroup_2d()
tg_a = MtlThreadGroupArray(T, (8, 8))
tg_a[pos.x, pos.y] = a[pos.x, pos.y]
sg_a = simdgroup_load(tg_a)
tg_b = MtlThreadGroupArray(T, (8, 8))
simdgroup_store(sg_a, tg_b)
b[pos.x, pos.y] = tg_b[pos.x, pos.y]
return
end
a = MtlArray(rand(typ, 8, 8))
b = MtlArray(zeros(typ, 8, 8))
@metal threads=(8, 8) kernel(a, b)
if Array(a) != Array(b)
@test Array(a) == Array(b)
end
end
count += 1
end
from metal.jl.
This didn't fail for 1000000 iterations just by adding threadgroup_barrier(Metal.MemoryFlagThreadGroup)
as shown below. Is this just a fluke? I still don't fully understand what barriers do so I don't know if this actually fixes the problem or just hides it.
count = 0
for _ in 1:50000
for typ in [Float16, Float32]
function kernel(a::MtlDeviceArray{T}, b::MtlDeviceArray{T}) where {T}
pos = thread_position_in_threadgroup_2d()
tg_a = MtlThreadGroupArray(T, (8, 8))
tg_a[pos.x, pos.y] = a[pos.x, pos.y]
threadgroup_barrier(Metal.MemoryFlagThreadGroup)
sg_a = simdgroup_load(tg_a)
tg_b = MtlThreadGroupArray(T, (8, 8))
simdgroup_store(sg_a, tg_b)
b[pos.x, pos.y] = tg_b[pos.x, pos.y]
return
end
a = MtlArray(rand(typ, 8, 8))
b = MtlArray(zeros(typ, 8, 8))
@metal threads=(8, 8) kernel(a, b)
if Array(a) != Array(b)
@test Array(a) == Array(b)
end
end
count += 1
end
from metal.jl.
Yeah, that does seem correct. I guess the simdgroup_load
could result in a different thread reading the threadgroup array, so we need a memory fence for the threagroup memory (aka. threadgroup_barrier(Metal.MemoryFlagThreadGroup)
) to ensure the correct memory is read by the SIMD operation afterwards.
Possibly we need another fence after the simdgroup_store
, since we're not directly having the wavefront store to device memory, but go through the threadgroup array first. I'll add one to be sure.
from metal.jl.
Related Issues (20)
- M1/M2: Large matrix multiplications can contains NaNs HOT 30
- `MTLBinaryArchive`
- `Metal.code_agx()` failing in MacOS 15 Beta 3 HOT 2
- Test for min / max broadcasting issue HOT 5
- Add a `metal_version` function
- Type piracy HOT 1
- Potentially unused code in gpuarrays.jl
- Control flow-related miscompilation: HOT 1
- Implement MPSMatrixSolve HOT 1
- `Shared` vs `SharedStorage` in examples/unified_memory HOT 2
- Unsuported call to an unknown function when calling `Distributions` HOT 3
- More sporadic 1.11 hangs HOT 4
- EnzymeRules for MTLArray Constructor
- Support for `LinearAlgebra.kron` HOT 2
- Can't use gemm! methods with Metal HOT 3
- Error for thread/group size with different integer types HOT 6
- README example broken HOT 2
- Display summary for `Metal.@profile`
- Simple throwing kernel hangs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metal.jl.