Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Error while compiling example code #614

Closed
@BenjaminHorn

Description

@BenjaminHorn

I try to compile some sample code from the documentation. The ones in https://github.com/thrust/thrust/wiki/Quick-Start-Guide works fine, but im having some problem with the examples in https://github.com/thrust/thrust/blob/master/README.md

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

int main(void)
{
  // generate random data serially
  thrust::host_vector<int> h_vec(100);
  std::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>());
  return 0;
}

It seems this line causing the problem: int x = thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());

nvcc -c -O2 -o build/Release/CUDA-Linux-x86/main.o main.cpp
In file included from /usr/local/cuda/bin/..//include/thrust/system/detail/generic/for_each.h:27:0,
from /usr/local/cuda/bin/..//include/thrust/detail/for_each.inl:26,
from /usr/local/cuda/bin/..//include/thrust/for_each.h:277,
from /usr/local/cuda/bin/..//include/thrust/system/detail/generic/transform.inl:19,
from /usr/local/cuda/bin/..//include/thrust/system/detail/generic/transform.h:100,
from /usr/local/cuda/bin/..//include/thrust/detail/transform.inl:25,
from /usr/local/cuda/bin/..//include/thrust/transform.h:719,
from /usr/local/cuda/bin/..//include/thrust/system/detail/generic/copy.inl:23,
from /usr/local/cuda/bin/..//include/thrust/system/detail/generic/copy.h:56,
from /usr/local/cuda/bin/..//include/thrust/detail/copy.inl:21,
from /usr/local/cuda/bin/..//include/thrust/detail/copy.h:86,
from /usr/local/cuda/bin/..//include/thrust/detail/allocator/copy_construct_range.inl:21,
from /usr/local/cuda/bin/..//include/thrust/detail/allocator/copy_construct_range.h:44,
from /usr/local/cuda/bin/..//include/thrust/detail/contiguous_storage.inl:22,
from /usr/local/cuda/bin/..//include/thrust/detail/contiguous_storage.h:128,
from /usr/local/cuda/bin/..//include/thrust/detail/vector_base.h:29,
from /usr/local/cuda/bin/..//include/thrust/host_vector.h:26,
from main.cpp:1:
/usr/local/cuda/bin/..//include/thrust/system/detail/generic/for_each.h: In instantiation of ‘OutputType thrust::system::cuda::detail::reduce_detail::reduce(thrust::system::cuda::detail::execution_policy&, InputIterator, InputIterator, OutputType, BinaryFunction) [with DerivedPolicy = thrust::system::cuda::detail::tag; InputIterator = thrust::detail::normal_iteratorthrust::device_ptr; OutputType = int; BinaryFunction = thrust::plus]’:
/usr/local/cuda/bin/..//include/thrust/system/cuda/detail/reduce.inl:268:66: required from ‘OutputType thrust::system::cuda::detail::reduce(thrust::system::cuda::detail::execution_policy&, InputIterator, InputIterator, OutputType, BinaryFunction) [with DerivedPolicy = thrust::system::cuda::detail::tag; InputIterator = thrust::detail::normal_iteratorthrust::device_ptr; OutputType = int; BinaryFunction = thrust::plus]’
/usr/local/cuda/bin/..//include/thrust/detail/reduce.inl:65:110: required from ‘T thrust::reduce(const thrust::detail::execution_policy_base&, InputIterator, InputIterator, T, BinaryFunction) [with DerivedPolicy = thrust::system::cuda::detail::tag; InputIterator = thrust::detail::normal_iteratorthrust::device_ptr; T = int; BinaryFunction = thrust::plus]’
/usr/local/cuda/bin/..//include/thrust/detail/reduce.inl:173:76: required from ‘T thrust::reduce(InputIterator, InputIterator, T, BinaryFunction) [with InputIterator = thrust::detail::normal_iteratorthrust::device_ptr; T = int; BinaryFunction = thrust::plus]’
main.cpp:19:68: required from here
/usr/local/cuda/bin/..//include/thrust/detail/static_assert.h:71:13: error: invalid application of ‘sizeof’ to incomplete type ‘thrust::detail::STATIC_ASSERTION_FAILURE’
sizeof(::thrust::detail::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>
^
/usr/local/cuda/bin/..//include/thrust/system/detail/generic/for_each.h:48:3: note: in expansion of macro ‘THRUST_STATIC_ASSERT’
THRUST_STATIC_ASSERT( (thrust::detail::depend_on_instantiation<InputIterator, false>::value) );
^

Activity

jaredhoberock

jaredhoberock commented on Jan 7, 2015

@jaredhoberock
Contributor

Hi Benjamin,

CUDA files compiled with nvcc need to have .cu extensions.

For future reference, Stack Overflow or the thrust-users mailing list are the appropriate venues for these sorts of questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jaredhoberock@BenjaminHorn

        Issue actions

          Error while compiling example code · Issue #614 · NVIDIA/thrust