CUDA 中的单独编译 [英] separate compilaton in CUDA

查看:22
本文介绍了CUDA 中的单独编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

系统规格:支持 nvidia optimus 的笔记本电脑(geforce 740m,支持计算能力 2.0)、ubuntu 13.10、cuda 5.0、optirun (Bumblebee) 3.2.1.

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:

ma​​in.cu

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

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

定义.h

#include <cuda.h>

extern __global__ void hello(void);

defines.cu

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

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

使用:

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

当我尝试使用以下命令运行输出 a.out 文件时:

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

optirun ./a.out

我没有听到你好!"在控制台中.可能是什么问题?

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

推荐答案

这不对:

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.

试试这个:

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

相关的 nvcc 文档是 这里

或者,按照您链接的示例,您也可以这样做:

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

正如@JackOLantern 指出的那样,您可能希望将上述命令中的 sm_20 替换为 sm_30 以匹配您的设备,但这不是您失败的原因正在观察.为 -arch=sm_20 编译的代码将在 cc 3.0 设备上运行.

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.

这篇关于CUDA 中的单独编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆