allendaicool / thrust

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

Compilation error in example found in the QuickStartGuide #138

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to compile the following code (found in the quickStartGuide)

-----------------------------------------------

#include <thrust/transform_reduce.h>
#include <thrust/functional.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <cmath>

// square<T> computes the square of a number f(x) -> x*x
template <typename T>
struct square
{
    __host__ __device__
        T operator()(const T& x) const { 
            return x * x;
        }
};

int main(void)
{
    // initialize host array
    float x[4] = {1.0, 2.0, 3.0, 4.0};

    // transfer to device
    thrust::device_vector<float> d_x(x, x + 4);

    // setup arguments
    square<float>        unary_op;
    thrust::plus<float> binary_op;
    float init = 0;

    // compute norm
    float norm = std::sqrt( thrust::transform_reduce(d_x.begin(),
d_x.end(), unary_op, init, binary_op) );

    std::cout << norm << std::endl;

    return 0;
}

-----------------------------------------------

What is the expected output? What do you see instead?
It is expected to compile... but it doesn't.

What version of the product are you using? On what operating system?
Thrust 1.2 , on Ubuntu Linux

Please provide any additional information below.
It gives the following error:

--------------------------------------------------------------------------

/usr/local/cuda/bin/../include/thrust/detail/device/cuda/reduce.inl: In
function ‘OutputType thrust::detail::device::cuda::reduce(InputIterator,
InputIterator, OutputType, BinaryFunction) [with InputIterator =
thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’:
/usr/local/cuda/bin/../include/thrust/detail/device/dispatch/reduce.h:58: 
 instantiated from ‘OutputType
thrust::detail::device::dispatch::reduce(InputIterator, InputIterator,
OutputType, BinaryFunction, thrust::detail::cuda_device_space_tag) [with
InputIterator = thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/device/reduce.h:46:  
instantiated from ‘OutputType thrust::detail::device::reduce(InputIterator,
InputIterator, OutputType, BinaryFunction) [with InputIterator =
thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/dispatch/reduce.h:87:  
instantiated from ‘OutputType
thrust::detail::dispatch::reduce(InputIterator, InputIterator, OutputType,
BinaryFunction, thrust::device_space_tag) [with InputIterator =
thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/reduce.inl:63:   instantiated
from ‘T thrust::reduce(InputIterator, InputIterator, T, BinaryFunction)
[with InputIterator = thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, T = float, BinaryFunction = thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/transform_reduce.inl:42:  
instantiated from ‘OutputType thrust::transform_reduce(InputIterator,
InputIterator, UnaryFunction, OutputType, BinaryFunction) [with
InputIterator = thrust::detail::normal_iterator<thrust::device_ptr<float>
>, UnaryFunction = square<float>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
testeIterator.cpp:31:   instantiated from here
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/reduce.inl:129:
error: invalid application of ‘sizeof’ to incomplete type
‘thrust::detail::STATIC_ASSERTION_FAILURE<false>’ 
/usr/local/cuda/bin/../include/thrust/detail/device/dispatch/reduce.h:58: 
 instantiated from ‘OutputType
thrust::detail::device::dispatch::reduce(InputIterator, InputIterator,
OutputType, BinaryFunction, thrust::detail::cuda_device_space_tag) [with
InputIterator = thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/device/reduce.h:46:  
instantiated from ‘OutputType thrust::detail::device::reduce(InputIterator,
InputIterator, OutputType, BinaryFunction) [with InputIterator =
thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/dispatch/reduce.h:87:  
instantiated from ‘OutputType
thrust::detail::dispatch::reduce(InputIterator, InputIterator, OutputType,
BinaryFunction, thrust::device_space_tag) [with InputIterator =
thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/reduce.inl:63:   instantiated
from ‘T thrust::reduce(InputIterator, InputIterator, T, BinaryFunction)
[with InputIterator = thrust::transform_iterator<square<float>,
thrust::detail::normal_iterator<thrust::device_ptr<float> >, float,
thrust::use_default>, T = float, BinaryFunction = thrust::plus<float>]’
/usr/local/cuda/bin/../include/thrust/detail/transform_reduce.inl:42:  
instantiated from ‘OutputType thrust::transform_reduce(InputIterator,
InputIterator, UnaryFunction, OutputType, BinaryFunction) [with
InputIterator = thrust::detail::normal_iterator<thrust::device_ptr<float>
>, UnaryFunction = square<float>, OutputType = float, BinaryFunction =
thrust::plus<float>]’
testeIterator.cpp:31:   instantiated from here
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/reduce.inl:129:
error: invalid application of ‘sizeof’ to incomplete type
‘thrust::detail::STATIC_ASSERTION_FAILURE<false>’ 

Original issue reported on code.google.com by sallesvi...@gmail.com on 5 May 2010 at 5:37

GoogleCodeExporter commented 9 years ago
Are you compiling this example with nvcc?  If so, does the file have a ".cu" 
extension?

If you compile with a .cpp extension then nvcc will pass the file immediately 
to the
host compiler and produce the error above.

Original comment by wnbell on 5 May 2010 at 7:23

GoogleCodeExporter commented 9 years ago
Thanks a lot!
I haven't realized that I was compiling a file with extension .cpp ...

Sorry for the bug report.

Original comment by sallesvi...@gmail.com on 5 May 2010 at 7:26

GoogleCodeExporter commented 9 years ago
No problem!  It's a common mistake, so don't feel too bad :)

Original comment by wnbell on 5 May 2010 at 7:48

GoogleCodeExporter commented 9 years ago
i have used sort function in thrust library. when i build the solution in 
vs2010 it is taking more time to build.can any body say why?

Original comment by raj.blo...@gmail.com on 8 Dec 2012 at 6:30

GoogleCodeExporter commented 9 years ago
Fell so bad about that... 

Original comment by luizrosa...@gmail.com on 9 Aug 2013 at 5:36