首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在现有C项目中使用CUDA推力:编译错误

在现有C项目中使用CUDA推力:编译错误
EN

Stack Overflow用户
提问于 2020-03-24 00:38:43
回答 1查看 182关注 0票数 0

我正在尝试将以下基本代码(radix_sort_128x.cu)合并到现有的C项目中:

代码语言:javascript
复制
#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)编译这个文件时,我得到以下错误:

代码语言:javascript
复制
/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语句(使用了推力头)导致了这个错误,并且可能是由于C与C++的冲突。你知道怎么解决这个问题吗?我已经尝试将整个项目编译为C++,但这并没有解决任何问题。提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-24 04:51:06

我的CUDA版本(10.1)与GCC版本(8.3.1)不兼容。我曾试图将GCC降级到4.3.5,但没有意识到/usr/local/cuda/include中的符号链接指向devtoolset-8 GCC 8.3.1版,并且我的降级尝试失败了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60817809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档