相关疑难解决方法(0)

CUDA __device__未解析的extern函数

我试图了解如何__device__在单独的头文件中解耦CUDA 代码.

我有三个文件.

文件:1:int2.cuh

#ifndef INT2_H_
#define INT2_H_

#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

__global__ void kernel();
__device__ int k2(int k);

int launchKernel(int dim);

#endif /* INT2_H_ */
Run Code Online (Sandbox Code Playgroud)

文件2:int2.cu

#include "int2.cuh"
#include "cstdio"

__global__ void kernel() {
    int tid = threadIdx.x;
    printf("%d\n", k2(tid));
}

__device__ int k2(int i) {
    return i * i;
}

int launchKernel(int dim) {
    kernel<<<1, dim>>>();
    cudaDeviceReset();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

文件3:CUDASample.cu

include <stdio.h>
#include <stdlib.h>
#include "int2.cuh"
#include "iostream"

using namespace std;

static const …
Run Code Online (Sandbox Code Playgroud)

c c++ cuda linker-errors

11
推荐指数
1
解决办法
9866
查看次数

不支持CUDA外部呼叫

我正在开发一个在Fermi卡上运行的CUDA 4.0应用程序.根据规范,Fermi具有Compute Capability 2.0,因此应该支持非内联函数调用.

我在一个不同的obj文件中用nvcc 4.0编译我的每个类.然后,我用g ++ - 4.4将它们全部链接起来.

请考虑以下代码:

[文件A.cuh]

#include <cuda_runtime.h>

struct A
{
    __device__ __host__ void functionA();
};
Run Code Online (Sandbox Code Playgroud)

[文件B.cuh]

#include <cuda_runtime.h>

struct B
{
    __device__ __host__ void functionB();
};
Run Code Online (Sandbox Code Playgroud)

[File A.cu]

#include "A.cuh"
#include "B.cuh"

void A::functionA()
{
    B b;
    b.functionB();
}
Run Code Online (Sandbox Code Playgroud)

试图编译A.cu与nvcc -o A.o -c A.cu -arch=sm_20输出Error: External calls are not supported (found non-inlined call to _ZN1B9functionBEv).

一定做错了什么,但是什么?

cuda

9
推荐指数
1
解决办法
5601
查看次数

标签 统计

cuda ×2

c ×1

c++ ×1

linker-errors ×1