Skip to content

Commit d1bee3f

Browse files
Putting output before input in function arguments in some examples (#475)
1 parent c5fe83c commit d1bee3f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

examples/matmul.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@ using KernelAbstractions, Test, Random
22
include(joinpath(dirname(pathof(KernelAbstractions)), "../examples/utils.jl")) # Load backend
33

44
# Simple kernel for matrix multiplication
5-
@kernel function matmul_kernel!(a, b, c)
5+
@kernel function matmul_kernel!(output, a, b)
66
i, j = @index(Global, NTuple)
77

88
# creating a temporary sum variable for matrix multiplication
9-
tmp_sum = zero(eltype(c))
9+
tmp_sum = zero(eltype(output))
1010
for k = 1:size(a)[2]
1111
tmp_sum += a[i,k] * b[k, j]
1212
end
1313

14-
c[i,j] = tmp_sum
14+
output[i,j] = tmp_sum
1515
end
1616

1717
# Creating a wrapper kernel for launching with error checks
18-
function matmul!(a, b, c)
18+
function matmul!(output, a, b)
1919
if size(a)[2] != size(b)[1]
2020
println("Matrix size mismatch!")
2121
return nothing
2222
end
2323
backend = KernelAbstractions.get_backend(a)
2424
kernel! = matmul_kernel!(backend)
25-
kernel!(a, b, c, ndrange=size(c))
25+
kernel!(output, a, b, ndrange=size(output))
2626
end
2727

2828
a = rand!(allocate(backend, Float32, 256, 123))
2929
b = rand!(allocate(backend, Float32, 123, 45))
30-
c = KernelAbstractions.zeros(backend, Float32, 256, 45)
30+
output = KernelAbstractions.zeros(backend, Float32, 256, 45)
3131

32-
matmul!(a,b,c)
32+
matmul!(output, a,b)
3333
KernelAbstractions.synchronize(backend)
3434

35-
@test isapprox(c, a*b)
35+
@test isapprox(output, a*b)

examples/naive_transpose.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(joinpath(dirname(pathof(KernelAbstractions)), "../examples/utils.jl")) #
33

44
@kernel function naive_transpose_kernel!(a, b)
55
i, j = @index(Global, NTuple)
6-
@inbounds b[i, j] = a[j, i]
6+
@inbounds a[i, j] = b[j, i]
77
end
88

99
# create wrapper function to check inputs
@@ -24,8 +24,8 @@ end
2424
res = 1024
2525

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

3030
naive_transpose!(a,b)
3131
KernelAbstractions.synchronize(backend)

0 commit comments

Comments
 (0)