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.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容