Skip to content

Commit 3ce338b

Browse files
authored
Merge pull request #45 from arhik/main
update examples
2 parents 2f8c002 + ca04055 commit 3ce338b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

examples/elemwise.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
using Test
12
using WGPUCompute
23
using WGPUCompute: elwise
34
x = WgpuArray{Float32, 2}(rand(16, 16))
45
y = elwise(+, x, x)
6+
7+
x_cpu = x |> collect
8+
z_cpu = 2.0f0.*x_cpu
9+
10+
@test z_cpu (y |> collect)

src/array.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ function unsafe_fill!(gpuDevice, dst::WgpuArrayPtr{T}, value::Union{UInt8, Int8}
163163
WGPUCore.writeBuffer(gpuDevice.queue, dst.buffer, fill(value, N))
164164
end
165165

166-
167166
mutable struct WgpuArray{T, N} <: AbstractGPUArray{T, N}
168167
dims::Dims{N}
169168
storageData::Union{Nothing, Vector{T}, Array{T}}

src/ops/elemwise.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function broadcast_kernel(op::Function, x::WgpuArray{T, N}, y::WgpuArray{T, N},
88
out[gId] = op(x[gId], y[gId])
99
end
1010

11-
function broadcast_kernel(op::Function, x::WgpuArray{T, N}, y::Number, out::WgpuArray{T, N}) where {T, N}
11+
function broadcast_kernel(op::Function, x::WgpuArray{T, N}, y::Float32, out::WgpuArray{T, N}) where {T, N}
1212
xdim = workgroupDims.x
1313
ydim = workgroupDims.y
1414
gIdx = workgroupId.x*xdim + localId.x
@@ -44,15 +44,15 @@ function elwise(f::Function, a::Number, b::WgpuArray{T, N}) where {T, N}
4444
return out
4545
end
4646

47-
# Base.:+(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(+, a, b)
48-
# Base.:-(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(-, a, b)
49-
# Base.:*(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(*, a, b)
50-
# Base.:/(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(/, a, b)
51-
# Base.:+(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(+, a, b)
52-
# Base.:-(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(-, a, b)
53-
# Base.:*(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(*, a, b)
54-
# Base.:/(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(/, a, b)
55-
# Base.:+(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(+, a, b)
56-
# Base.:-(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(-, a, b)
57-
# Base.:*(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(*, a, b)
58-
# Base.:/(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(/, a, b)
47+
Base.:+(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(+, a, b)
48+
Base.:-(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(-, a, b)
49+
Base.:*(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(*, a, b)
50+
Base.:/(a::WgpuArray{T, N}, b::WgpuArray{T, N}) where {T, N} = elwise(/, a, b)
51+
Base.:+(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(+, a, b)
52+
Base.:-(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(-, a, b)
53+
Base.:*(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(*, a, b)
54+
Base.:/(a::WgpuArray{T, N}, b::Number) where {T, N} = elwise(/, a, b)
55+
Base.:+(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(+, a, b)
56+
Base.:-(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(-, a, b)
57+
Base.:*(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(*, a, b)
58+
Base.:/(a::Number, b::WgpuArray{T, N}) where {T, N} = elwise(/, a, b)

0 commit comments

Comments
 (0)