Saya mencoba memasukkan kode dasar berikut (radix_sort_128x.cu) ke dalam proyek C yang ada:

#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);                               
}

Namun, ketika saya mencoba mengkompilasi file ini menggunakan NVCC (nvcc -c -o radix_sort_128x.o radix_sort_128x.cu), saya mendapatkan kesalahan berikut:

/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();

Tampaknya pernyataan #include saya (menggunakan header Thrust) menyebabkan kesalahan ini, dan mungkin karena konflik C vs C++. Adakah ide bagaimana cara memperbaikinya? Saya sudah mencoba mengkompilasi seluruh proyek sebagai C++, tetapi itu tidak memperbaiki apa pun. Terima kasih sebelumnya!

0
TimD1 23 Maret 2020, 19:38

1 menjawab

Jawaban Terbaik

Versi CUDA saya (10.1) tidak kompatibel dengan versi GCC (8.3.1). Saya telah mencoba menurunkan versi GCC ke 4.3.5, tetapi tidak menyadari bahwa tautan simbolis di /usr/local/cuda/include mengarahkan CUDA ke devtoolset-8 GCC versi 8.3.1 dan upaya saya untuk menurunkan versi gagal.

1
TimD1 23 Maret 2020, 20:51