Skip to content
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

sortperm with dims #2308

Merged
merged 9 commits into from
Apr 9, 2024
Merged

sortperm with dims #2308

merged 9 commits into from
Apr 9, 2024

Conversation

xaellison
Copy link
Contributor

@xaellison xaellison commented Mar 31, 2024

Adds sortperm with dims kwarg (and bitonicsort with dims) to solve #2061

@xaellison xaellison marked this pull request as ready for review April 1, 2024 03:04
return extraneous_block(vals[1], dims)
end

# methods are defined for Val{1} because using view has 2x speed penalty for 1D arrays
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably speed up view by returning a CuDeviceArray when possible, just like we do with CuArray

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting a change here or is this an idea for a separate change in the repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate change.

@maleadt
Copy link
Member

maleadt commented Apr 1, 2024

Nice! So we only use quicksort now for partialsort!?

@xaellison
Copy link
Contributor Author

Nice! So we only use quicksort now for partialsort!?

That's right. However, some preliminary benchmarking suggests bitonic sort is faster than partialsort for comparable input. Maybe we want to use bitonic for everything? This would also let us add methods for partialsortperm (even though they would just be doing a full sortperm)

@maleadt
Copy link
Member

maleadt commented Apr 2, 2024

Maybe we want to use bitonic for everything?

I'd be in favor, also because I haven't implemented the new version of dynamic parallelism yet.

@xaellison xaellison requested a review from maleadt April 8, 2024 12:08
src/sorting.jl Outdated Show resolved Hide resolved
Copy link
Member

@maleadt maleadt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

src/sorting.jl Outdated Show resolved Hide resolved
@maleadt maleadt added enhancement New feature or request cuda array Stuff about CuArray. labels Apr 9, 2024
@maleadt maleadt linked an issue Apr 9, 2024 that may be closed by this pull request
@maleadt maleadt merged commit b3e1bdf into JuliaGPU:master Apr 9, 2024
1 check was pending
@maleadt
Copy link
Member

maleadt commented Apr 16, 2024

Some of the kernel launches added here exceed device resources, e.g., during this CI run: https://buildkite.com/julialang/cuda-dot-jl/builds/4942#018ee5fc-7926-4b0a-a855-11039bda2b72

base/sorting: Error During Test at /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:313
  Test threw exception
  Expression: check_sort!(Int32, (2, 2, 50000); dims = 3, rev = true)
  CUDA error: too many resources requested for launch (code 701, ERROR_LAUNCH_OUT_OF_RESOURCES)
  Stacktrace:
    [1] throw_api_error(res::CUDA.cudaError_enum)
      @ CUDA /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/libcuda.jl:30
    [2] check
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/libcuda.jl:37 [inlined]
    [3] cuLaunchKernel
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/utils/call.jl:30 [inlined]
    [4] #930
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:66 [inlined]
    [5] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:33 [inlined]
    [6] macro expansion
      @ ./none:0 [inlined]
    [7] pack_arguments(::CUDA.var"#930#931"{Bool, Int64, CuStream, CuFunction, CuDim3, CuDim3}, ::CUDA.KernelState, ::CuDeviceArray{Int32, 3, 1}, ::Int32, ::Int32, ::Int32, ::Int32)
      @ CUDA ./none:0
    [8] launch(::CuFunction, ::CUDA.KernelState, ::CuDeviceArray{Int32, 3, 1}, ::Int32, ::Int32, ::Int32, ::Int32; blocks::Tuple{Int64, Int64, Int64}, threads::Tuple{Int64, Int64}, cooperative::Bool, shmem::Int64, stream::CuStream)
      @ CUDA /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:59
    [9] launch
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:52 [inlined]
   [10] #936
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:175 [inlined]
   [11] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:135 [inlined]
   [12] macro expansion
      @ ./none:0 [inlined]
   [13] convert_arguments
      @ ./none:0 [inlined]
   [14] #cudacall#935
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:177 [inlined]
   [15] cudacall
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/lib/cudadrv/execution.jl:173 [inlined]
   [16] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/compiler/execution.jl:266 [inlined]
   [17] macro expansion
      @ ./none:0 [inlined]
   [18] call(::CUDA.HostKernel{typeof(CUDA.BitonicSortImpl.comparator_small_kernel), Tuple{CuDeviceArray{Int32, 3, 1}, Int32, Int32, Int32, Int32, typeof(identity), typeof(isless), Val{true}, Val{3}}}, ::CuDeviceArray{Int32, 3, 1}, ::Int32, ::Int32, ::Int32, ::Int32, ::typeof(identity), ::typeof(isless), ::Val{true}, ::Val{3}; call_kwargs::@Kwargs{threads::Tuple{Int64, Int64}, blocks::Tuple{Int64, Int64, Int64}, shmem::Int64})
      @ CUDA ./none:0
   [19] call
      @ ./none:0 [inlined]
   [20] (::CUDA.HostKernel{typeof(CUDA.BitonicSortImpl.comparator_small_kernel), Tuple{CuDeviceArray{Int32, 3, 1}, Int32, Int32, Int32, Int32, typeof(identity), typeof(isless), Val{true}, Val{3}}})(::CuArray{Int32, 3, CUDA.Mem.DeviceBuffer}, ::Int32, ::Int32, ::Int32, ::Int32, ::Function, ::Function, ::Val{true}, ::Val{3}; threads::Tuple{Int64, Int64}, blocks::Tuple{Int64, Int64, Int64}, kwargs::@Kwargs{shmem::Int64})
      @ CUDA /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/compiler/execution.jl:389
   [21] bitonic_sort!(c::CuArray{Int32, 3, CUDA.Mem.DeviceBuffer}; by::Function, lt::Function, rev::Bool, dims::Int64)
      @ CUDA.BitonicSortImpl /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/sorting.jl:948
   [22] bitonic_sort!
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/sorting.jl:902 [inlined]
   [23] #sort!#1224
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/sorting.jl:988 [inlined]
   [24] sort!
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/sorting.jl:987 [inlined]
   [25] #sort!#1225
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/src/sorting.jl:992 [inlined]
   [26] check_sort!(T::Type, N::Tuple{Int64, Int64, Int64}, f::Function; kwargs::@Kwargs{dims::Int64, rev::Bool})
      @ Main /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:198
   [27] check_sort!
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:196 [inlined]
   [28] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:313 [inlined]
   [29] macro expansion
      @ ~/.cache/julia-buildkite-plugin/julia_installs/bin/linux/x64/1.10/julia-1.10-latest-linux-x86_64/share/julia/stdlib/v1.10/Test/src/Test.jl:669 [inlined]
   [30] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:313 [inlined]
   [31] macro expansion
      @ ~/.cache/julia-buildkite-plugin/julia_installs/bin/linux/x64/1.10/julia-1.10-latest-linux-x86_64/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
   [32] macro expansion
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:283 [inlined]
   [33] macro expansion
      @ ~/.cache/julia-buildkite-plugin/julia_installs/bin/linux/x64/1.10/julia-1.10-latest-linux-x86_64/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
   [34] top-level scope
      @ /var/lib/buildkite-agent/builds/gpuci-16/julialang/cuda-dot-jl/test/base/sorting.jl:281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sortperm fails with dims keyword
2 participants