Search code examples
cudathrust

Thrust conversion loss data warnings


I was trying to use thrust to perform a reduction on some data but at compile time I get a lot of warnings regarding possible conversion loss of data

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>          ]

I know those are warnings but they are really annoying, is there any way to turn off these?


Solution

  • This is two years later, and the problem(s) still exist. I have figured out what's going on here, and have a solution.

    First, to restate the problem. If you create a brand new CUDA project (I'm using CUDA 7.5 and Visual Studio 2013) and put in simply this:

    #include <thrust/device_vector.h>
    
    int main()
    {
        thrust::device_vector<int> test;
        return 0;
    }
    

    Then switch the project to 64-bit (change the config to x64, which changes the compiler to 64 code generation), you get several warnings from within Thrust that complain about conversion loss from size_t to int. These warnings all are coming (at least today) from the Thrust execution_policy.hpp include file.

    In that file there are several cases where the type size_type is defined as int, then later used as an equivalent or return value for size_t data. That explains the warnings. In MSVC 64-bit-land a size_t is 2x the size of an int.

    As a test, I've changed the several instances of:

    typedef int size_type;
    

    in execution_policy.hpp to:

    typedef size_t size_type;
    

    and all the warnings go away.

    I'm going now over to the Thrust github project and suggest just such a change.

    Hope this helps somebody, it's been driving me nuts.