File tree Expand file tree Collapse file tree 1 file changed +13
-25
lines changed Expand file tree Collapse file tree 1 file changed +13
-25
lines changed Original file line number Diff line number Diff line change @@ -2,33 +2,21 @@ using Test
22using Metal
33
44function vadd (a, b, c)
5- i0 = Tuple (thread_position_in_grid_3d ())
6- stride = Tuple (threads_per_grid_3d ())
7- is = i0
8- while 1 <= is[1 ] <= size (a, 1 ) &&
9- 1 <= is[2 ] <= size (a, 2 ) &&
10- 1 <= is[3 ] <= size (a, 3 )
11- I = CartesianIndex (is)
12- c[I] = a[I] + b[I]
13- is = (is[1 ] + stride[1 ],
14- is[2 ] + stride[2 ],
15- is[3 ] + stride[3 ])
16- end
5+ i = thread_position_in_grid_1d ()
6+ c[i] = a[i] + b[i]
177 return
188end
199
20- function main ()
21- dims = (3 ,4 ,5 )
22- a = round .(rand (Float32, dims) * 100 )
23- b = round .(rand (Float32, dims) * 100 )
24- c = similar (a)
10+ dims = (3 ,4 )
11+ a = round .(rand (Float32, dims) * 100 )
12+ b = round .(rand (Float32, dims) * 100 )
13+ c = similar (a)
2514
26- d_a = MtlArray (a)
27- d_b = MtlArray (b)
28- d_c = MtlArray (c)
15+ d_a = MtlArray (a)
16+ d_b = MtlArray (b)
17+ d_c = MtlArray (c)
2918
30- len = prod (dims)
31- @metal threads= dims vadd (d_a, d_b, d_c)
32- c = Array (d_c)
33- @test a+ b ≈ c
34- end
19+ len = prod (dims)
20+ @metal threads= len vadd (d_a, d_b, d_c)
21+ c = Array (d_c)
22+ @test a+ b ≈ c
You can’t perform that action at this time.
0 commit comments