Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

thrust::sort assigns to uninitialized objects #1106

Closed as not planned
Closed as not planned

Description

@dkolsen-pgi

Test program:

#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

  1. added this to the 1.13.0 milestone on Mar 9, 2021
  2. added
    compiler: nvc++
    on Mar 9, 2021
  3. brycelelbach commented on Mar 9, 2021

    @brycelelbach
    Contributor

    This is FS 28362

  4. added
    P1: should have
    nvc++ flyspray
    on Mar 29, 2021
  5. changed the title [-]thrust::sort() assigns to uninitialized objects[/-] [+]thrust::sort assigns to uninitialized objects[/+] on Mar 29, 2021
  6. modified the milestones: 1.13.0, 1.14.0 on Jun 9, 2021
  7. modified the milestones: 1.14.0, 1.15.0 on Aug 17, 2021
  8. modified the milestones: 1.15.0, 1.16.0 on Oct 15, 2021
  9. modified the milestones: 1.16.0, 1.17.0 on Feb 7, 2022
  10. removed their assignment
    on Apr 25, 2022
  11. modified the milestones: 1.17.0, Backlog on Apr 25, 2022
  12. jrhemstad commented on Feb 24, 2023

    @jrhemstad
    Collaborator

    Closing in favor of NVIDIA/cccl#734 which is more general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1: should havecompiler: nvc++nvc++ flyspraythrust

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions