You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At sort.cu, we use gpu_sort() which performs a radix sort which could be inefficient(O(n log n)) compared to even our CPU backend where we use std::nth_element which is O(n).
We could use NVIDIA's RAFT library which already has an efficient top-k selection
The sort in sort.cu is a merge sort not a radix sort. Also a radix sort is not O(n log n)) but O(n) with a constant based on the bit width. For an efficient top-k (esp for half precision) a radix-based selection probably makes sense. Though we will have to play around with that.
The sort in sort.cu is a merge sort not a radix sort. Also a radix sort is not O(n log n)) but O(n) with a constant based on the bit width. For an efficient top-k (esp for half precision) a radix-based selection probably makes sense. Though we will have to play around with that.
Ah you are right, I was on an earlier commit where we were using CUB's radix sort. The problem then was we were doing full radix sort rather than Radix select. Also if I am not wrong right now we are at O(n log n))😅 . You are right radix sort is O(w.n).
Activity
NripeshN commentedon Jan 26, 2026
At sort.cu, we use gpu_sort() which performs a radix sort which could be inefficient(O(n log n)) compared to even our CPU backend where we use std::nth_element which is O(n).
We could use NVIDIA's RAFT library which already has an efficient top-k selection
awni commentedon Jan 26, 2026
The sort in
sort.cuis a merge sort not a radix sort. Also a radix sort is notO(n log n))butO(n)with a constant based on the bit width. For an efficient top-k (esp for half precision) a radix-based selection probably makes sense. Though we will have to play around with that.NripeshN commentedon Jan 27, 2026
Ah you are right, I was on an earlier commit where we were using CUB's radix sort. The problem then was we were doing full radix sort rather than Radix select. Also if I am not wrong right now we are at
O(n log n))😅 . You are right radix sort isO(w.n).Can I take on this issue?👉🏽👈🏽
awni commentedon Jan 27, 2026
Feel free to work on it!
awni commentedon Jan 27, 2026
A standalone MLX benchmark for various shape and type combinations: