本文介绍了NVidia推力device_vector的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用作为CUDA 4.0工具包一部分的NVidia Thrust库,并希望在深入挖掘之前进行验证。我可以执行以下,并在生成期间没有问题:

I started using the NVidia Thrust library which comes as part of the CUDA 4.0 toolkit and wanted to verify something before digging deeper. I can perform the following and have no issues during build:

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

当我尝试下面的命令时遇到编译错误:

When I try the following I get a compilation error:

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

我想知道的是我可以假设任何数据类型,我可以使用在STL向量应该可以在推力向量中使用,而不管它是设备还是主机?

What I would like to know is can I assume any data type I can use in an STL vector should be useable in a thrust vector irrespective of whether it's device or host? Or are there limitations here and I shouldn't expect this to work?

我得到的错误如下:

c:\program files\ nvidia gpu computing toolkit \cuda\v4.0\include\thrust\detail\device\cuda\for_each.inl(93):错误C2027:使用未定义类型'thrust :: detail :: STATIC_ASSERTION_FAILURE'
1>与
1> [
1> x = false
1>]
1> c :\program files\\\
vidia 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 \\\
vidia 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> RandomAccessIterator = thrust :: detail :: normal_iterator>,
1> OutputIterator = thrust :: detail :: normal_iterator>,
1> Size = __ w64 int,
1> UnaryFunction = thrust :: detail :: device_destroy_functor
1>]
1> c:\program files\\\
vidia gpu computing toolkit \cuda\v4.0\include\thrust\detail\device\for_each.inl(54 ):参见函数模板实例化'OutputIterator thrust :: detail :: device :: for_each_n(OutputIterator,Size,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\\\
vidia gpu computing toolkit \cuda\v4.0\include\thrust\detail\dispatch\\ \\for_each.h(72):参见函数模板实例化'InputIterator thrust :: detail :: device :: for_each(InputIterator,InputIterator,UnaryFunction)'正在编译
1> with
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\rustal\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\正在编译
1>和
1参见参考的函数模板实例化InputIterator thrust :: detail :: for_each(InputIterator,InputIterator,UnaryFunction) > [
1> InputIterator = thrust :: detail :: normal_iterator>,
1> UnaryFunction = thrust :: detail :: device_destroy_functor
1>]
1> c: \\ program \ nvidia gpu计算工具包\cuda\v4.0\\\\\\\\\\\\\\\\\\\\\\\\\\\\ dustroy.h(59):参见函数模板实例化的参考'void thrust :: for_each正在编译
1>
1> [
1> ForwardIterator = thrust :: detail :: normal_iterator>,
1> T(= InputIterator,InputIterator,UnaryFunction) value_type,
1> InputIterator = thrust :: detail :: normal_iterator>,
1> UnaryFunction = thrust :: detail :: device_destroy_functor
1>]
1> c: \\program files\\\
vidia 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\\\
vidia gpu computing toolkit \cuda\v4.0\include\thrust\detail\vector_base.inl(442):参见函数模板实例化'void thrust :: detail :: destroy>(ForwardIterator,ForwardIterator)'正在编译
1>与
1> [
1> Pointer = thrust :: device_ptr ,
1> ForwardIterator = thrust :: detail :: normal_iterator>
1>]
1> c:\program files\\\
vidia gpu computing toolkit \cuda\v4.0 \include\thrust\detail\vector_base.inl(440):当编译类模板成员函数'thrust :: detail :: vector_base ::〜vector_base(void)'
1> with
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>
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>]
========== Build:0成功,1失败,0最新,0跳过=== =======

c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\device\cuda\for_each.inl(93): error C2027: use of undefined type 'thrust::detail::STATIC_ASSERTION_FAILURE'1> with1> [1> x=false1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\device\dispatch\for_each.h(56) : see reference to function template instantiation 'RandomAccessIterator thrust::detail::device::cuda::for_each_n(RandomAccessIterator,Size,UnaryFunction)' being compiled1> with1> [1> RandomAccessIterator=thrust::detail::normal_iterator>,1> Size=__w64 int,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\device\for_each.inl(43) : see reference to function template instantiation 'RandomAccessIterator thrust::detail::device::dispatch::for_each_n(RandomAccessIterator,Size,UnaryFunction,thrust::detail::cuda_device_space_tag)' being compiled1> with1> [1> RandomAccessIterator=thrust::detail::normal_iterator>,1> OutputIterator=thrust::detail::normal_iterator>,1> Size=__w64 int,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\device\for_each.inl(54) : see reference to function template instantiation 'OutputIterator thrust::detail::device::for_each_n(OutputIterator,Size,UnaryFunction)' being compiled1> with1> [1> OutputIterator=thrust::detail::normal_iterator>,1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor,1> Size=__w64 int1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\dispatch\for_each.h(72) : see reference to function template instantiation 'InputIterator thrust::detail::device::for_each(InputIterator,InputIterator,UnaryFunction)' being compiled1> with1> [1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\for_each.inl(51) : see reference to function template instantiation 'InputIterator thrust::detail::dispatch::for_each(InputIterator,InputIterator,UnaryFunction,thrust::device_space_tag)' being compiled1> with1> [1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\for_each.inl(67) : see reference to function template instantiation 'InputIterator thrust::detail::for_each(InputIterator,InputIterator,UnaryFunction)' being compiled1> with1> [1> InputIterator=thrust::detail::normal_iterator>,1> UnaryFunction=thrust::detail::device_destroy_functor1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\detail\dispatch\destroy.h(59) : see reference to function template instantiation 'void thrust::for_each>(InputIterator,InputIterator,UnaryFunction)' being compiled1> with1> [1> ForwardIterator=thrust::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 computing toolkit\cuda\v4.0\include\thrust\detail\destroy.h(42) : see reference to function template instantiation 'void thrust::detail::dispatch::destroy(ForwardIterator,ForwardIterator,thrust::detail::false_type)' being compiled1> with1> [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) : see reference to function template instantiation 'void thrust::detail::destroy>(ForwardIterator,ForwardIterator)' being compiled1> with1> [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) : while compiling class template member function 'thrust::detail::vector_base::~vector_base(void)'1> with1> [1> T=std::string,1> Alloc=thrust::device_malloc_allocator1> ]1> c:\program files\nvidia gpu computing toolkit\cuda\v4.0\include\thrust\device_vector.h(55) : see reference to class template instantiation 'thrust::detail::vector_base' being compiled1> with1> [1> T=std::string,1> Alloc=thrust::device_malloc_allocator1> ]1> c:\users\fsquared\mydata\idata\main.cpp(119) : see reference to class template instantiation 'thrust::device_vector' being compiled1> with1> [1> T=std::string1> ]========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我在这里使用MSCV 2010。

I am using MSCV 2010 here.

推荐答案

CUDA不支持设备代码中的标准C ++容器类型,它仅限于C ++基本类型。你可以定义自己的类在GPU上使用,但是构造函数和成员函数必须定义为CUDA __ device __ 函数,并且对于什么语言还有一些限制功能在设备代码中支持。

CUDA does not support standard C++ container types in device code, it is limited to C++ fundamental types only. You can define your own classes for use on the GPU, but the constructor and member functions must be defined as CUDA __device__ functions, and there are still a number of limitations on what language features are support in device code.

这篇关于NVidia推力device_vector的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 22:17