forked from JuliaGPU/CUDA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vadd.jl
26 lines (18 loc) · 583 Bytes
/
vadd.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using Test
using CUDAdrv
include(joinpath(@__DIR__, "..", "test", "array.jl")) # real applications: use CuArrays.jl
dev = CuDevice(0)
ctx = CuContext(dev)
md = CuModuleFile(joinpath(@__DIR__, "vadd.ptx"))
vadd = CuFunction(md, "kernel_vadd")
dims = (3,4)
a = round.(rand(Float32, dims) * 100)
b = round.(rand(Float32, dims) * 100)
c = similar(a)
d_a = CuTestArray(a)
d_b = CuTestArray(b)
d_c = CuTestArray(c)
len = prod(dims)
cudacall(vadd, Tuple{CuPtr{Cfloat},CuPtr{Cfloat},CuPtr{Cfloat}}, d_a, d_b, d_c; threads=len)
@test a+b ≈ Array(d_c)
CUDAdrv.unsafe_destroy!(ctx)