# How to build NVidia binaries using CMake's new HIP language?

**URL:** https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208
**Category:** Code
**Tags:** os:linux, gen:ninja, gen:makefiles
**Created:** [October 5, 2021, 9:40am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208 "2021-10-05T09:40:59Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![krasznaa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krasznaa/32/893_2.png) [@krasznaa](https://discourse.cmake.org/u/krasznaa)
#### Post date: [October 5, 2021, 9:40am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/1 "2021-10-05T09:40:59Z")

</div>

I’ve updated my code recently to make use of the “HIP language”, introduced in 3.21.

After some initial success on a host with an AMD card, I was now trying to build some code on a host that has an NVidia card. And had to realise that I don’t know how to do that. What environment/cache variable can one use to tell the build that it should use `HIP_PLATFORM=nvidia`? Unfortunately looking through the CMake source code I didn’t find any hint about this. ☹

Cheers,  
Attila

---

<div class="post-metadata">

### Author: ![zackgalbreath](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zackgalbreath/32/94_2.png) [@zackgalbreath](https://discourse.cmake.org/u/zackgalbreath)
#### Post date: [October 7, 2021, 3:52pm UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/2 "2021-10-07T15:52:37Z")

</div>

I believe you’re correct, this isn’t working properly yet. I’ll let you know when we have a MR up so you can try it out if you’re interested.

---

<div class="post-metadata">

### Author: ![krasznaa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krasznaa/32/893_2.png) [@krasznaa](https://discourse.cmake.org/u/krasznaa)
#### Post date: [October 7, 2021, 4:20pm UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/3 "2021-10-07T16:20:45Z")

</div>

Sounds good! Yes, please let me know, I’ll give it a spin.

---

<div class="post-metadata">

### Author: ![wme7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wme7/32/3336_2.png) [@wme7](https://discourse.cmake.org/u/wme7)
#### Post date: [April 12, 2023, 7:07am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/4 "2023-04-12T07:07:06Z")

</div>

Hello @zackgalbreath and @krasznaa, any progress on this topic?

I’m experiencing the same problem with a [test library](https://www.reddit.com/r/cmake/comments/12iknc9/building_crossplataform_libraries_with_hip_in_c/) that I built on a **AMD platform** and then try to move it on **NVIDIA platform**.

I’m using CMake 3.26 at the moment, but perhaps there, is by now, a proper path to address `hip` compilations on NVIDIA platforms. 🤔

---

<div class="post-metadata">

### Author: ![krasznaa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krasznaa/32/893_2.png) [@krasznaa](https://discourse.cmake.org/u/krasznaa)
#### Post date: [April 13, 2023, 11:57am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/5 "2023-04-13T11:57:47Z")

</div>

Hi Manuel,

Since in our code we don’t use HIP all too seriously (there’s just some basic infrastructure for using it, but no actual “algorithmic code”), I lost track of this. (Our build still uses [my hand-written implementation](https://github.com/acts-project/vecmem/tree/main/cmake/hip) for this.)

I would still be very keen on switching to a centrally managed implementation. So if there’s any update around this, I would also be very interested in knowing about it…

Cheers,  
Attila

---

<div class="post-metadata">

### Author: ![wme7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wme7/32/3336_2.png) [@wme7](https://discourse.cmake.org/u/wme7)
#### Post date: [April 26, 2023, 1:15pm UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/6 "2023-04-26T13:15:09Z")

</div>

Hi Attila,

After scratching my head with this problem for the last week. I managed to archive a working solution 😄

In [this example](https://github.com/wme7/devLibrary), I demonstrate the only work around I was able to obtain in order to produce a truly cross-platform sample library using HIP/CUDA and CMake in a clean/simply manner.

I would appreciate any feedback/critic on this approach 🤔

kind regards,  
Manuel

---

<div class="post-metadata">

### Author: ![krasznaa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krasznaa/32/893_2.png) [@krasznaa](https://discourse.cmake.org/u/krasznaa)
#### Post date: [September 11, 2023, 2:02pm UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/7 "2023-09-11T14:02:05Z")

</div>

Hi Manuel,

Sorry for never replying to this. ☹ Don’t have a good excuse, I just forgot. ☹

That example is fine for what it’s doing, but it’s not really what this thread is about. One can use the runtime API of HIP fairly easily from CMake. Even without support being in CMake directly, one can use the code coming with ROCm.

[https://rocm.docs.amd.com/en/latest/understand/cmake\_packages.html#consuming-the-hip-api-in-c-code](https://rocm.docs.amd.com/en/latest/understand/cmake_packages.html#consuming-the-hip-api-in-c-code)

Very similar to what you do in that example…

But what I’m after is building “device code” for an NVIDIA or AMD backend from the same HIP code. Currently I do this in a very fragile way in our code, with:

> <https://github.com/acts-project/vecmem/blob/main/cmake/hip/CMakeDetermineHIPCompiler.cmake#L106-L135>

But ideally I’d prefer CMake to provide a global `CMAKE_HIP_PLATFORM` global cache variable, and a target specific `HIP_PLATFORM` property, which could be used to control what backend any piece of HIP code would be compiled/linked for. And that would need some further development from somebody. Not sure exactly who…

Cheers,  
Attila

---

<div class="post-metadata">

### Author: ![wme7](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wme7/32/3336_2.png) [@wme7](https://discourse.cmake.org/u/wme7)
#### Post date: [February 3, 2025, 10:05am UTC](https://discourse.cmake.org/t/how-to-build-nvidia-binaries-using-cmakes-new-hip-language/4208/8 "2025-02-03T10:05:06Z")

</div>

Thx @krasznaa for your sharing, I truly find your CMakeLists insightful !

Is my time to apologize because I just noticed your response until today.  
(… and reactivated my forum account)

It is true, my goal is not just using HIP to build NVidia binaries, but to have a single code that can build AMD or NVidia binaries with CMake reliably. But, I wish my code to only support CUDA on **NVidia** and HIP on **AMD platform** , strictly.

Just as an update, I’m coming back to explore HIP for the second time, and I can see a lot of progress on HIP 6.2.4 although the support for HIP on **NVidia** still limited. However, this time I found an easier time by controlling the language and linkage properties of the sources. To the point of being able to generate NVidia binaries from HIP reliably.

Moreover, we can now specify a `CMAKE_HIP_PLATFORM` finally (like for a `CUDA` build). Here I leave an update of my old [snippets](https://github.com/wme7/devLibrary) to reflect what I have learned so far.
