nvcc not supporting c++11, any tricks or suggestion for OSX Mavericks?

Hi all,

I was wondering if anyone has any tricks for OSX to get this working,

My issue is this, currently using OSX clang / llvm in mavericks and compiling c++ files with c11 subtleties separate from nvcc files and that works great. I purposely have removed all c11 specifics from the .cu files to make sure the everything compiles and it does.

However, on final linking it dies ;-(. Ive spent a great deal of time on this today and if anyone has any suggestion i would be very grateful. I would like to keep my development work portable and without this fix i wont be able to demo some of our work.

Ive tried installing gcc4.7.3 through brew, likewise build OpenMPI 1.8.1 with gcc via modifying the brew .rb file to specify gcc4.7.3 but no luck there. I tried this because on our linux workstation it compiles and links perfectly,

Please lmk and thanks so much for the help,

Here is the final error on link,
Undefined symbols for architecture x86_64:
“std::ios_base::Init::Init()”, referenced from:
__GLOBAL__I_a in CudaKernels.o
“std::ios_base::Init::~Init()”, referenced from:
__GLOBAL__I_a in CudaKernels.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am splitting compilation of my core project from compilation of CUDA kernels. In the main project I compile with g++ and c++11, while I create a “kernels” static library for CUDA using c++03. As the CXX_FLAGS are global (at least in cmake), I avoid them being propagated to the c++ compiler used by cuda with:
set(CUDA_PROPAGATE_HOST_FLAGS False)

Getting C++11 in at part of my code it’s better than nothing!

Did you already try CUDA 6.5? In principle it it possible to use c++11 starting with 6.5, but as far as I know this is a unofficial feature.

There is no partial support in 6.5 final release… specifying c++11 does nothing but flag an unknown and ignored option from nvcc.

Ive done a non-standard link to get things working, and it does, but would not suggest it to others as it could be problematic. Very strange though, as no c++11 is used in the kernel files compiled with nvcc…

That might be true on the mac. It’s not true on linux. There is a non-publicly-documented -std=c++11 switch which can be passed to nvcc, which alters its behavior (demonstrably, on linux, on CUDA 6.5).

As an example, if you use “auto” whether in host or device code, and compile it with nvcc (CUDA 6.5, linux), it will fail if you don’t specify -std=c++11:

$ cat t573.cu
#include <iostream>

__device__ float tdata = 2.0f;

template <typename T>
__host__ __device__ T square(T x){
 return x*x;
}

__global__ void mykernel(){

  auto y = square(tdata);
  printf("result = %f\n", y);
}

int main(){
  float hdata = 3.0f;
  auto res = square(hdata);
  printf("host result: %f\n", res);
  mykernel<<<1,1>>>();
  cudaDeviceSynchronize();
}
$ nvcc -arch=sm_20 -o t573 t573.cu
t573.cu(12): error: explicit type is missing ("int" assumed)

t573.cu(18): error: explicit type is missing ("int" assumed)

2 errors detected in the compilation of "/tmp/tmpxft_000005fa_00000000-8_t573.cpp1.ii".
$ nvcc -arch=sm_20 -std=c++11 -o t573 t573.cu
$

thats nice … seems like (official) partial support of C++ 11 features might come in the next cuda toolkit …