allendaicool / thrust

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

thrust::reduce example code from sum.cu (and thrust homepage) generates linker errors #271

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please post a short code sample which reproduces the problem:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/reduce.h>
#include <thrust/functional.h>
#include <cstdlib>

void main()
{
    // generate random data on the host
    thrust::host_vector<int> h_vec(100);
    thrust::generate(h_vec.begin(), h_vec.end(), rand);

    // transfer to device and compute sum
    thrust::device_vector<int> d_vec = h_vec;
    int x = thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());
}

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

It's worth noting that the following linker errors go away when the the call to 
thrust::reduce is commented out.

2>iucore.obj : error LNK2019: unresolved external symbol "int __cdecl 
thrust::detail::device::cuda::get_unordered_blocked_reduce_n_schedule<class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >,int,int,struct 
thrust::plus<int> >(class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> >,int,int,struct thrust::plus<int>)" 
(??$get_unordered_blocked_reduce_n_schedule@V?$normal_iterator@V?$device_ptr@H@t
hrust@@@detail@thrust@@HHU?$plus@H@3@@cuda@device@detail@thrust@@YAHV?$normal_it
erator@V?$device_ptr@H@thrust@@@23@HHU?$plus@H@3@@Z) referenced in function 
"int __cdecl 
thrust::detail::device::dispatch::get_unordered_blocked_reduce_n_schedule<class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >,int,int,struct 
thrust::plus<int> >(class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> >,int,int,struct thrust::plus<int>,struct 
thrust::detail::cuda_device_space_tag)" 
(??$get_unordered_blocked_reduce_n_schedule@V?$normal_iterator@V?$device_ptr@H@t
hrust@@@detail@thrust@@HHU?$plus@H@3@@dispatch@device@detail@thrust@@YAHV?$norma
l_iterator@V?$device_ptr@H@thrust@@@23@HHU?$plus@H@3@Ucuda_device_space_tag@23@@
Z)
2>iucore.obj : error LNK2019: unresolved external symbol "void __cdecl 
thrust::detail::device::cuda::unordered_blocked_reduce_n<class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >,int,int,struct 
thrust::plus<int>,class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> > >(class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> >,int,int,struct thrust::plus<int>,class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >)" 
(??$unordered_blocked_reduce_n@V?$normal_iterator@V?$device_ptr@H@thrust@@@detai
l@thrust@@HHU?$plus@H@3@V123@@cuda@device@detail@thrust@@YAXV?$normal_iterator@V
?$device_ptr@H@thrust@@@23@HHU?$plus@H@3@0@Z) referenced in function "void 
__cdecl thrust::detail::device::dispatch::unordered_blocked_reduce_n<class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >,int,int,struct 
thrust::plus<int>,class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> > >(class thrust::detail::normal_iterator<class 
thrust::device_ptr<int> >,int,int,struct thrust::plus<int>,class 
thrust::detail::normal_iterator<class thrust::device_ptr<int> >,struct 
thrust::detail::cuda_device_space_tag)" 
(??$unordered_blocked_reduce_n@V?$normal_iterator@V?$device_ptr@H@thrust@@@detai
l@thrust@@HHU?$plus@H@3@V123@@dispatch@device@detail@thrust@@YAXV?$normal_iterat
or@V?$device_ptr@H@thrust@@@23@HHU?$plus@H@3@0Ucuda_device_space_tag@23@@Z)

What version of Thrust are you using? Which version of nvcc?  Which host
compiler?  On what operating system?

Thrust 1.3, NVCC 3.2 64-bit, MSVC 10, Windows 7 64-bit

Please provide any additional information below.

Are there any quick hack workarounds for this?   :)

Original issue reported on code.google.com by mikerobe...@gmail.com on 8 Nov 2010 at 6:31

GoogleCodeExporter commented 9 years ago
Oops. In Visual Studio I have "Platform Toolset" for this project set to vc90, 
so the compiler that compiles this thrust code is MSCV 9.

Cheers,
Mike

Original comment by mikerobe...@gmail.com on 8 Nov 2010 at 6:43

GoogleCodeExporter commented 9 years ago

Original comment by jaredhoberock on 8 Nov 2010 at 6:47

GoogleCodeExporter commented 9 years ago

Original comment by jaredhoberock on 8 Nov 2010 at 6:50

GoogleCodeExporter commented 9 years ago
Thanks for the report, Mike.

I'm not able to reproduce this problem on my system (Thrust 1.3.0, nvcc 3.2 
32b, MSVC 9 32b).  Can you attach the output of nvcc --verbose?

Original comment by jaredhoberock on 8 Nov 2010 at 7:02

GoogleCodeExporter commented 9 years ago
Hey Jared,

You can safely file this bug under "Mike's an idiot". I was compiling outside 
of NVCC. 

The thrust interface is so high-level and pleasant it started sneaking into my 
cpp files. I moved the reduce code into a .cu file, compiled with NVCC, and the 
problem went away.

Thanks so much for your help.  :)

Original comment by mikerobe...@gmail.com on 8 Nov 2010 at 7:12

GoogleCodeExporter commented 9 years ago
Thanks for root causing it, Mike.

Actually this is our fault; compiling in CUDA mode without nvcc should produce 
a compiler error, not a confusing linker error.  I've filed a separate issue to 
track this problem [1].

[1] http://code.google.com/p/thrust/issues/detail?id=272

Original comment by jaredhoberock on 8 Nov 2010 at 7:19