# Using cling with CUDA enabled

**URL:** <https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434>\
**Category:** Newbie\
**Tags:** cling\
**Created:** [October 27, 2021, 9:28pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434 "2021-10-27T21:28:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alstown](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/d2c977/32.png) [@alstown](https://root-forum.cern.ch/u/alstown)\
**Post date:** [October 27, 2021, 9:28pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/1 "2021-10-27T21:28:26Z")

</div>

I would ultimately like to use Cling + CUDA in a Jupyter notebook if this is not the right place for this please let me know.

Is there usage documentation elsewhere for Cling + CUDA?  
I have looked regarding CUDA usage in the following:  
(I’m not allowed to put full links)  
gorepl /docs/cling.html  
cdn.jsdelivr /gh/root-project/cling@master/www/index.html  
github/rootproject/cling

Is CUDA just natively supported with the Cling prebuilt binaries? From the release notes it looks as if it is at least being worked on. If it is supported what is the canonical way to use it?

I have seen the github project ComputationalRadiationPhysics/xeus-cling-cuda-container, however it was last updated 16 months ago and looks to be using older versions of both NVIDIA and cling.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 28, 2021, 6:45am UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/2 "2021-10-28T06:45:15Z")

</div>

Welcome to the ROOT Forum! Maybe @vvassilev or @Axel can give an answer to this

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [October 28, 2021, 12:58pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/3 "2021-10-28T12:58:57Z")

</div>

@SimeonEhrig should we create some documentation on this? 🙂

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [October 28, 2021, 1:03pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/4 "2021-10-28T13:03:53Z")

</div>

> **[GTC 2020: CUDA C++ in Jupyter: Adding CUDA Runtime Support to Cling](https://developer.nvidia.com/gtc/2020/video/s21588-vid)**

> <https://github.com/root-project/cling/issues/115>
>
> Hi ROOT team,
> 
> I am opening this issue to document and discuss our plan to add… CUDA support to Cling. Maybe someone can open and link an issue on https://root.cern/bugs, I neither have a CERN nor an external account and the tracker is not public for people without registration :)
> 
> The discussion started after a post of mine in the cling-dev mailing list, where @Axel-Naumann picked me up and we spinned of a longer private discussion.
> 
> \> On 07.11.2016 10:34, Huebl, Axel wrote:
> \> \[...\] I am trying to compile a simple CUDA program, which is supported by clang
> \> already:
> \> 
> \> \[...\] internal include issues when starting cling via
> \> ./cling -x cuda --cuda-path=$CUDA\_ROOT --cuda-gpu-arch=sm\_35
> \-L$CUDA\_ROOT/lib -lstdc++ -lcudart \[...\]
> 
> By now, @Axel-Naumann did already fix all issues during startup and we think we are now at the point where one could work on accessing clang's PTX emitter to generate PTX code and then pass it to the driver API.
> 
> \`\`\`
> $ cling -x cuda --cuda-gpu-arch=sm\_35 -nocudainc
> atexit not in Module!
> at\_quick\_exit not in Module!
> 
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* CLING \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> \* Type C++ code and press enter to run it \*
> \* Type .q to exit \*
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> \[cling\]$ 
> \`\`\`
> 
> Clang currently translates CUDA code by linking the PTX code in a fat binary and passing it the CUDA driver during runtime, which generates SASS code (shader assembly) from it to execute. This is similar to what \`nvcc\` provides, besides that \`nvcc\` can additionally generate and link \`SASS\` code for a specific compute architecture directly, but that's not important here (\[see this page for further details\](http://llvm.org/docs/CompileCudaWithLLVM.html)).
> 
> From our discussions I understood, that cling already has similar functionality for e.g. \[PowerPC\](https://github.com/root-mirror/cling/blob/097a4e3fbd38b211709a8f5a2c5fb0bc5fe715e3/lib/Interpreter/IncrementalExecutor.cpp#L68) in place to target specific emitters and execute their assembler artifacts. Can you guide us how one could add the same functionality for PTX?
> 
> At \[GCoE Dresden\](http://www.gcoe-dresden.de), which is a collaboration of research groups in and around Dresden (Technical University, Max-Planck, Helmholtz-Zentrum Dresden-Rossendorf), we are currently discussing the possibilities for interactive simulations, RT profiling and tuning, teaching, rapid prototyping and interactive simulations and much more that one could get from a CUDA capable interpreter. Long story short: exciting possibilities!
> 
> From what I know about the routines in ROOT, there is no wide spread manycore or GPU acceleration available up to now. Adding CUDA support from cling will provide native CUDA support in your framework which is probably something that could be of interest from your side. Maybe you also want to build on that and directly add general manycore support \[in a more performance portable and abstract way\](https://github.com/ComputationalRadiationPhysics/alpaka), a topic on which we have experience, too.
> 
> We have currently one interested student that could work on the topic and any support and docs would be greatly appreciated. Two other groups from TU Dresden and Max-Planck also seemed interested and we might be able to contribute further resources (although that is not up to me). Due to our GCoE we also have a fruitful collaboration with Nvidia, which might be necessary, too.
> 
> CCing @harrism you might be \[interested\](https://twitter.com/harrism/status/795400414309023744) in this thread.

> [@ROOT, cling and SYCL](https://root-forum.cern.ch/t/root-cling-and-sycl/46014):
>
> Hello dev’s, I was wondering what are the team’s thought / plans with respect to SYCL. Is there a potential future support of it within ROOT / cling envisioned? Or only later after it is shown whether the SYCL project is widely accepted / used? See: [https://intel.github.io/llvm-docs/CompilerAndRuntimeDesign.html#sycl-support-in-clang-front-end](https://intel.github.io/llvm-docs/CompilerAndRuntimeDesign.html#sycl-support-in-clang-front-end)[https://sc20.supercomputing.org/proceedings/bof/bof\_pages/bof155.html](https://sc20.supercomputing.org/proceedings/bof/bof_pages/bof155.html)

---

<div class="post-metadata">

**Author:** ![SimeonEhrig](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/simeonehrig/32/27066_2.png) [@SimeonEhrig](https://root-forum.cern.ch/u/SimeonEhrig)\
**Post date:** [October 29, 2021, 7:13pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/5 "2021-10-29T19:13:52Z")

</div>

I think we can do it. There are some known issues, but since the CUDA mode is used with Clad, I think it makes sense to make it public. And maybe we can find someone to work on this feature too 😉

---

<div class="post-metadata">

**Author:** ![fecet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fecet/32/34016_2.png) [@fecet](https://root-forum.cern.ch/u/fecet)\
**Post date:** [August 1, 2023, 9:57am UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/6 "2023-08-01T09:57:33Z")

</div>

I’m also interested write cuda code with cling and the latest cling have added cuda support. How can I start to setup it? Thans you for any inputs!

---

<div class="post-metadata">

**Author:** ![riya\_bisht](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/riya_bisht/32/35967_2.png) [@riya\_bisht](https://root-forum.cern.ch/u/riya_bisht)\
**Post date:** [March 17, 2024, 3:10pm UTC](https://root-forum.cern.ch/t/using-cling-with-cuda-enabled/47434/7 "2024-03-17T15:10:48Z")

</div>

Hey,  
Did you find out a way to setup it? I am also experimenting with Cuda and Cling integration.
