# Using CMake with NVidia's CUDA

**URL:** https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698
**Category:** Usage
**Created:** [August 12, 2020, 8:55pm UTC](https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698 "2020-08-12T20:55:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hungry-snorlax](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hungry-snorlax/32/615_2.png) [@hungry-snorlax](https://discourse.cmake.org/u/hungry-snorlax)
#### Post date: [August 12, 2020, 8:55pm UTC](https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698/1 "2020-08-12T20:55:22Z")

</div>

Hello, I have a cuda file (.cu) which does not have a main point of entry. I am able to compile it on the terminal using nvcc and a bunch of nvcc compile options to a .cubin (CUDA binary).

Could someone please tell me how I can do that in CMake. I am able to go from .cu to .ptx (an intermediate object), but not .cu to .cubin. What commands do I have to use in my CMakeLists.txt. I know that you can either use FindCUDA (deprecated) or the built-in CUDA language support to use CUDA. I am using the built-in CUDA language support and CMake 3.17. What commands to I need to compile my .cu file to a .cubin.

Thank you.

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [August 14, 2020, 12:35pm UTC](https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698/2 "2020-08-14T12:35:44Z")

</div>

The built-in CUDA language support only offers `.cu` to `.ptx` and `.cu` to `.obj` support, it doesn’t offer `.cu` to `.cubin`.

You could use the support to go from `.cu` to `.ptx` and use something like custom POST\_BUILD commands to transform the PTX files to `.cubin`

---

<div class="post-metadata">

### Author: ![mnicely](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mnicely/32/807_2.png) [@mnicely](https://discourse.cmake.org/u/mnicely)
#### Post date: [September 2, 2020, 12:15pm UTC](https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698/3 "2020-09-02T12:15:52Z")

</div>

Hi Robert,

Given your response and the fact that that `--ptx` option is not allowed when compiling for multiple GPU architectures. If a user wants to compile a fatbin for architectures, would that have to be accomplished with foreach or something?

This seems like a limitation to CMake… Can you provide any insight to why the functionality was removed from findCUDAToolkit?

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [September 8, 2020, 1:32am UTC](https://discourse.cmake.org/t/using-cmake-with-nvidias-cuda/1698/4 "2020-09-08T01:32:51Z")

</div>

> [@mnicely](#):
>
> Given your response and the fact that that `--ptx` option is not allowed when compiling for multiple GPU architectures. If a user wants to compile a fatbin for architectures, would that have to be accomplished with foreach or something?

If you are not interested in generating a full object file the best option is to have multiple targets with the same sources but different architectures specified.

> [@mnicely](#):
>
> This seems like a limitation to CMake… Can you provide any insight to why the functionality was removed from findCUDAToolkit?

Goal was to provide support for the common code generation types. PTX and full object files matched that goal. Nothing is stopping CMake from supporting fatbin generation it just hasn’t been a priority for contributors.
