# How to separate device function and kernel function?

**URL:** <https://forums.developer.nvidia.com/t/how-to-separate-device-function-and-kernel-function/13383>\
**Category:** CUDA Programming and Performance\
**Created:** [November 22, 2009, 9:40am UTC](https://forums.developer.nvidia.com/t/how-to-separate-device-function-and-kernel-function/13383 "2009-11-22T09:40:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wlx](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wlx](https://forums.developer.nvidia.com/u/wlx)\
**Post date:** [November 22, 2009, 9:40am UTC](https://forums.developer.nvidia.com/t/how-to-separate-device-function-and-kernel-function/13383/1 "2009-11-22T09:40:05Z")

</div>

I would like to run a complicate model in CUDA, and I just want to organize the code just like the C/C++ way, the header code and the implementation code.

But when I try to this, just separate the kernel function and the device function, relink them with the header file, get the error:

```auto
Error: External calls are not supported

```

So, is it possible to separate the kernel function and the device function?

Thanks.

---

<div class="post-metadata">

**Author:** ![avidday](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/avidday/32/59219_2.png) [@avidday](https://forums.developer.nvidia.com/u/avidday)\
**Post date:** [November 22, 2009, 9:46am UTC](https://forums.developer.nvidia.com/t/how-to-separate-device-function-and-kernel-function/13383/2 "2009-11-22T09:46:50Z")

</div>

There is no device code linker in CUDA, so everything a kernel uses ( **device** functions, **constant** definitions, texture definitions, etc) must be included in the same compilation unit as the kernel itself. This means that you can put device function code in another file if you like, but you must include that file into the file containing your kernel code at compilation time. Just a prototype isn’t sufficient, because **device** functions are inlined by the compiler, so the code must also be present at compile time.

---

<div class="post-metadata">

**Author:** ![wlx](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@wlx](https://forums.developer.nvidia.com/u/wlx)\
**Post date:** [November 22, 2009, 12:37pm UTC](https://forums.developer.nvidia.com/t/how-to-separate-device-function-and-kernel-function/13383/3 "2009-11-22T12:37:10Z")

</div>

Thanks.
