lion03 / thrust

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

Example on home page doesn't compile (ubuntu 10.4; cuda 3.1; thrust 1.2) #186

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please post a short code sample which reproduces the problem:
This is the example copy-pasted from the home page:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <cstdlib>

int main(void)
{
    // generate 16M random numbers on the host
    thrust::host_vector<int> h_vec(1 << 24);
    thrust::generate(h_vec.begin(), h_vec.end(), rand);

    // transfer data to the device
    thrust::device_vector<int> d_vec = h_vec;

    // sort data on the device (145M keys per second on a GTX 280)
    thrust::sort(d_vec.begin(), d_vec.end());

    // transfer data back to host
    thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());

    return 0;
}

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

The expected output is nothing; instead I get:

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(295): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "Derived thrust::experimental::operator+(const thrust::experimental::iterator_facade<Derived1, Pointer1, Value1, Space1, Traversal1, Reference1, Difference1> &, Derived::difference_type) [with Derived=thrust::detail::normal_iterator<int *>, Pointer=int *, Value=int, Space=thrust::host_space_tag, Traversal=thrust::random_access_traversal_tag, Reference=int &, Difference=ptrdiff_t]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(354): here
            instantiation of "thrust::detail::normal_iterator<Alloc::pointer> thrust::detail::vector_base<T, Alloc>::end() [with T=int, Alloc=std::allocator<int>]" 
testThrust2.cu(12): here

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(296): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "Derived thrust::experimental::operator+(const thrust::experimental::iterator_facade<Derived1, Pointer1, Value1, Space1, Traversal1, Reference1, Difference1> &, Derived::difference_type) [with Derived=thrust::detail::normal_iterator<int *>, Pointer=int *, Value=int, Space=thrust::host_space_tag, Traversal=thrust::random_access_traversal_tag, Reference=int &, Difference=ptrdiff_t]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(354): here
            instantiation of "thrust::detail::normal_iterator<Alloc::pointer> thrust::detail::vector_base<T, Alloc>::end() [with T=int, Alloc=std::allocator<int>]" 
testThrust2.cu(12): here

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(265): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "__gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/include/c++/4.4/bits/stl_algobase.h(738): here
            instantiation of "void std::fill(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/fill.h(48): here
            instantiation of "void thrust::detail::dispatch::fill(ForwardIterator, ForwardIterator, const T &, thrust::host_space_tag) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/fill.inl(36): here
            instantiation of "void thrust::fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/uninitialized_fill.h(46): 
here
            instantiation of "void thrust::detail::dispatch::uninitialized_fill(ForwardIterator, ForwardIterator, const T &, thrust::detail::true_type) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/uninitialized_fill.inl(41): here
            instantiation of "void thrust::uninitialized_fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(164): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::fill_init(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(66): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/host_vector.h(85): here
            instantiation of "thrust::host_vector<T, Alloc>::host_vector(thrust::detail::vector_base<T, Alloc>::size_type, const thrust::detail::vector_base<T, Alloc>::value_type &) [with T=int, Alloc=std::allocator<int>]" 
testThrust2.cu(11): here

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(266): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "__gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/include/c++/4.4/bits/stl_algobase.h(738): here
            instantiation of "void std::fill(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/fill.h(48): here
            instantiation of "void thrust::detail::dispatch::fill(ForwardIterator, ForwardIterator, const T &, thrust::host_space_tag) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/fill.inl(36): here
            instantiation of "void thrust::fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/uninitialized_fill.h(46): 
here
            instantiation of "void thrust::detail::dispatch::uninitialized_fill(ForwardIterator, ForwardIterator, const T &, thrust::detail::true_type) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/uninitialized_fill.inl(41): here
            instantiation of "void thrust::uninitialized_fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(164): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::fill_init(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(66): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/host_vector.h(85): here
            instantiation of "thrust::host_vector<T, Alloc>::host_vector(thrust::detail::vector_base<T, Alloc>::size_type, const thrust::detail::vector_base<T, Alloc>::value_type &) [with T=int, Alloc=std::allocator<int>]" 
testThrust2.cu(11): here

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(243): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "__gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/include/c++/4.4/bits/stl_algobase.h(738): here
            instantiation of "void std::fill(_ForwardIterator, _ForwardIterator, const _Tp &) [with _ForwardIterator=thrust::detail::normal_iterator<int *>, _Tp=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/fill.h(48): here
            instantiation of "void thrust::detail::dispatch::fill(ForwardIterator, ForwardIterator, const T &, thrust::host_space_tag) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/fill.inl(36): here
            instantiation of "void thrust::fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/uninitialized_fill.h(46): 
here
            instantiation of "void thrust::detail::dispatch::uninitialized_fill(ForwardIterator, ForwardIterator, const T &, thrust::detail::true_type) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/uninitialized_fill.inl(41): here
            instantiation of "void thrust::uninitialized_fill(ForwardIterator, ForwardIterator, const T &) [with ForwardIterator=thrust::detail::normal_iterator<int *>, T=int]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(164): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::fill_init(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(66): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(size_t, const T &) [with T=int, Alloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/host_vector.h(85): here
            instantiation of "thrust::host_vector<T, Alloc>::host_vector(thrust::detail::vector_base<T, Alloc>::size_type, const thrust::detail::vector_base<T, Alloc>::value_type &) [with T=int, Alloc=std::allocator<int>]" 
testThrust2.cu(11): here

/usr/local/cuda/bin/../include/thrust/device_malloc_allocator.h(115): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "size_t thrust::detail::vector_base<T, Alloc>::max_size() const [with T=int, Alloc=thrust::device_malloc_allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(990): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::allocate_and_copy(size_t, ForwardIterator, ForwardIterator, size_t &, thrust::detail::normal_iterator<Alloc::pointer> &) [with T=int, Alloc=thrust::device_malloc_allocator<int>, ForwardIterator=thrust::detail::normal_iterator<const int *>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(204): here
            instantiation of "void thrust::detail::vector_base<T, Alloc>::range_init(ForwardIterator, ForwardIterator, thrust::detail::false_type) [with T=int, Alloc=thrust::device_malloc_allocator<int>, ForwardIterator=thrust::detail::normal_iterator<const int *>]" 
/usr/local/cuda/bin/../include/thrust/detail/vector_base.inl(106): here
            instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(const thrust::detail::vector_base<OtherT, OtherAlloc> &) [with T=int, Alloc=thrust::device_malloc_allocator<int>, OtherT=int, OtherAlloc=std::allocator<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/device_vector.inl(32): here
            instantiation of "thrust::device_vector<T, Alloc>::device_vector(const thrust::host_vector<OtherT, OtherAlloc> &) [with T=int, Alloc=thrust::device_malloc_allocator<int>, OtherT=int, OtherAlloc=std::allocator<int>]" 
testThrust2.cu(15): here

/usr/local/cuda/bin/../include/thrust/iterator/iterator_facade.h(259): error: 
calling a host function from a __device__/__global__ function is not allowed
          detected during:
            instantiation of "thrust::detail::choose_raw_buffer_allocator<T, Space>::type::reference thrust::detail::raw_buffer<T, Space>::operator[](size_t) [with T=unsigned int, Space=thrust::detail::cuda_device_space_tag]" 
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/detail/stable_radix_sor
t.inl(1143): here
            instantiation of "void thrust::detail::device::cuda::detail::radix_sort(unsigned int *, unsigned int, PreProcess, PostProcess, unsigned int) [with PreProcess=thrust::detail::device::cuda::detail::encode_uint<int>, PostProcess=thrust::detail::device::cuda::detail::decode_uint<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/detail/stable_radix_sor
t_key.inl(112): here
            instantiation of "void thrust::detail::device::cuda::detail::stable_radix_sort_key_dev(KeyType *, unsigned int, thrust::detail::integral_constant<int, 4>, thrust::detail::integral_constant<bool, true>, thrust::detail::integral_constant<bool, true>) [with KeyType=int]" 
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/detail/stable_radix_sor
t_key.inl(131): here
            instantiation of "void thrust::detail::device::cuda::detail::stable_radix_sort_key_dev(KeyType *, unsigned int, thrust::detail::integral_constant<int, 4>) [with KeyType=int]" 
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/detail/stable_radix_sor
t_key.inl(243): here
            instantiation of "void thrust::detail::device::cuda::detail::stable_radix_sort(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>]" 
/usr/local/cuda/bin/../include/thrust/detail/device/cuda/sort.inl(262): here
            [ 3 instantiation contexts not shown ]
            instantiation of "void thrust::detail::device::stable_sort(RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/device/sort.inl(43): here
            instantiation of "void thrust::detail::device::sort(RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/dispatch/sort.h(98): here
            instantiation of "void thrust::detail::dispatch::sort(RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering, thrust::device_space_tag) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/sort.inl(52): here
            instantiation of "void thrust::sort(RandomAccessIterator, RandomAccessIterator, StrictWeakOrdering) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>, StrictWeakOrdering=thrust::less<int>]" 
/usr/local/cuda/bin/../include/thrust/detail/sort.inl(41): here
            instantiation of "void thrust::sort(RandomAccessIterator, RandomAccessIterator) [with RandomAccessIterator=thrust::detail::normal_iterator<thrust::device_ptr<int>>]" 
testThrust2.cu(18): here

7 errors detected in the compilation of 
"/tmp/tmpxft_00005c76_00000000-4_testThrust2.cpp1.ii".

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

Thrust version: thrust-v1.2.zip

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Mon_Jun__7_18:56:31_PDT_2010
Cuda compilation tools, release 3.1, V0.2.1221

$ uname -a
Linux pc7143 2.6.32-24-generic #38-Ubuntu SMP Mon Jul 5 09:20:59 UTC 2010 
x86_64 GNU/Linux

Please provide any additional information below.

Maybe I've got the wrong gcc version, but there is no output to indicate such a 
problem.

Original issue reported on code.google.com by fpbeek...@gmail.com on 30 Jul 2010 at 11:57

GoogleCodeExporter commented 8 years ago
CUDA 3.1 requires Thrust v1.2.1 [1].

[1]http://code.google.com/p/thrust/downloads/list

Original comment by jaredhoberock on 31 Jul 2010 at 1:13

GoogleCodeExporter commented 8 years ago
The following page: http://code.google.com/p/thrust/wiki/Documentation from 
where I got thrust, still has a link to thrust 1.2. Could you update it ?

Original comment by fpbeek...@gmail.com on 31 Jul 2010 at 4:14

GoogleCodeExporter commented 8 years ago
Fixed.

Original comment by jaredhoberock on 31 Jul 2010 at 5:24