Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

separate compilaton in CUDA

System specs: laptop with nvidia optimus support (geforce 740m, supports compute capability 2.0), ubuntu 13.10, cuda 5.0, optirun (Bumblebee) 3.2.1.

Im' trying to compile and run simpler version of example described here:

main.cu

#include "defines.h"
#include <cuda.h>

int main () 
{
    hello<<<1, 1>>>();
    cudaDeviceSynchronize();
}

defines.h

#include <cuda.h>

extern __global__ void hello(void);

defines.cu

#include <cstdio>
#include <cuda.h>

__global__ void hello()
{
    printf("Hello!
");
}

using:

nvcc –arch=sm_20 –dc main.cu defines.cu
nvcc –arch=sm_20 main.o defines.o

When I try to run output a.out file using:

optirun ./a.out

I get no "Hello!" in console. What can be the problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is not right:

nvcc –arch=sm_20 –dc main.cu defines.cu
nvcc –arch=sm_20 main.cu defines.cu

The first command performs compilation (but no linking) in separate compilation mode. The second command performs compilation and linking in one step, but without using separate compilation mode.

Try just this:

nvcc -arch=sm_20 -rdc=true main.cu defines.cu

The relevant nvcc documentation is here

Alternatively, and following the example you linked, you could also do this:

nvcc –arch=sm_20 –dc main.cu defines.cu
nvcc –arch=sm_20 main.o defines.o

As @JackOLantern points out, you may wish to replace sm_20 in the above commands with sm_30 to match your device, but that is not the reason for the failure you are observing. Code compiled for -arch=sm_20 will run on a cc 3.0 device.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...