validation of CUDA installation

#include "stdio.h"
int main()
{
 printf("Hello, world\n");
 return 0;
}
nvcc hello1.cu
./a.out 
Hello, world
#include "stdio.h"
__global__ void add(int a, int b, int *c)
{
 *c = a + b;
}
int main()
{
int a,b,c;
int *dev_c;
a=3;
b=4;
cudaMalloc((void**)&dev_c, sizeof(int));
add<<<1,1>>>(a,b,dev_c);
cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}
nvcc add.cu
./a.out 
3 + 4 is 7
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Mon_Mar_11_22:13:24_CDT_2019
Cuda compilation tools, release 10.0, V10.0.326
/usr/local/cuda-10.0/samples/5_Simulations/oceanFFT$  sudo SMS=72 EXTRA_LDFLAGS=–unresolved-symbols=ignore-in-shared-libs TARGET_ARCH=aarch64 make
/usr/local/cuda-10.0/bin/nvcc -ccbin g++   -m64     -Xlinker –unresolved-symbols=ignore-in-shared-libs -gencode arch=compute_72,code=sm_72 -gencode arch=compute_72,code=compute_72 -o oceanFFT oceanFFT.o oceanFFT_kernel.o  -L/usr/lib/nvidia-container-csv-cuda -lGL -lGLU -lglut -lcufft
/usr/bin/ld: cannot find –unresolved-symbols=ignore-in-shared-libs: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:314: recipe for target 'oceanFFT' failed
make: *** [oceanFFT] Error 1

working examples are from:
http://www.math.uaa.alaska.edu/~afkjm/cs448/handouts/cuda-firstprograms.pdf

Hi,

Would you mind to explain more about your issue?
It looks like the first sample is working but our oceanFFT sample is failed?

Thanks.

I was trying to troubleshoot with Microsoft guys onnxruntime build procedure which used to fail at execution of the code

file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.cu
    "#ifndef __CUDACC__\n"
    "# error \"The CMAKE_CUDA_COMPILER is set to an invalid CUDA compiler\"\n"
    "#endif\n"
    "int main(){return 0;}\n")

as

/usr/local/cuda-10.0/bin/nvcc -cudart shared -Xcompiler=-fPIE -x cu -c /code/onnxruntime/build/Linux/Release/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_bb43d.dir/main.cu.o

https://github.com/microsoft/onnxruntime/issues/3024#issuecomment-586781469

the last state of theissue is as follows:

which works is:

/usr/local/cuda-10.0/bin/nvcc -cudart shared -Xcompiler=-fPIE -x cu -c <path to>/hello1.cu -o <path to>/hello1.cu.o

however, the below wont work:

/usr/bin/g++ <path to>/hello1.cu.o -o hello1 -lcudadevrt -lcudart_static -L"/usr/local/cuda-10.0/targets/aarch64-linux/lib/stubs" -L"/usr/local/cuda-10.0/targets/aarch64-linux/lib" -lcudadevrt -lcudart

output.log (15 KB)

Hi,

A cuda program need to be compiled with nvcc.
It won’t work to compile it by a standard g++ with cuda linked.

Do I answer your question?

Thanks.

Thanks,
got it!