Skip to content

reduce doesn't query src backend if backend specified #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/reduce/mapreduce_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ function mapreduce_1d(
blocks = (len + num_per_block - 1) ÷ num_per_block

if !isnothing(temp)
@argcheck get_backend(temp) === get_backend(src)
@argcheck get_backend(temp) === backend
@argcheck eltype(temp) === typeof(init)
@argcheck length(temp) >= blocks * 2
dst = temp
else
# Figure out type for destination
dst_type = typeof(init)
dst = similar(src, dst_type, blocks * 2)
dst = KernelAbstractions.allocate(backend, dst_type, blocks * 2)
end

# Later the kernel will be compiled for views anyways, so use same types
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AcceleratedKernels as AK
using KernelAbstractions
using Test
using Random
using MappedArrays
import Pkg


Expand Down Expand Up @@ -756,6 +757,12 @@ end
max_tasks=16,
min_elems=1000,
)

# Range input
@test AK.sum(1234:100_000, backend) == sum(1234:100000)

# MappedArrays input
@test AK.sum(mappedarray(x->x*x, 1234:100_000), backend) == sum(x->x*x, 1234:100000)
end


Expand All @@ -778,6 +785,7 @@ end
end
end


# Fuzzy correctness testing
for _ in 1:100
for dims in 1:3
Expand Down Expand Up @@ -964,6 +972,12 @@ end
v = array_from_host([Point(rand(Float32), rand(Float32)) for _ in 1:10_042])
temp = similar(v, Tuple{Float32, Float32})
f(v, temp)

# Range input
@test AK.mapreduce(x->x*x, +, 1234:100_000, backend, init=Int64(10)) == sum(x->x*x, 1234:100000, init=Int64(10))

# MappedArrays input
@test AK.mapreduce(x->2*x, +, mappedarray(x->x*x, 1234:100_000), backend, init=Int64(10)) == sum(x->2*x*x, 1234:100000, init=Int64(10))
end


Expand Down