lion03 / thrust

Automatically exported from code.google.com/p/thrust
Apache License 2.0
0 stars 0 forks source link

warning: calling a __host__ function ... when using thrust::transform_iterator with a std::container::iterator #329

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please post a short, self-contained code sample which reproduces the
problem:

#include <vector>
#include <thrust/functional.h>
#include <thrust/iterator/transform_iterator.h>

struct gets_value : public thrust::unary_function<int, int>
{
    __host__ int operator()(int value) const
    {
        return value;
    }
};

int main(int argc, char** argv)
{
    thrust::transform_iterator<gets_value,std::vector<int>::iterator> i;

    return 0;
}

What is the expected output? What do you see instead?

"thrust/thrust/iterator/iterator_adaptor.h(81): warning: calling a __host__ 
function from a __host__ __device__ function is not allowed
          detected during:
            instantiation of "thrust::experimental::iterator_adaptor<Derived, Base, Pointer, Value, Space, Traversal, Reference, Difference>::iterator_adaptor() [with Derived=thrust::transform_iterator<gets_value, __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>>>, thrust::use_default, thrust::use_default>, Base=__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>>>, Pointer=int *, Value=int, Space=thrust::use_default, Traversal=std::random_access_iterator_tag, Reference=int, Difference=thrust::use_default]" 
"thrust/thrust/iterator/transform_iterator.h(209): here
            instantiation of "thrust::transform_iterator<AdaptableUnaryFunction, Iterator, Reference, Value>::transform_iterator() [with AdaptableUnaryFunction=gets_value, Iterator=__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>>>, Reference=thrust::use_default, Value=thrust::use_default]" 
test.cu(17): here

What version of Thrust are you using?

Revision 1409 : 7ded38be1741    (from March 8, 2011)

Which version of nvcc?

Built on Mon_Feb_21_03:22:30_PST_2011
Cuda compilation tools, release 4.0, V0.2.1221

 Which host compiler?  On what operating system?

Mac gcc 4.2 default.

Which GPU?

n/a

Please provide any additional information below.

Original issue reported on code.google.com by andrew.c...@gmail.com on 31 Mar 2011 at 4:08

GoogleCodeExporter commented 8 years ago
sorry I meant to add, this is a simplified reproduction of a slightly more 
complicated problem:  I need to apply a transform iterator to a 
std::map::iterator, which gives the same error.  This is purely host code, so I 
am not sure why using thrust::transform_iterator would lead to a __host__ 
function being called from __host__ __device__ function.

Original comment by andrew.c...@gmail.com on 31 Mar 2011 at 4:10

GoogleCodeExporter commented 8 years ago
The std::vector::iterator's constructor (which is a __host__ function) invoked 
by iterator_adaptor's constructor [1] (which is a __host__ __device__ function) 
is producing the warning.  I'm not sure we can do anything about this given the 
current rules of CUDA.

We're aware of this problem, as are the compiler folks.

[1] 
http://code.google.com/p/thrust/source/browse/thrust/iterator/iterator_adaptor.h
#81

Original comment by jaredhoberock on 31 Mar 2011 at 6:14

GoogleCodeExporter commented 8 years ago
Can this specific warning then be suppressed somehow in the mean time?

Original comment by janick.m...@gmail.com on 30 May 2011 at 2:26