jrprak
July 10, 2009, 8:47am
1
Hi,
why does declaring a device vector of a user-defined type (like a struct) cause a compile-time error?
This code doesn’t work because of it:
struct KcFeature
{
float x;
float y;
float val;
};
thrust::device_vector<KcFeature> dv;
The error returned:
obj/release/kltcuda.cpp.o: In function `thrust::detail::vector_base<KcFeature, thrust::device_allocator >::resize(unsigned int, KcFeature)':
kltcuda.cpp:(.text._ZN6thrust6detail11vector_baseI9KcFeature
NS_16device_allocatorIS2_EEE6resizeEjS2_[thrust::detail::vect
or_base<KcFeature, thrust::device_allocator >::resize(unsigned int, KcFeature)]+0xd2): undefined reference to `void thrust::detail::device::cuda::for_each<thrust::detail::vector_base<KcFeature, thrust::device_allocator >::iterator::device_dereferenceable_type, thrust::detail::dispatch::detail::destroyer >(thrust::detail::vector_base<KcFeature, thrust::device_allocator >::iterator::device_dereferenceable_type, thrust::detail::vector_base<KcFeature, thrust::device_allocator >::iterator::device_dereferenceable_type, thrust::detail::dispatch::detail::destroyer)’
Any ideas?
nbell
July 10, 2009, 2:47pm
2
[quote name=‘jrprak’ post=‘563741’ date=‘Jul 10 2009, 04:47 AM’]
Hi,
why does declaring a device vector of a user-defined type (like a struct) cause a compile-time error?
This code doesn’t work because of it:
[codebox]#include
struct KcFeature
{
float x;
float y;
float val;
};
int main(void)
{
thrust::device_vector<KcFeature> dv;
return 0;
}
[/codebox]
and it seems to work fine.
I would try the following:
make sure that you’re using nvcc 2.2 (or 2.3 beta) by running nvcc --version.
delete all object files and recompile everything
try compiling the code snippet above
Jared and I read this board frequently, but in the future you should post questions to thrust-users [1] so we don’t miss anything.
[1] http://groups.google.com/group/thrust-users
obj/release/kltcuda.cpp.o: In function `thrust::detail::vector_base<KcFeature, thrust::device_allocator<KcFeature> >::resize(unsigned int, KcFeature)':
kltcuda.cpp:(.text._ZN6thrust6detail11vector_baseI9KcFeature
It looks like you’re compiling with the MSVC compiler instead of nvcc, the CUDA compiler. Try giving your source file a ‘.cu’ extension and rename it to ‘kltcuda.cu’ to make sure that MSVC uses nvcc to compile.