static_assert that the iterator passed to `sort_by_key` is mutable
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
CUDA 11.6
``` c++
#include
#include
#include
void test_thrust_sort() {
using Pair = thrust::pair;
thrust::device_vector vec(320 * 100, 0.0f);
thrust::sequence(vec.begin(), vec.end(), 0.0);
thrust::shuffle(thrust::device, vec.begin(), vec.end(), thrust::default_random_engine(0));
auto p_vec = vec.data();
auto it = thrust::make_transform_iterator(
thrust::make_counting_iterator(0ul),
[=] __device__ __host__(size_t i) -> Pair { return thrust::make_pair(i % 100, p_vec[i]); });
auto op = [=] __host__ __device__(Pair const& le, Pair const& re) {
if (le.first != re.first) {
return le.first < re.first;
}
return le.second < re.second;
};
thrust::device_vector sorted_idx(vec.size());
thrust::sequence(sorted_idx.begin(), sorted_idx.end(), 0ul);
thrust::sort_by_key(thrust::device, it, it + vec.size(), sorted_idx.begin(), op);
}
int main() {
test_thrust_sort();
return 0;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.