cuda - 推力转换损失数据警告

标签 cuda thrust

我试图使用 thrust 对一些数据进行归约,但在编译时我收到很多关于可能的数据转换丢失的警告

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\thrust/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 Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\thrust/system/cuda/detail/cuda_launch_config.h(147): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data
1>          C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\thrust/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 Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include\thrust/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整数。这些警告都来自(至少今天)来自 Thrust execution_policy.hpp 包含文件。

在该文件中,有几种情况类型 size_type 被定义为 int,然后用作 size_t 的等效值或返回值> 数据。这解释了警告。在 MSVC 64 位环境中,size_tint 大小的 2 倍。

作为测试,我更改了以下几个实例:

typedef int size_type;

execution_policy.hpp 中:

typedef size_t size_type;

所有的警告都消失了。

我现在要转到 Thrust github 项目并提出这样的更改建议。

希望这对某些人有所帮助,这让我抓狂。

关于cuda - 推力转换损失数据警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18189375/

相关文章:

cuda - CUDA 是否保证 float 为 4 个字节?

cuda - 如何选择指定GPU来运行CUDA程序?

c++ - CUDA Thrust reduce_by_key 使用更少的内存

cuda - Nvidia NVML 驱动程序/库版本不匹配

cuda - 将 cuda 与 gmp 链接

c++ - 将 C++ 与 CUDA 结合使用

c++ - CUDA/推力图像处理

cuda - 简单的 CUDA 推力程序错误

cuda - 如何估计基于推力的实现的 GPU 内存需求?

c++ - 如何在CUDA中为多个Thrust对象成员函数调用内核函数?