我试图使用推力来减少一些数据,但在编译时,我收到了很多关于数据可能转换丢失的警告
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.5includethrust/system/cuda/detail/cuda_launch_config.h(338) : see reference to function template instantiation 'size_t thrust::system::cuda::detail::block_size_with_maximum_potential_occupancy<thrust::system::cuda::detail::cuda_launch_config_detail::util::zero_function<T>>(const thrust::system::cuda::detail::function_attributes_t &,const thrust::system::cuda::detail::device_properties_t &,UnaryFunction)' being compiled
1> with
1> [
1> T=size_t,
1> UnaryFunction=thrust::system::cuda::detail::cuda_launch_config_detail::util::zero_function<size_t>
1> ]
1>C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.5includethrust/system/cuda/detail/cuda_launch_config.h(147): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data
1> C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.5includethrust/system/cuda/detail/cuda_launch_config.h(159) : see reference to function template instantiation 'L thrust::system::cuda::detail::cuda_launch_config_detail::util::divide_ri<L,R>(const L,const R)' being compiled
1> with
1> [
1> L=int,
1> R=size_t
1> ]
1> C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.5includethrust/system/cuda/detail/cuda_launch_config.h(272) : see reference to function template instantiation 'L thrust::system::cuda::detail::cuda_launch_config_detail::util::round_i<L,size_t>(const L,const R)' being compiled
1> with
1> [
1> L=int,
1> R=size_t
1> ]
我知道这些都是警告,但它们真的很烦人,有什么办法可以关掉这些吗?
两年后,问题仍然存在。我已经弄清楚了这里发生了什么,并找到了解决方案。
首先,重申问题。如果你创建一个全新的CUDA项目(我使用的是CUDA 7.5和Visual Studio 2013),并简单地输入以下内容:
#include <thrust/device_vector.h>
int main()
{
thrust::device_vector<int> test;
return 0;
}
然后将项目切换到64位(将配置更改为x64,这将编译器更改为64代码生成),您会从Thrust中收到几条警告,抱怨从size_t
到int
的转换丢失。这些警告都来自Thrust execution_policy.hpp
include文件(至少在今天)。
在该文件中,有几种情况下,类型size_type
被定义为int
,然后用作size_t
数据的等效值或返回值。这就解释了这些警告。在MSVC 64位平台中,size_t
是int
的大小的2倍。
作为测试,我更改了以下几个实例:
typedef int size_type;
在execution_policy.hpp
中到:
typedef size_t size_type;
所有的警告都消失了。
我现在转到Thrust github项目,并建议进行这样的更改。
希望这能帮助到别人,这让我抓狂。
我认为您可以使用#pragma warning (disable : 4267)
。但是,如果您没有令人信服的理由不这样做,我会修改代码。
CCD_ 11和CCD_。现在可能对你有用的东西可能会在某个时候在你不想被咬的地方咬你。例如,请参阅"为什么size_t很重要"。