# L-17 MCS 572 Fri 4 Oct 2024 : gpuadd1metal.jl # The CUDA version is copied from the tutorial at # https://cuda.juliagpu.org/stable/tutorials/introduction/ # and adjusted for use on an M1 MacBook Air with Metal using Metal using Test function gpu_add1!(y, x) for i = 1:length(y) @inbounds y[i] += x[i] end return nothing end N = 32 x_d = Metal.fill(1.0f0, N) # filled with Float32 1.0 on GPU y_d = Metal.fill(2.0f0, N) # filled with Float32 2.0 # run with N threads @metal threads=N gpu_add1!(y_d, x_d) result = (@test all(Array(y_d) .== 3.0f0)) println(result)