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
{{ message }}
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
thrust::sort assigns to uninitialized objects #1106
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <stdio.h>
struct strict {
int value;
int state;
__host__ __device__ strict() : value(0), state(121212) { }
__host__ __device__ strict(int v) : value(v), state(121212) { }
__host__ __device__ strict(strict const& s) : value(s.value), state(121212) {}
__host__ __device__ strict& operator=(strict const& s) {
if (state != 121212) {
printf("copy assign into an uninitialized object\n");
thrust::cuda_cub::terminate();
}
value = s.value;
return *this;
}
};
__host__ __device__ bool operator==(strict const& a, strict const& b) {
return a.value == b.value;
}
__host__ __device__ bool operator<(strict const& a, strict const& b) {
return a.value < b.value;
}
#define N 40000
int main() {
thrust::host_vector<strict> hv;
for (int i = 0; i < N; ++i) {
hv.push_back(strict(N - i));
}
thrust::device_vector<strict> dv(hv);
thrust::sort(dv.begin(), dv.end());
}
When compiled nvcc (I tested both 10.1 and 11.0 EA) and run, the program prints a bunch of messages: copy assign into an uninitialized object
then crashes with:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): for_each: failed to synchronize: cudaErrorLaunchFailure: unspecified launch failure
Aborted
The problematic code is in cub/block/block_exchange.cuh, which creates a __shared__ array of the type being sorted, then uses the array without calling the constructor of the objects.
Activity
brycelelbach commentedon Mar 9, 2021
This is FS 28362
[-]thrust::sort() assigns to uninitialized objects[/-][+]thrust::sort assigns to uninitialized objects[/+]jrhemstad commentedon Feb 24, 2023
Closing in favor of NVIDIA/cccl#734 which is more general.