首页 文章

NVidia Thrust device_vector of strings

提问于
浏览
1

我开始使用NVidia Thrust库作为CUDA 4.0工具包的一部分,并希望在深入挖掘之前验证一些内容 . 我可以执行以下操作并在构建期间没有任何问题:

thrust::host_vector <int> iVec;
thrust::device_vector <int> iVec2;
thrust::host_vector <std::string> sVec;

当我尝试以下操作时出现编译错误:

thrust::device_vector <std::string> sVec2;

我想知道的是,我可以假设我可以在STL向量中使用的任何数据类型都可以在推力向量中使用,无论它是设备还是主机?或者这里有限制,我不应该期望这个有用吗?

我得到的错误如下:

c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ device \ cuda \ for_each.inl(93):error C2027:使用未定义类型'thrust :: detail :: STATIC_ASSERTION_FAILURE' 1> with 1> [1> x = false 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ device \ dispatch \ for_each.h(56):请参阅函数模板实例化'RandomAccessIterator thrust :: detail :: device :: cuda :: for_each_n(RandomAccessIterator,Size,UnaryFunction)'正在编译1> 1> [1> RandomAccessIterator = thrust :: detail :: normal_iterator>, 1> Size = __ w64 int,1> UnaryFunction = thrust :: detail :: device_destroy_functor 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ device \ for_each . inl(43):参见函数模板实例化'RandomAccessIterator thrust :: detail :: device :: dispatch :: for_each_n(RandomAccessIterator,Size,UnaryFunction,thrust :: detail :: cuda_device_space_tag)'正在编译1> 1> [ 1> RandomAccessItera tor = thrust :: detail :: normal_iterator>,1> OutputIterator = thrust :: detail :: normal_iterator>,1> Size = __ w64 int,1> UnaryFunction = thrust :: detail :: device_destroy_functor 1>] 1> c:\程序文件\ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ device \ for_each.inl(54):参见函数模板实例化'OutputIterator thrust :: detail :: device :: for_each_n(OutputIterator,大小,UnaryFunction)'正在编译1> 1> [1> OutputIterator = thrust :: detail :: normal_iterator>,1> InputIterator = thrust :: detail :: normal_iterator>,1> UnaryFunction = thrust :: detail :: device_destroy_functor ,1> Size = __ w64 int 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ dispatch \ for_each.h(72):参见函数模板实例化参考'InputIterator thrust :: detail :: device :: for_each(InputIterator,InputIterator,UnaryFunction)'正在编译1> 1> [1> InputIterator = thrust :: detail :: normal_iterator>,1> UnaryFunction = thrust :: detail: :device_destroy_f unctor 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ for_each.inl(51):参见函数模板实例化'InputIterator thrust :: detail :: dispatch :: for_each(InputIterator,InputIterator,UnaryFunction,thrust :: device_space_tag)'正在编译1> 1> [1> InputIterator = thrust :: detail :: normal_iterator>,1> UnaryFunction = thrust :: detail :: device_destroy_functor 1 >] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ for_each.inl(67):参见函数模板实例化'InputIterator thrust :: detail :: for_each( InputIterator,InputIterator,UnaryFunction)'正在编译1> 1> [1> InputIterator = thrust :: detail :: normal_iterator>,1> UnaryFunction = thrust :: detail :: device_destroy_functor 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ dispatch \ destroy.h(59):参见函数模板实例化'void thrust :: for_each>(InputIterator,InputIterator, UnaryFunction)'正在编译1> 1> [1> ForwardIterator = thrust :: detail :: normal_iterator>,1> T = value_type,1> InputIterator = thrust :: detail :: normal_iterator>,1> UnaryFunction = thrust :: detail :: device_destroy_functor 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ destroy.h(42):参见函数模板实例化'void thrust :: detail :: dispatch :: destroy(ForwardIterator,ForwardIterator,thrust :: detail :: false_type)'正在编译1> 1> [1> ForwardIterator = thrust :: detail :: normal_iterator> 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ vector_base.inl(442):参见函数模板实例化'void thrust :: detail :: destroy>(ForwardIterator,ForwardIterator)'正在编译1> with 1> [1> Pointer = thrust :: device_ptr,1> ForwardIterator = thrust :: detail :: normal_iterator> 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ detail \ vector_base.inl(440):whil e编译类模板成员函数'thrust :: detail :: vector_base :: ~vector_base(void)'1> 1> [1> T = std :: string,1> Alloc = thrust :: device_malloc_allocator 1>] 1> c:\ program files \ nvidia gpu computing toolkit \ cuda \ v4.0 \ include \ thrust \ device_vector.h(55):参见类模板实例化'thrust :: detail :: vector_base'正在编译1> with 1> [1> T = std :: string,1>Alloc = thrust :: device_malloc_allocator 1>] 1> c:\ users \ fsquared \ mydata \ idata \ main.cpp(119):参见类模板实例化'thrust :: device_vector'正在编译1> 1> [1 > T = std :: string 1>] ==========构建:0成功,1失败,0最新,0跳过==========

我在这里使用MSCV 2010 .

1 回答

  • 2

    CUDA不支持设备代码中的标准C容器类型,它基本上仅限于C POD类型 . 您可以定义自己的类以在GPU上使用,但构造函数和成员函数必须定义为CUDA __device__ 函数,并且在设备代码中支持哪些语言功能仍有许多限制 .

相关问题