2

I want to have a .cuh file where I can declare kernel functions and host functions as well. The implementation of these functions will be made inside the .cu file. The implementation will include the use of the Thrust library.

In the main.cpp file I would like to use the implementation that is inside the .cu file. So let's say we have something like this:

myFunctions.cuh

#include <thrust/sort.h>
#include <thrust/device_vector.h>
#include <thrust/remove.h>
#include <thrust/host_vector.h>
#include <iostream>

__host__ void show();

myFunctions.cu

#include "myFunctions.cuh"

__host__ void show(){
   std::cout<<"test"<<std::endl;
}

main.cpp

#include "myFunctions.cuh"

int main(void){

    show();

    return 0;
}

If I compile by doing this:

nvcc myFunctions.cu main.cpp -O3

And then run the executable by typing ./a.out

The test text will be printed.

However, if I decide to include -std=c++0x by using the following command:

nvcc myFunctions.cu main.cpp -O3 --compiler-options "-std=c++0x"

I get a lot of errors, some of which are the following:

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: identifier "nullptr" is undefined

/usr/include/c++/4.6/x86_64-linux-gnu/./bits/c++config.h(159): error: expected a ";"

/usr/include/c++/4.6/bits/exception_ptr.h(93): error: incomplete type is not allowed

/usr/include/c++/4.6/bits/exception_ptr.h(93): error: expected a ";"

/usr/include/c++/4.6/bits/exception_ptr.h(112): error: expected a ")"

/usr/include/c++/4.6/bits/exception_ptr.h(114): error: expected a ">"

/usr/include/c++/4.6/bits/exception_ptr.h(114): error: identifier "__o" is undefined

What do these errors mean and how can I avoid them?

Thank you in advance

ksm001
  • 3,772
  • 10
  • 36
  • 57
  • 1
    You might be interested in [this SO question](http://stackoverflow.com/questions/12073828/c-version-supported-by-cuda-5-0) and it's answers. Probably the simplest solution is to restrict your usage of things that actually require c++0x features to .cpp files – Robert Crovella Apr 22 '13 at 14:55
  • I thought c++11 was a newer version than c++0x and that's why it's not supported. However, I would still want to use c++0x in the .cpp files, is this possible? thank you. If you want you can make an answer so that I can accept. – ksm001 Apr 22 '13 at 15:24

1 Answers1

5

If you look at this specific answer, you'll see the user is compiling an empty dummy app with the same switch you are using and getting some of the exact same errors. If you restrict the usage of that switch to compiling .cpp files, you'll probably have better results:

myFunctions.h:

void show();

myFunctions.cu:

#include <thrust/sort.h>
#include <thrust/device_vector.h>
#include <thrust/remove.h>
#include <thrust/host_vector.h>
#include <thrust/sequence.h>
#include <iostream>

#include "myFunctions.h"

void show(){
  thrust::device_vector<int> my_ints(10);
  thrust::sequence(my_ints.begin(), my_ints.end());
  std::cout<<"my_ints[9] = "<< my_ints[9] << std::endl;
}

main.cpp:

#include "myFunctions.h"

int main(void){

    show();

    return 0;
}

build:

g++ -c -std=c++0x main.cpp
nvcc -arch=sm_20 -c myFunctions.cu 
g++ -L/usr/local/cuda/lib64 -lcudart -o test main.o myFunctions.o
Community
  • 1
  • 1
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257