syoummer
syoummer

Reputation: 36

Compile Error Changing Backend System of Thrust with CUDA 5

I installed CUDA 5 recently and found existing code based on Thrust cannot be compiled. The error only happens if I switch to OMP or TBB.

So I did an experiment using monte_carlo.cpp from Thrust example.

When I using include path of CUDA 5.0, I got this error:

g++ -O2 -o monte_carlo monte_carlo.cpp -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP -fopenmp -I /usr/local/cuda-5.0/include/

/tmp/ccFsJtAs.o: In function main': monte_carlo.cpp:(.text+0xa0): undefined reference tofloat thrust::detail::backend::cuda::reduce_n, float, thrust::use_default>, long, float, thrust::plus

(thrust::transform_iterator, float, thrust::use_default>, long, float, thrust::plus)'

But if I change to CUDA 4.1 using

g++ -O2 -o monte_carlo monte_carlo.cpp -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP -fopenmp -I /usr/local/cuda-4.1/include/

There is no error.

And my platform is Ubuntu 10.04 with g++ 4.4.3.

Hope anyone can help me, thanks!

Edit OMP problem is solved by changing the order of -fopenmp as @Robert pointed out, but I failed to compile using TBB

g++ -O2 -o monte_carlo monte_carlo.cpp -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_TBB -ltbb -I /usr/local/cuda/include/ /tmp/ccxSmcnJ.o: In function main': monte_carlo.cpp:(.text+0xa0): undefined reference tofloat thrust::detail::backend::cuda::reduce_n, float, thrust::use_default>, long, float, thrust::plus >(thrust::transform_iterator, float, thrust::use_default>, long, float, thrust::plus)' collect2: ld returned 1 exit status

But the compilation successes if I use

g++ -O2 -o monte_carlo monte_carlo.cpp -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_TBB -ltbb -I /usr/local/cuda-4.1/include/

Upvotes: 0

Views: 342

Answers (1)

talonmies
talonmies

Reputation: 72349

The OpenMP compilation would appear to have been caused by incorrectly specified compilation arguments. Compiling using

g++ -O2 -o monte_carlo monte_carlo.cpp -fopenmp -DTHRUST_DEVICE_BACKEND=THRUST_DEVICE_BACKEND_OMP -lgomp -I\usr\local\cuda\include

(i.e. specifying OpenMP code generation before any pre-processor directives) allowed for correct compilation using the thrust OpenMP backed.

The reported TBB back end compilation error would appear to have been caused by attempting to use the TBB backend on thrust 1.5.3, which has no TBB support.

[This answer has been assembled from question edits and comments to get the question off the unanswered list for the CUDA tag]

Upvotes: 1

Related Questions