Skip to content
Merged
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
2 changes: 1 addition & 1 deletion test/generic/accumulate.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ALGS = AK.AccumulateAlgorithm[AK.ScanPrefixes()]

@isdefined(TEST_DL) && TEST_DL[] && push!(ALGS, AK.DecoupledLookback())
TEST_DL && push!(ALGS, AK.DecoupledLookback())

@testset "accumulate_1d $(alg isa AK.DecoupledLookback ? "DL" : "SP")" for alg in ALGS

Expand Down
24 changes: 12 additions & 12 deletions test/generic/binarysearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

vh = Array(v)
xh = Array(x)
ixh = AK.searchsortedfirst(vh, xh; prefer_threads)
ixh = AK.searchsortedfirst(vh, xh; prefer_threads=true)
ixh_base = [searchsortedfirst(vh, e) for e in xh]

@test all(Array(ix) .== ixh .== ixh_base)
Expand All @@ -28,7 +28,7 @@

vh = Array(v)
xh = Array(x)
ixh = AK.searchsortedfirst(vh, xh; prefer_threads)
ixh = AK.searchsortedfirst(vh, xh; prefer_threads=true)
ixh_base = [searchsortedfirst(vh, e) for e in xh]

@test all(Array(ix) .== ixh .== ixh_base)
Expand All @@ -47,7 +47,7 @@

vh = Array(v)
xh = Array(x)
ixh = AK.searchsortedlast(vh, xh; prefer_threads)
ixh = AK.searchsortedlast(vh, xh; prefer_threads=true)
ixh_base = [searchsortedlast(vh, e) for e in xh]

@test all(Array(ix) .== ixh .== ixh_base)
Expand All @@ -60,7 +60,7 @@

vh = Array(v)
xh = Array(x)
ixh = AK.searchsortedlast(vh, xh; prefer_threads)
ixh = AK.searchsortedlast(vh, xh; prefer_threads=true)
ixh_base = [searchsortedlast(vh, e) for e in xh]

@test all(Array(ix) .== ixh .== ixh_base)
Expand All @@ -80,14 +80,14 @@
xh = Array(x)
ixh = similar(xh, Int32)

AK.searchsortedfirst!(ixh, vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedfirst(vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedlast!(ixh, vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedlast(vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedfirst!(ixh, vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedfirst(vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedlast!(ixh, vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)
AK.searchsortedlast(vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100)

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.searchsortedfirst!(ixh, vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedfirst(vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedlast!(ixh, vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedlast(vh, xh; prefer_threads, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedfirst!(ixh, vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedfirst(vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedlast!(ixh, vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
@test_throws MethodError AK.searchsortedlast(vh, xh; prefer_threads=true, by=abs, lt=(>), rev=true, max_tasks=10, min_elems=100, bad=:kwarg)
end
2 changes: 1 addition & 1 deletion test/generic/looping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Random.seed!(0)

# CPU
if IS_CPU_BACKEND && prefer_threads
if prefer_threads
x = zeros(Int, 1000)
AK.foreachindex(x; prefer_threads) do i
x[i] = i
Expand Down
65 changes: 21 additions & 44 deletions test/generic/map.jl
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
@testset "map" begin
Random.seed!(0)

# CPU
if IS_CPU_BACKEND && prefer_threads
x = Array(1:1000)
y = AK.map(x; prefer_threads) do i
i^2
end
@test y == map(i -> i^2, x)
x = array_from_host(1:1000)
y = AK.map(x; prefer_threads) do i
i^2
end
@test Array(y) == map(i -> i^2, 1:1000)

x = Array(1:1000)
y = zeros(Int, 1000)
AK.map!(y, x; prefer_threads) do i
i^2
end
@test y == map(i -> i^2, x)
x = array_from_host(1:1000)
y = array_from_host(zeros(Int, 1000))
AK.map!(y, x; prefer_threads) do i
i^2
end
@test Array(y) == map(i -> i^2, 1:1000)

x = rand(Float32, 1000)
y = AK.map(x; prefer_threads, max_tasks=2, min_elems=100) do i
i > 0.5 ? i : 0
end
@test y == map(i -> i > 0.5 ? i : 0, x)
x = array_from_host(rand(Float32, 1000))
# Tests different things with GPU and CPU backends as well as irrelevant parameters being ignored
y = AK.map(x; prefer_threads, block_size=64, max_tasks=2, min_elems=100) do i
i > 0.5 ? i : 0
end
@test Array(y) == map(i -> i > 0.5 ? i : 0, Array(x))

if prefer_threads # CPU only
x = rand(Float32, 1000)
y = AK.map(x; prefer_threads, max_tasks=4, min_elems=500) do i
i > 0.5 ? i : 0
end
@test y == map(i -> i > 0.5 ? i : 0, x)

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.map(x -> x^2, x; prefer_threads, bad=:kwarg)
# GPU
else
x = array_from_host(1:1000)
y = AK.map(x; prefer_threads) do i
i^2
end
@test Array(y) == map(i -> i^2, 1:1000)

x = array_from_host(1:1000)
y = array_from_host(zeros(Int, 1000))
AK.map!(y, x; prefer_threads) do i
i^2
end
@test Array(y) == map(i -> i^2, 1:1000)

x = array_from_host(rand(Float32, 1000))
y = AK.map(x; prefer_threads, block_size=64) do i
i > 0.5 ? i : 0
end
@test Array(y) == map(i -> i > 0.5 ? i : 0, Array(x))

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.map(x -> x^2, x; prefer_threads, bad=:kwarg)
end

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.map(x -> x^2, x; prefer_threads, bad=:kwarg)
end
32 changes: 16 additions & 16 deletions test/generic/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Base.zero(::Type{Point}) = Point(0.0f0, 0.0f0)

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.reduce(+, array_from_host(rand(Int32, 10)); init=10, bad=:kwarg)
if !IS_CPU_BACKEND
if !prefer_threads
@test_throws ArgumentError AK.reduce(+, array_from_host(rand(Int32, 256)); prefer_threads, init=Int32(0), block_size=192)
end

Expand All @@ -150,7 +150,7 @@ Base.zero(::Type{Point}) = Point(0.0f0, 0.0f0)
)
AK.reduce(
(x, y) -> x + 1,
rand(Int32, 10_000);
array_from_host(rand(Int32, 10_000));
prefer_threads,
init=Int32(0),
neutral=Int64(0),
Expand Down Expand Up @@ -279,7 +279,7 @@ end
sum(vh; init=Int32(0), dims)
end

if IS_CPU_BACKEND
if prefer_threads
# The CPU fallback should not require strided storage.
vh = reshape(1:12, 1, 3, 4)
@test Array(AK.reduce(+, vh, BACKEND; prefer_threads, init=0, dims=(1,2))) ==
Expand All @@ -302,7 +302,7 @@ end

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.reduce(+, array_from_host(rand(Int32, 10, 10)); prefer_threads, init=10, bad=:kwarg)
if !IS_CPU_BACKEND
if !prefer_threads
@test_throws ArgumentError AK.reduce(+, array_from_host(rand(Int32, 16, 16)); prefer_threads, init=Int32(0), dims=1, block_size=192)
end

Expand Down Expand Up @@ -339,7 +339,7 @@ end
@testset "mapreduce_1d" begin
Random.seed!(0)

function minbox(s)
function minbox(s; prefer_threads)
# Extract coordinates into tuple and reduce to find dimensionwise minima
AK.mapreduce(
p -> (p.x, p.y),
Expand All @@ -365,10 +365,10 @@ end
for _ in 1:1000
num_elems = rand(1:100_000)
v = array_from_host([Point(rand(Float32), rand(Float32)) for _ in 1:num_elems])
mgpu = minbox(v)
mgpu = minbox(v; prefer_threads)

vh = Array(v)
mcpu = minbox(vh)
mcpu = minbox(vh; prefer_threads=true)
mbase = minbox_base(vh)

@test typeof(mgpu) === typeof(mcpu) === typeof(mbase)
Expand All @@ -383,10 +383,10 @@ end
n3 = rand(1:100)

v = array_from_host([Point(rand(Float32), rand(Float32)) for _ in 1:n1, _ in 1:n2, _ in 1:n3])
mgpu = minbox(v)
mgpu = minbox(v; prefer_threads)

vh = Array(v)
mcpu = minbox(vh)
mcpu = minbox(vh; prefer_threads=true)
mbase = minbox_base(vh)

@test typeof(mgpu) === typeof(mcpu) === typeof(mbase)
Expand Down Expand Up @@ -483,7 +483,7 @@ end
init=Int32(0),
)

if IS_CPU_BACKEND
if prefer_threads
bc = Base.Broadcast.instantiate(Base.Broadcast.broadcasted(+, reshape(1:6, 2, 3), reshape(10:15, 2, 3)))
@test AK.mapreduce(identity, +, bc; prefer_threads, init=0) ==
mapreduce(identity, +, bc; init=0)
Expand Down Expand Up @@ -513,7 +513,7 @@ end

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.mapreduce(-, +, v; prefer_threads, init=10, bad=:kwarg)
if !IS_CPU_BACKEND
if !prefer_threads
@test_throws ArgumentError AK.mapreduce(-, +, array_from_host(rand(Int32, 256)); prefer_threads, init=Int32(0), block_size=192)
end
end
Expand Down Expand Up @@ -552,7 +552,7 @@ end
end
end

function minbox(s, dims)
function minbox(s, dims; prefer_threads)
# Extract coordinates into tuple and reduce to find dimensionwise minima
AK.mapreduce(
p -> (p.x, p.y),
Expand Down Expand Up @@ -583,10 +583,10 @@ end
n2 = rand(1:100)
n3 = rand(1:100)
v = array_from_host([Point(rand(Float32), rand(Float32)) for _ in 1:n1, _ in 1:n2, _ in 1:n3])
mgpu = minbox(v, dims)
mgpu = minbox(v, dims; prefer_threads)

vh = Array(v)
mcpu = minbox(vh, dims)
mcpu = minbox(vh, dims; prefer_threads=true)
mbase = minbox_base(vh, dims)

@test eltype(mgpu) === eltype(mcpu) === eltype(mbase)
Expand Down Expand Up @@ -679,7 +679,7 @@ end
mapreduce(x -> x - Int32(1), +, vh; init=Int32(0), dims)
end

if IS_CPU_BACKEND
if prefer_threads
# The CPU fallback should not require strided storage.
vh = reshape(1:12, 1, 3, 4)
@test Array(AK.mapreduce(x -> 2x, +, vh, BACKEND; prefer_threads, init=0, dims=(1,2))) ==
Expand All @@ -700,7 +700,7 @@ end

# Test that undefined kwargs are not accepted
@test_throws MethodError AK.mapreduce(-, +, array_from_host(rand(Int32, 3, 4, 5)); prefer_threads, init=10, bad=:kwarg)
if !IS_CPU_BACKEND
if !prefer_threads
@test_throws ArgumentError AK.mapreduce(-, +, array_from_host(rand(Int32, 16, 16)); prefer_threads, init=Int32(0), dims=1, block_size=192)
end

Expand Down
14 changes: 7 additions & 7 deletions test/generic/sort.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
@testset "merge_sort" begin
Random.seed!(0)

Expand Down Expand Up @@ -229,7 +229,7 @@ end
issorted(vh[ixh]; kwargs...)
end

if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
for T in filter(T -> T !== Float64 || KernelAbstractions.supports_float64(BACKEND),
(UInt32, Int32, Float32, UInt64, Int64, Float64))
v_h = rand(T, 10_000)
Expand Down Expand Up @@ -277,7 +277,7 @@ end
end


if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
@testset "merge_sort_by_key" begin
Random.seed!(0)

Expand Down Expand Up @@ -359,7 +359,7 @@ end
end


if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
@testset "merge_sortperm" begin
Random.seed!(0)

Expand Down Expand Up @@ -468,7 +468,7 @@ end
end


if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
@testset "merge_sortperm_lowmem" begin
Random.seed!(0)

Expand Down Expand Up @@ -586,7 +586,7 @@ end
end


if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
@testset "sortperm_extended" begin
# Helper: ix is a valid permutation of 1:n that produces a sorted order
function is_valid_perm(vh, ixh; kwargs...)
Expand Down Expand Up @@ -698,7 +698,7 @@ if !IS_CPU_BACKEND || !prefer_threads
end

@testset "radix_sort_alg" begin
if !IS_CPU_BACKEND || !prefer_threads
if !prefer_threads
Random.seed!(0)

# ── Correctness: fuzzy testing across supported types ─────────────────
Expand Down
Loading
Loading