|
169 | 169 | """
|
170 | 170 | Tests if `c` is a valid sort of `a`
|
171 | 171 | """
|
172 |
| -function check_equivalence(a::Vector, c::Vector; kwargs...) |
| 172 | +function check_equivalence(a::Vector, c::Vector; alg=nothing, kwargs...) |
173 | 173 | counter(a) == counter(c) && issorted(c; kwargs...)
|
174 | 174 | end
|
175 | 175 |
|
@@ -281,58 +281,86 @@ end
|
281 | 281 | end
|
282 | 282 |
|
283 | 283 | @testset "interface" begin
|
| 284 | +@testset "quicksort" begin |
284 | 285 | # pre-sorted
|
285 |
| - @test check_sort!(Int, 1000000) |
286 |
| - @test check_sort!(Int32, 1000000) |
287 |
| - @test check_sort!(Float64, 1000000) |
288 |
| - @test check_sort!(Float32, 1000000) |
| 286 | + @test check_sort!(Int, 1000000; alg=CuQuickSort) |
| 287 | + @test check_sort!(Int32, 1000000; alg=CuQuickSort) |
| 288 | + @test check_sort!(Float64, 1000000; alg=CuQuickSort) |
| 289 | + @test check_sort!(Float32, 1000000; alg=CuQuickSort) |
289 | 290 | @test check_sort!(Int32, 1000000; rev=true)
|
290 | 291 | @test check_sort!(Float32, 1000000; rev=true)
|
291 | 292 |
|
292 | 293 | # reverse sorted
|
293 |
| - @test check_sort!(Int32, 1000000, x -> -x) |
294 |
| - @test check_sort!(Float32, 1000000, x -> -x) |
295 |
| - @test check_sort!(Int32, 1000000, x -> -x; rev=true) |
296 |
| - @test check_sort!(Float32, 1000000, x -> -x; rev=true) |
297 |
| - |
298 |
| - @test check_sort!(Int, 10000, x -> rand(Int)) |
299 |
| - @test check_sort!(Int32, 10000, x -> rand(Int32)) |
300 |
| - @test check_sort!(Int8, 10000, x -> rand(Int8)) |
301 |
| - @test check_sort!(Float64, 10000, x -> rand(Float64)) |
302 |
| - @test check_sort!(Float32, 10000, x -> rand(Float32)) |
303 |
| - @test check_sort!(Float16, 10000, x -> rand(Float16)) |
| 294 | + @test check_sort!(Int32, 1000000, x -> -x; alg=CuQuickSort) |
| 295 | + @test check_sort!(Float32, 1000000, x -> -x; alg=CuQuickSort) |
| 296 | + @test check_sort!(Int32, 1000000, x -> -x; rev=true, alg=CuQuickSort) |
| 297 | + @test check_sort!(Float32, 1000000, x -> -x; rev=true, alg=CuQuickSort) |
| 298 | + |
| 299 | + @test check_sort!(Int, 10000, x -> rand(Int); alg=CuQuickSort) |
| 300 | + @test check_sort!(Int32, 10000, x -> rand(Int32); alg=CuQuickSort) |
| 301 | + @test check_sort!(Int8, 10000, x -> rand(Int8); alg=CuQuickSort) |
| 302 | + @test check_sort!(Float64, 10000, x -> rand(Float64); alg=CuQuickSort) |
| 303 | + @test check_sort!(Float32, 10000, x -> rand(Float32); alg=CuQuickSort) |
| 304 | + @test check_sort!(Float16, 10000, x -> rand(Float16); alg=CuQuickSort) |
304 | 305 |
|
305 | 306 | # non-uniform distributions
|
306 |
| - @test check_sort!(UInt8, 100000, x -> round(255 * rand() ^ 2)) |
307 |
| - @test check_sort!(UInt8, 100000, x -> round(255 * rand() ^ 3)) |
| 307 | + @test check_sort!(UInt8, 100000, x -> round(255 * rand() ^ 2); alg=CuQuickSort) |
| 308 | + @test check_sort!(UInt8, 100000, x -> round(255 * rand() ^ 3); alg=CuQuickSort) |
308 | 309 |
|
309 | 310 | # more copies of each value than can fit in one block
|
310 |
| - @test check_sort!(Int8, 4000000, x -> rand(Int8)) |
| 311 | + @test check_sort!(Int8, 4000000, x -> rand(Int8); alg=CuQuickSort) |
311 | 312 |
|
312 | 313 | # multiple dimensions
|
313 | 314 | @test check_sort!(Int32, (4, 50000, 4); dims=2)
|
314 | 315 | @test check_sort!(Int32, (4, 4, 50000); dims=3, rev=true)
|
315 | 316 |
|
316 | 317 | # large sizes
|
317 |
| - @test check_sort!(Float32, 2^25) |
| 318 | + @test check_sort!(Float32, 2^25; alg=CuQuickSort) |
318 | 319 |
|
319 | 320 | # various sync depths
|
320 | 321 | for depth in 0:4
|
321 | 322 | CUDA.limit!(CUDA.LIMIT_DEV_RUNTIME_SYNC_DEPTH, depth)
|
322 |
| - @test check_sort!(Int, 100000, x -> rand(Int)) |
| 323 | + @test check_sort!(Int, 100000, x -> rand(Int); alg=CuQuickSort) |
323 | 324 | end
|
324 | 325 |
|
325 | 326 | # using a `by` argument
|
326 |
| - @test check_sort(Float32, 100000; by=x->abs(x - 0.5)) |
| 327 | + @test check_sort(Float32, 100000; by=x->abs(x - 0.5), alg=CuQuickSort) |
327 | 328 | @test check_sort!(Float32, (100000, 4); by=x->abs(x - 0.5), dims=1)
|
328 | 329 | @test check_sort!(Float32, (4, 100000); by=x->abs(x - 0.5), dims=2)
|
329 |
| - @test check_sort!(Float64, 400000; by=x->8*x-round(8*x)) |
| 330 | + @test check_sort!(Float64, 400000; by=x->8*x-round(8*x), alg=CuQuickSort) |
330 | 331 | @test check_sort!(Float64, (100000, 4); by=x->8*x-round(8*x), dims=1)
|
331 | 332 | @test check_sort!(Float64, (4, 100000); by=x->8*x-round(8*x), dims=2)
|
332 | 333 | # target bubble sort by using sub-blocksize input:
|
333 |
| - @test check_sort!(Int, 200; by=x->x % 2) |
334 |
| - @test check_sort!(Int, 200; by=x->x % 3) |
335 |
| - @test check_sort!(Int, 200; by=x->x % 4) |
| 334 | + @test check_sort!(Int, 200; by=x->x % 2, alg=CuQuickSort) |
| 335 | + @test check_sort!(Int, 200; by=x->x % 3, alg=CuQuickSort) |
| 336 | + @test check_sort!(Int, 200; by=x->x % 4, alg=CuQuickSort) |
| 337 | +end # end quicksort tests |
| 338 | + |
| 339 | +@testset "bitonic sort" begin |
| 340 | + # test various types |
| 341 | + @test check_sort!(Int, 10000, x -> rand(Int); alg=CuBitonicSort) |
| 342 | + @test check_sort!(Int32, 10000, x -> rand(Int32); alg=CuBitonicSort) |
| 343 | + @test check_sort!(Int8, 10000, x -> rand(Int8); alg=CuBitonicSort) |
| 344 | + @test check_sort!(Float64, 10000, x -> rand(Float64); alg=CuBitonicSort) |
| 345 | + @test check_sort!(Float32, 10000, x -> rand(Float32); alg=CuBitonicSort) |
| 346 | + @test check_sort!(Float16, 10000, x -> rand(Float16); alg=CuBitonicSort) |
| 347 | + |
| 348 | + # test various sizes |
| 349 | + @test check_sort!(Float32, 1, x -> rand(Float32); alg=CuBitonicSort) |
| 350 | + @test check_sort!(Float32, 2, x -> rand(Float32); alg=CuBitonicSort) |
| 351 | + @test check_sort!(Float32, 3, x -> rand(Float32); alg=CuBitonicSort) |
| 352 | + @test check_sort!(Float32, 4, x -> rand(Float32); alg=CuBitonicSort) |
| 353 | + @test check_sort!(Float32, 1 << 16 + 0, x -> rand(Float32); alg=CuBitonicSort) |
| 354 | + @test check_sort!(Float32, 1 << 16 + 1, x -> rand(Float32); alg=CuBitonicSort) |
| 355 | + @test check_sort!(Float32, 1 << 16 + 31, x -> rand(Float32); alg=CuBitonicSort) |
| 356 | + @test check_sort!(Float32, 1 << 16 + 32, x -> rand(Float32); alg=CuBitonicSort) |
| 357 | + @test check_sort!(Float32, 1 << 16 + 33, x -> rand(Float32); alg=CuBitonicSort) |
| 358 | + @test check_sort!(Float32, 1 << 16 + 127, x -> rand(Float32); alg=CuBitonicSort) |
| 359 | + @test check_sort!(Float32, 1 << 16 + 128, x -> rand(Float32); alg=CuBitonicSort) |
| 360 | + @test check_sort!(Float32, 1 << 16 + 129, x -> rand(Float32); alg=CuBitonicSort) |
| 361 | +end # end bitonic tests |
| 362 | + |
| 363 | + @test_throws MethodError check_sort!(Int, (100, 100); alg=CuBitonicSort, dims=1) |
336 | 364 |
|
337 | 365 | #partial sort
|
338 | 366 | @test check_partialsort!(Int, 100000, 1)
|
|
0 commit comments