# Calling a host function from within the device

**URL:** <https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785>\
**Category:** CUDA Programming and Performance\
**Created:** [November 1, 2011, 2:40pm UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785 "2011-11-01T14:40:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxest](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@maxest](https://forums.developer.nvidia.com/u/maxest)\
**Post date:** [November 1, 2011, 2:40pm UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785/1 "2011-11-01T14:40:46Z")

</div>

Exactly one year ago I used the current at the time CUDA version (don’t remember which one) and I wrote some CUDA kernels that made use of my vector class. This class has some functions, mostly overloaded operators. And they all worked fine. But today I downloaded that newest CUDA toolkit, try to compile my old project and…

```auto
error: calling a host function("vec3::operator +") from a __device__ / __global__ function("rasterizePixel") is not allowed

```

Is there a way to fix that? And I would prefer a way that avoids any modifications to vec3 class.

---

<div class="post-metadata">

**Author:** ![BioCoder](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/biocoder/32/10569_2.png) [@BioCoder](https://forums.developer.nvidia.com/u/BioCoder)\
**Post date:** [April 13, 2016, 3:15am UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785/2 "2016-04-13T03:15:10Z")

</div>

I have a same problem when I tried to compile julia\_gpu.cu (cuda\_by\_example/chapter04) with CUDA 7.5

Since Cuda By Example is a very old textbook, I guess CUDA of higher version has changed a lot and is not compatible with the old codes in the textbook.

Does anybody know how to solve this problem?

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [April 13, 2016, 3:44am UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785/3 "2016-04-13T03:44:02Z")

</div>

1. Try decorating the function in question with **host**  **device**
2. Check the cuda by example sample code, I think it may have the issue fixed:

[url][https://developer.nvidia.com/cuda-example[/url]](https://developer.nvidia.com/cuda-example%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![BioCoder](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/biocoder/32/10569_2.png) [@BioCoder](https://forums.developer.nvidia.com/u/BioCoder)\
**Post date:** [April 13, 2016, 3:54am UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785/4 "2016-04-13T03:54:24Z")

</div>

> [@](#):
>
> 1. Try decorating the function in question with **host**  **device**
> 2. Check the cuda by example sample code, I think it may have the issue fixed:
> 
> [https://developer.nvidia.com/cuda-example](https://developer.nvidia.com/cuda-example)

Well, you mean the codes in CUDA By Example have been updated?

---

<div class="post-metadata">

**Author:** ![BioCoder](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/biocoder/32/10569_2.png) [@BioCoder](https://forums.developer.nvidia.com/u/BioCoder)\
**Post date:** [April 13, 2016, 4:00am UTC](https://forums.developer.nvidia.com/t/calling-a-host-function-from-within-the-device/24785/5 "2016-04-13T04:00:00Z")

</div>

Unfortunately, however, the codes that I am using are the latest ones.
