Max
Max

Reputation: 67

CUDA and C++, how to link cpp and cu files?

//Header file A.h
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
class A
{
   __host__ __device__ void move();
}

//cu file A.cu
#include "A.h"
{
   __host__ __device__ void A::move()
   {
      ...
   }
}

When calling the method defined in the A.cu file from another .cu file, I`m getting the following error:

External calls are not supported (found non-inlined call to ...),

I'm using the sm_10 compile option.

Upvotes: 1

Views: 3894

Answers (1)

Vitality
Vitality

Reputation: 21455

You need separate compilation. Separate compilation requires cards with compute capability at least 2.0 and at least CUDA 5.0.

Quoting the CUDA 5.0 Release Highlights:

All __device__ functions can now be separately compiled and linked using NVCC. This allows creation of closed-source static libraries of __device__ functions and the ability for these libraries to call user-defined __device__ callback functions. The linker support is considered to be a BETA feature in this release.

Separate compilation is described in Chapter 7 of the CUDA COMPILER DRIVER NVCC Reference Guide.

For those interested, there is a very good thread on separate compilation in the NVIDIA forum, see

How to create a static lib for device functions using cuda 5.0?

Upvotes: 3

Related Questions