簡體   English   中英

在現有 C 項目中使用 CUDA Thrust:編譯錯誤

[英]Using CUDA Thrust in existing C project: Compilation Error

我正在嘗試將以下基本代碼( radix_sort_128x.cu )合並到現有的C項目中:

#include <thrust/device_vector.h>                                                
#include <thrust/copy.h>                                                         
#include <thrust/sort.h>                                                         

#include "cuda.h"                                                                
extern "C" {                                                                     
    #include "radix_sort_128x.h"                                                  
}                                                                                

__host__ __device__ bool operator<(const mm128_t & lhs, const mm128_t & rhs)        
{ return lhs.x < rhs.x; }                                                        

extern "C"                                                                       
void radix_sort_128x_kernel(mm128_t* list, size_t n) {                           
    thrust::device_vector<mm128_t> list_d(list, list + n);                       
    thrust::sort(list_d.begin(), list_d.end());                                     
    thrust::copy(list_d.begin(), list_d.end(), list);                               
}

但是,當我嘗試使用 NVCC ( nvcc -c -o radix_sort_128x.o radix_sort_128x.cu ) 編譯此文件時,出現以下錯誤:

/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.tcc: In instantiation of ‘static std::basic_string<_CharT, _Traits, _Alloc>::_Rep* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_create(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.tcc:578:28:   required from ‘static _CharT* std::basic_string<_CharT, _Traits, _Alloc>::_S_construct(_InIterator, _InIterator, const _Alloc&, std::forward_iterator_tag) [with _FwdIterator = const char16_t*; _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>]’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:5052:20:   required from ‘static _CharT* std::basic_string<_CharT, _Traits, _Alloc>::_S_construct_aux(_InIterator, _InIterator, const _Alloc&, std::__false_type) [with _InIterator = const char16_t*; _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>]’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:5073:24:   required from ‘static _CharT* std::basic_string<_CharT, _Traits, _Alloc>::_S_construct(_InIterator, _InIterator, const _Alloc&) [with _InIterator = const char16_t*; _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>]’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.tcc:656:134:   required from ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc&) [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>; std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h:6725:95:   required from here
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.tcc:1067:1: error: cannot call member function ‘void std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_set_sharable() [with _CharT = char16_t; _Traits = std::char_traits<char16_t>; _Alloc = std::allocator<char16_t>]’ without object __p->_M_set_sharable();

看來我的任何#include語句(使用 Thrust 標頭)都會導致此錯誤,並且可能是由於 C 與 C++ 沖突造成的。 知道如何解決這個問題嗎? 我試過將整個項目編譯為 C++,但這並沒有解決任何問題。 提前致謝!

我的 CUDA 版本 (10.1) 與 GCC 版本 (8.3.1) 不兼容。 我曾嘗試將 GCC 降級到 4.3.5,但沒有意識到/usr/local/cuda/include中的符號鏈接將 CUDA 指向devtoolset-8 GCC 版本 8.3.1,而我的降級嘗試失敗了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM