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.

CPU->GPU copy of a default-initialized vector [windows/vs2019] #1275

@mfoco

Description

@mfoco

In Windows, with VS2019 16.7.2 (debug mode) and the default thrust provided with CUDA 11 package, I found this problem:

int main()
{
    thrust::device_vector<int> gpu;
    std::vector<int> cpu;
    gpu = cpu; // assertion in debug
}

The code triggers an assertion in vector:46 (standard vector header, provided by Microsoft) coming from thrust/system/cuda/detail/internal/copy_cross_system.h:106 (it's inside the function cross_system_copy_n, and the assert is triggering because the code is dereferencing the begin() iterator, which is invalid (being the vector empty), and more specifically is nullptr (being uninitialized).

The problem disappears if the gpu vector is allocated (e.g. by pushing back and clearing) before the assignment:

#include <thrust/device_vector.h>

int main()
{
    thrust::device_vector<int> gpu;
    std::vector<int> cpu;
    gpu.push_back(1);
    gpu.clear();
    gpu = cpu; // works! (actually, the CUDA11 version triggers a different assertion, but that has been fixed already)
}

I think this might be loosely related to #938 and #939 .

The other assertion I mentioned above has been fixed by @allisonvacanti here (b9a2073)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions