# NVCC at Runtime - End User Friendly Configuration Compiling GPU code without requiring Visual Studio

**URL:** <https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089>\
**Category:** CUDA Programming and Performance\
**Created:** [June 11, 2009, 3:13pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089 "2009-06-11T15:13:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keldor314](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Keldor314](https://forums.developer.nvidia.com/u/Keldor314)\
**Post date:** [June 11, 2009, 3:13pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/1 "2009-06-11T15:13:26Z")

</div>

What’s the best way to compile a kernal at runtime, assuming that I want minimal requirements for what the end user must install to get it working? Is there a way to run NVCC to compile GPU only code without requiring cl.exe?

I know that pyCUDA offers runtime compilation of kernals, but getting it installed and running is far more involved that I can reasonably expect the end user to figure out. What I need is a self-contained, user friendly way to allow user customized kernals to be compiled and executed on the fly.

My application is a flame fractal viewer, and one of my goals is to allow the user to enter in custom formulas and explore the fractals they produce.

---

<div class="post-metadata">

**Author:** ![cvnguyen](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@cvnguyen](https://forums.developer.nvidia.com/u/cvnguyen)\
**Post date:** [June 11, 2009, 8:35pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/2 "2009-06-11T20:35:41Z")

</div>

You must have another compiler/linker to generate the host code. NVCC generates only the GPU code and invokes the other to build the whole program. In the meantime, CUDA for Win only supports Visual C++ compiler, so there is no way to avoid it.

You may let the users compile code in Linux or have a dedicated server receiving customized code, compiling them, and sending back to the users.

---

<div class="post-metadata">

**Author:** ![tmurray](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tmurray](https://forums.developer.nvidia.com/u/tmurray)\
**Post date:** [June 11, 2009, 8:39pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/3 "2009-06-11T20:39:08Z")

</div>

generate PTX and JIT?

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [June 11, 2009, 11:08pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/4 "2009-06-11T23:08:23Z")

</div>

You’ll need to ship nvcc with your application, and call it from your program, but I’m not sure that EULA allows it.

You can also switch to OpenCL, it supports dynamic compilation.

---

<div class="post-metadata">

**Author:** ![jph4599](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jph4599](https://forums.developer.nvidia.com/u/jph4599)\
**Post date:** [June 12, 2009, 12:58pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/5 "2009-06-12T12:58:25Z")

</div>

> [@](#):
>
> generate PTX and JIT?

Is that what this post is talking about?

> [@](#):
>
> Now it is possible to run a PTX file directory using the driver level API. But you have to pass in parameters and configure the call directly using API calls:
> 
> see:
> 
> cuModuleLoad
> 
> cuModuleGetFunction
> 
> cuParamSetSize
> 
> cuFuncSetBlockShape
> 
> cuFuncSetSharedSize
> 
> cuParamSetv
> 
> cuLaunchGrid
> 
> and use nvcc --ptx to generate a text file that can be loaded by cuModuleLoad

That means in order to “allow the user to enter in custom formulas”, Keldor314 would have to dynamically turn the user input into PTX and insert it into the file resulting from nvcc --ptx?

---

<div class="post-metadata">

**Author:** ![thstart](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@thstart](https://forums.developer.nvidia.com/u/thstart)\
**Post date:** [June 13, 2009, 2:50am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/6 "2009-06-13T02:50:36Z")

</div>

> [@](#):
>
> You’ll need to ship nvcc with your application, and call it from your program, but I’m not sure that EULA allows it.
> 
> You can also switch to OpenCL, it supports dynamic compilation.

OpenCL - when it is expected to be released? I registered as developer but still

do not get any response.

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [June 13, 2009, 5:59am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/7 "2009-06-13T05:59:10Z")

</div>

> [@](#):
>
> OpenCL - when it is expected to be released?

don’t know, hopefully not so far from here

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [June 14, 2009, 12:47pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/8 "2009-06-14T12:47:09Z")

</div>

> [@](#):
>
> You must have another compiler/linker to generate the host code. NVCC generates only the GPU code and invokes the other to build the whole program. In the meantime, CUDA for Win only supports Visual C++ compiler, so there is no way to avoid it.

Some of the Microsoft SDKs come with a compiler and linker (notably lacking any GUI IDEs) - but it is a version of the Visual C++ Compiler.

---

<div class="post-metadata">

**Author:** ![Keldor314](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Keldor314](https://forums.developer.nvidia.com/u/Keldor314)\
**Post date:** [June 16, 2009, 6:01pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/9 "2009-06-16T18:01:26Z")

</div>

Basically, I just want to compile a kernal. Pure GPU code, so why is cl.exe needed? Running nvcc --ptx still causes it to complain about cl.exe missing from the path. It would be nice to be able to invoke NVCC just to produce some PTX, without touching CPU side stuff at all.

What would really be nice is a cuCompileModule() function that takes a .cu file and compiles all the GPU code. We have this for DirectX shaders, OpenCL (when it is released), why not for cuda?

---

<div class="post-metadata">

**Author:** ![tmurray](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tmurray](https://forums.developer.nvidia.com/u/tmurray)\
**Post date:** [June 16, 2009, 6:09pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/10 "2009-06-16T18:09:54Z")

</div>

because the front end still depends on a number of compiler-specific options to guarantee correctness (e.g., sizeof(type) on the device == sizeof(type) on the host). OCL doesn’t necessarily make these guarantees because of how it handles memory, these guarantees don’t make sense for shaders, so CUDA is a special case.

---

<div class="post-metadata">

**Author:** ![Keldor314](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Keldor314](https://forums.developer.nvidia.com/u/Keldor314)\
**Post date:** [June 16, 2009, 6:24pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/11 "2009-06-16T18:24:40Z")

</div>

Hmm. I see. Is there a way to work around that - embed the necessary data in the host exe and have the compile use that? So long as the compiler specific stuff is known at runtime, correctness wouldn’t be a problem assuming that the correctness dependent data was passed along.

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [June 16, 2009, 8:54pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/12 "2009-06-16T20:54:47Z")

</div>

Compiler is only used as a preprocessor if you generate device data only (i.e. -ptx or -cubin flag). You can bundle a preprocessor (named cl.exe) and nvcc.exe with your app and do compilations at runtime.

---

<div class="post-metadata">

**Author:** ![Keldor314](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Keldor314](https://forums.developer.nvidia.com/u/Keldor314)\
**Post date:** [June 16, 2009, 10:22pm UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/13 "2009-06-16T22:22:30Z")

</div>

What things are done in the preprocessing stage by cl.exe?

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [June 17, 2009, 12:34am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/14 "2009-06-17T00:34:28Z")

</div>

> [@](#):
>
> What things are done in the preprocessing stage by cl.exe?

http://en.wikipedia.org/wiki/C\_preprocessor

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [June 17, 2009, 11:51am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/15 "2009-06-17T11:51:12Z")

</div>

It would be possible to create a wrapper around GCC named “cl.exe” that translates Visual Studio’s command line options into GCC compiler options. One only needs to support the options used by the CUDA frontend.

A windows native GCC implementation is available in a package called MinGW - it does not have a lot of extra dependencies.

---

<div class="post-metadata">

**Author:** ![Keldor314](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Keldor314](https://forums.developer.nvidia.com/u/Keldor314)\
**Post date:** [June 19, 2009, 4:26am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/16 "2009-06-19T04:26:14Z")

</div>

Do any of you happen to know which options are used?

---

<div class="post-metadata">

**Author:** ![sergeyn](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sergeyn](https://forums.developer.nvidia.com/u/sergeyn)\
**Post date:** [June 19, 2009, 5:00am UTC](https://forums.developer.nvidia.com/t/nvcc-at-runtime-end-user-friendly-configuration-compiling-gpu-code-without-requiring-visual-studio/10089/17 "2009-06-19T05:00:55Z")

</div>

> [@](#):
>
> Do any of you happen to know which options are used?

when I compile a file with “nvcc --cubin kernels.cu” I get following calls to the compiler:

cl -D\_\_CUDA\_ARCH\_\_=100 -nologo -E -TP -DCUDA\_FLOAT\_MATH\_FUNCTIONS -DCUDA\_NO\_SM\_11\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_12\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_13\_DOUBLE\_INTRINSICS “-Ic:\Program Files\CUDA\bin/…/include” “-Ic:\Program Files\CUDA\bin/…/include/cudart” -I. -D\_\_CUDACC\_\_ -C -FI cuda\_runtime.h kernels.cu

cl -D\_\_CUDA\_ARCH\_\_=100 -nologo -E -TC -DCUDA\_FLOAT\_MATH\_FUNCTIONS -DCUDA\_NO\_SM\_11\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_12\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_13\_DOUBLE\_INTRINSICS “-Ic:\Program Files\CUDA\bin/…/include” “-Ic:\Program Files\CUDA\bin/…/include/cudart” -I. -D\_\_CUDACC\_\_ -C C:\Users\HomeUse\AppData\Local\Temp/tmpxft\_00000c14\_00000000-3\_kernels.cudafe1.gpu

cl -D\_\_CUDA\_ARCH\_\_=100 -nologo -E -TC -DCUDA\_FLOAT\_MATH\_FUNCTIONS -DCUDA\_NO\_SM\_11\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_12\_ATOMIC\_INTRINSICS -DCUDA\_NO\_SM\_13\_DOUBLE\_INTRINSICS “-Ic:\Program Files\CUDA\bin/…/include” “-Ic:\Program Files\CUDA\bin/…/include/cudart” -I. -D\_\_GNUC\_\_ -D\_\_CUDABE\_\_ C:\Users\HomeUse\AppData\Local\Temp/tmpxft\_00000c14\_00000000-8\_kernels.cudafe2.gpu
