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

查看:137
本文介绍了在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:

main.cu

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

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

define.h
$ b

defines.h

#include <cuda.h>

extern __global__ void hello(void);

definitions.cu

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

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

使用:

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_30 以匹配您的设备,但是这不是您所观察到的失败的原因,请在上面的命令中使用code> sm_20 为 -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天全站免登陆