CUDA program calls device_vector resize with error of invalid device function

cuda testing program is as follows

#include <thrust/device_vector.h>
int main(void)
{
    try
    {
        thrust::device_vector<float> vec;
        vec.resize(6);
    }
    catch (thrust::system_error e)
    {
        std::cerr << "device_vector resize error: " << e.what() << std::endl;
        return -1;
    }

    return 0;
}

output window prints the following message

Exception thrown at 0x00007FFD8642CD29 in test.exe: Microsoft C++ exception: thrust::system::system_error at memory location 0x0000000A8D8FE0D0.
Exception thrown at 0x00007FFD8642CD29 in test.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFD8642CD29 in test.exe: Microsoft C++ exception: thrust::system::system_error at memory location 0x0000000A8D8FE0D0.
Unhandled exception at 0x00007FFD8642CD29 in test.exe: Microsoft C++ exception: thrust::system::system_error at memory location 0x0000000A8D8FE0D0.

console window prints the following message

CUDA error 8 [c:\program files\nvidia gpu computing toolkit\cuda\v10.0\include\thrust\system\cuda\detail\cub\iterator\../util_device.cuh, 151]: invalid device function
CUDA error 48 [C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\thrust/system/cuda/detail/parallel_for.h, 143]: no kernel image is available for execution on the device

I was confused for a long time after searching so much information from the internet. Then I read the answers carefully again with this post CMakeLists Issue: bad_alloc error when calling resize() on thrust::device_vector. In this post, @Robert Crovella gave a solution link. I came across the answer. I tried to modify the architecture type with compute_30,sm_30, this problem was solved. Only then did I realize the reason is the architecture type for my GPU. More information is provided in this page. I set the compiling parameters in CMakeLists.txt from

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
  set(CMAKE_CUDA_ARCHITECTURES 75)
endif()

to

set(CMAKE_CUDA_ARCHITECTURES 53)

The architecture type will be set in the item of code generation.


image.png

No more errors occur.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容