NVidia推力装置_弦矢量

NVidia Thrust device_vector of strings

本文关键字:装置 NVidia      更新时间:2023-10-16

我开始使用作为CUDA 4.0工具包一部分的英伟达Thrust库,并希望在深入挖掘之前进行验证。我可以执行以下操作,并且在构建过程中没有问题:

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计算工具包\cuda\v4.0\include\thrust\detail\device\cuda\\for_each.inl(93):错误C2027:使用未定义的类型"thrust::detail::STATIC_ASSERTION_FAILURE"1> 与1>[1> x=错误1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\device\dispatch\for_each.h(56):参见正在编译的函数模板实例化"RandomAccessIterator thrust::detail::device::cuda::for_each_n(RandomAccess Iterator,Size,UnaryFunction)"的参考1> 与1>[1> RandomAccessIterator=推力::detail::normal_iterator>,1> 大小=__w64 int,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\device\for_each.inl(43):请参阅正在编译的函数模板实例化"RandomAccessIterator thrust::detail::device::dispatch::for_each_n(RandomAccess Iterator,Size,UnaryFunction,thrust:::detail:::cuda_device_space_tag)"1> 与1>[1> RandomAccessIterator=推力::detail::normal_iterator>,1> OutputIterator=推力::detail::normal_iterator>,1> 大小=__w64 int,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\device\for_each.inl(54):请参阅正在编译的函数模板实例化'OutputIterator thrust::detail::device::for_each_n(OutputItator,Size,UnaryFunction)'的参考1> 与1>[1> OutputIterator=推力::detail::normal_iterator>,1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=推力::detail::device_destroy_functor,1> 大小=__w64 int1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\dispatch\for_each(72):请参阅正在编译的函数模板实例化"InputIterator thrust::detail::device::for_each"1> 与1>[1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\for_each.inl(51):请参阅正在编译的函数模板实例化"InputIterator thrust::detail::dispatch::for_each(InputIterater,InputIterato,UnaryFunction,thrust:::device_space_tag)"的参考1> 与1>[1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\for_each.inl(67):请参阅正在编译的函数模板实例化"InputIterator thrust::detail::for_each(InputIterater,InputIterato,UnaryFunction)"的参考1> 与1>[1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\dispatch\ddestroy.h(59):请参阅正在编译的函数模板实例化'void thrust::for_each>(InputIterator,InputIterater,UnaryFunction)'的参考1> 与1>[1> ForwardIterator=推力::detail::normal_iterator>,1> T=value_type,1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\destroy.h(42):请参阅正在编译的函数模板实例化'void thrust::detail::dispatch::destroy(ForwardIterator,ForwardItator,thrust:::detail:::false _type)'的参考1> 与1>[1> ForwardIterator=推力::detail::normal_iterator>1>]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\vector_base.inl(442):请参阅正在编译的函数模板实例化"void thrust::detail::destroy>(ForwardIterator,ForwardItator)"的参考1> 与1>[1> 指针=推力::device_ptr,1> ForwardIterator=推力::detail::normal_iterator>1>]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\detail\vector_base.inl(440):编译类模板成员函数'thrust::detail::vector_bbase::~vector_base(void)'时1> 与1>[1> T=std::字符串,1> Alloc=推力::device_malloc_allocater1> ]1> c:\program files\nvidia gpu计算工具包\cuda\v4.0\include\thrust\device_vector.h(55):请参阅正在编译的类模板实例化'thrust::detail::vector_base'的参考1> 与1>[1> T=std::字符串,1> Alloc=推力::device_malloc_allocater1> ]1> c:\users\fsquared\mydata\didata\main.cpp(119):请参阅对正在编译的类模板实例化'thrust::device_vector'的引用1> 与1>[1> T=std::字符串1> ]==========生成:0成功,1失败,0最新,0跳过==========

我在这里使用MSCV 2010。

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