Skip to content

Commit 3ae1162

Browse files
authored
Avoid relying on a RNG in the back-end. (#686)
1 parent 4224ad9 commit 3ae1162

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

examples/matmul.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function matmul!(output, a, b)
2626
return
2727
end
2828

29-
a = rand!(allocate(backend, Float32, 256, 123))
30-
b = rand!(allocate(backend, Float32, 123, 45))
29+
a = copyto!(allocate(backend, Float32, 256, 123), rand(Float32, 256, 123))
30+
b = copyto!(allocate(backend, Float32, 123, 45), rand(Float32, 123, 45))
3131
output = KernelAbstractions.zeros(backend, Float32, 256, 45)
3232

3333
matmul!(output, a, b)

examples/naive_transpose.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
res = 1024
2626

2727
# creating initial arrays
28-
b = rand!(allocate(backend, Float32, res, res))
28+
b = copyto!(allocate(backend, Float32, res, res), rand(Float32, res, res))
2929
a = KernelAbstractions.zeros(backend, Float32, res, res)
3030

3131
naive_transpose!(a, b)

examples/numa_aware.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function measure_membw(
2727

2828
a = dtype(3.1415)
2929
if init == :serial
30-
X = rand!(zeros(dtype, N))
31-
Y = rand!(zeros(dtype, N))
30+
X = rand(dtype, N)
31+
Y = rand(dtype, N)
3232
else
33-
X = rand!(KernelAbstractions.zeros(backend, dtype, N))
34-
Y = rand!(KernelAbstractions.zeros(backend, dtype, N))
33+
X = copyto!(KernelAbstractions.zeros(backend, dtype, N), rand(dtype, N))
34+
Y = copyto!(KernelAbstractions.zeros(backend, dtype, N), rand(dtype, N))
3535
end
3636
workgroup_size = 1024
3737

examples/performance.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ for block_dims in ((TILE_DIM, TILE_DIM), (TILE_DIM * TILE_DIM, 1), (1, TILE_DIM
145145
("transpose", simple_transpose_kernel!(backend, block_dims)),
146146
)
147147
NVTX.@range "Simple $name $block_dims" let
148-
input = rand!(allocate(backend, T, N, N))
148+
input = copyto!(allocate(backend, T, N, N), rand(T, N, N))
149149
output = similar(input)
150150

151151
# compile kernel
@@ -165,7 +165,7 @@ for (name, kernel) in (
165165
)
166166
for bank in (true, false)
167167
NVTX.@range "Localmem $name ($TILE_DIM, $TILE_DIM) bank=$bank" let
168-
input = rand!(allocate(backend, T, N, N))
168+
input = copyto!(allocate(backend, T, N, N), rand(T, N, N))
169169
output = similar(input)
170170

171171
# compile kernel
@@ -185,7 +185,7 @@ for (name, kernel) in (
185185
)
186186
for bank in (true, false)
187187
NVTX.@range "Localmem + multiple elements $name ($TILE_DIM, $BLOCK_ROWS) bank=$bank" let
188-
input = rand!(allocate(backend, T, N, N))
188+
input = copyto!(allocate(backend, T, N, N), rand(T, N, N))
189189
output = similar(input)
190190

191191
# We want a number of blocks equivalent to (TILE_DIM, TILE_DIM)

examples/performant_matmul.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ end
7878
N = 1024
7979
R = 512
8080
M = 2048
81-
A = rand!(allocate(backend, Float32, N, R))
82-
B = rand!(allocate(backend, Float32, R, M))
81+
A = copyto!(allocate(backend, Float32, N, R), rand(Float32, N, R))
82+
B = copyto!(allocate(backend, Float32, R, M), rand(Float32, R, M))
8383
C = KernelAbstractions.zeros(backend, Float32, N, M)
8484

8585
kern = coalesced_matmul_kernel!(backend, (TILE_DIM, TILE_DIM))

0 commit comments

Comments
 (0)