# Accessing kernel name from .cubin Cuda Applied programming.

**URL:** <https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850>\
**Category:** CUDA Programming and Performance\
**Created:** [October 9, 2008, 5:39pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850 "2008-10-09T17:39:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![skchoe](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@skchoe](https://forums.developer.nvidia.com/u/skchoe)\
**Post date:** [October 9, 2008, 5:39pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/1 "2008-10-09T17:39:21Z")

</div>

Hello everyone.

I found when I use runtime API, the generated cubin file has different kernel name from  
what I defined in cu file. Is there anyway to keep the name same or we can get the new  
name from cubin file?

Thanks in advance.

SK.

---

<div class="post-metadata">

**Author:** ![frea](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@frea](https://forums.developer.nvidia.com/u/frea)\
**Post date:** [October 9, 2008, 7:26pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/2 "2008-10-09T19:26:04Z")

</div>

I don’t know of any, but the kernel name does depend only on the function prototype, so you could just read it by hand one, and use constatly :).

---

<div class="post-metadata">

**Author:** ![skchoe](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@skchoe](https://forums.developer.nvidia.com/u/skchoe)\
**Post date:** [October 9, 2008, 8:55pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/3 "2008-10-09T20:55:02Z")

</div>

That’s what I guessed. It works when using Driver API, not Runtime API.

You may ask back why we need the explicit name from cubin in Runtime API. But  
In runtime API, instead of calling matrixMul\<\<thread, block\>\> (args…),  
I wanted to use driver API.

Actually I was sucessful when use the block of program using driver API with runtime API.  
Runtime API : For cudaMalloc(), cudaMemcpy().  
driver API: cuModuleLoad(), cuParamSet(), cuFuncSetBlockSize(), cuLaunchGrid().

The problem is that when I generate cubin file, the kernel name `matrixMul' in matrixMul_kernel.cu is changed to ` \_Z9matrixMulPfS\_S\_ii’ in the name field of code block.

How?  
`matrixMul' -----> ` \_Z9matrixMulPfS\_S\_ii’

This is one of my question.

Thanks.

SK.

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [October 9, 2008, 10:00pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/4 "2008-10-09T22:00:21Z")

</div>

> [@](#):
>
> `matrixMul' -----> ` \_Z9matrixMulPfS\_S\_ii’
> 
> [snapback]449886[/snapback]

This is because C++ name mangling is applied to the kernels. If you don’t want this, you can delcare the kernel

extern “C” **global** mykernel(…)

---

<div class="post-metadata">

**Author:** ![skchoe](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@skchoe](https://forums.developer.nvidia.com/u/skchoe)\
**Post date:** [October 9, 2008, 10:14pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/5 "2008-10-09T22:14:41Z")

</div>

> [@](#):
>
> This is because C++ name mangling is applied to the kernels.&nbsp; If you don’t want this, you can delcare the kernel
> 
> extern “C” **global** mykernel(…)
> 
> [snapback]449904[/snapback]

That works great. So I’ve only to focus on the name of kernel I named.

Is name mangling shows always same output? (I generated cubin several times but the

output of mangling was always same…)

SK.

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [October 9, 2008, 11:19pm UTC](https://forums.developer.nvidia.com/t/accessing-kernel-name-from-cubin-cuda-applied-programming/5850/6 "2008-10-09T23:19:14Z")

</div>

> [@](#):
>
> Is name mangling shows always same output?
> 
> [snapback]449915[/snapback]

Assuming the function signature is identical, then yes the mangled name will always be identical. That **is** the point of mangled names after all: a way for the compiler to generate and use unique function names for functions belonging to specific classes or with different template arguments. If it were random, the compiler would have an awfully hard time trying to link libraries and executables ;)

If you add an argument or change the type of an argument, then the mangled name will change.
