# How to get a fast debug build

**URL:** https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597
**Category:** Uncategorized
**Created:** [October 23, 2023, 2:42pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597 "2023-10-23T14:42:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)
#### Post date: [October 23, 2023, 2:42pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597/1 "2023-10-23T14:42:40Z")

</div>

Following [Allow to specify specific files for debug info by albanD · Pull Request #111748 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/pull/111748) being merged, there is a new compilation flag that can be used to specify debug informations ONLY for a given subset of the source files via:

```auto
# Your usual build
BUILD_CONFIG python setup.py develop

# Enable debug mode for two files
BUILD_CONFIG python setup.py clean
USE_CUSTOM_DEBINFO=torch/csrc/Module.cpp;aten/src/ATen/native/cpu/SortingKernel.cpp BUILD_CONFIG python setup.py develop

```

If you use ccache (as you should), this will only recompile these two files and relink the binary. You will now have full debug info for these files!

This has two main benefits: going from your usual build to enabling debug infos only recompiles the files you care about and the final binary only has bebug info for these two files. This means it won’t be gigabytes big and will not slow gdb to a crawl!

Side note, @malfet has another trick to do this if you don’t like the clean:

```auto
touch path/to/file.cpp; ninja -n >build.sh; sed '-O3/-g' build.sh; sh -f build.sh

```

---

<div class="post-metadata">

### Author: ![malfet](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/malfet/32/129_2.png) [@malfet](https://dev-discuss.pytorch.org/u/malfet)
#### Post date: [November 29, 2023, 3:27pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597/2 "2023-11-29T15:27:08Z")

</div>

Here is the correct command (replace sed with gsed on MacOS):

```auto
ninja -j1 -v -n torch_cpu |sed -e 's/-O[23]/-g/g' -e 's#\[[0-9]\+\/[0-9]\+\] \+##' |sh

```

---

<div class="post-metadata">

### Author: ![ZelboK](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/zelbok/32/1310_2.png) [@ZelboK](https://dev-discuss.pytorch.org/u/ZelboK)
#### Post date: [May 4, 2024, 3:33pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597/3 "2024-05-04T15:33:58Z")

</div>

The python script, `BUILD_WITHDEBINFO` aren’t working well for me.

Let’s say I want to get debugging info for `aten/src/ATen/native/cuda/group_norm_kernel.cu`

I’ve tried:

`./tools/build_with_debinfo.py aten/src/ATen/native/cuda/group_norm_kernel.cu`  
` `USE\_CUSTOM\_DEBINFO=aten/src/ATen/native/cuda/group\_norm\_kernel.cu; python setup.py develop`

And neither will let simply break into `cuda-gdb` with `break group_normal_kernel.cu:570` for example. I can’t just build the entire thing with debugging symbols either because then cuda-gdb becomes miserably slow.

`DEBUG=1 DEBUG_CUDA=1 python setup.py develop`  
I can do something like that and it’ll seemingly work. What am i doing wrong? Also when do we want to use install vs develop? If you don’t use install then it wouldn’t work no? I generally just use `cuda-gdb` into a python script that ends up calling the code.

---

<div class="post-metadata">

### Author: ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)
#### Post date: [May 4, 2024, 4:57pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597/4 "2024-05-04T16:57:37Z")

</div>

Hey!

Ho that is weird but I have never tried to use this on cuda files to be honest.  
If you’re using regular gdb, can it find the debug info for the c++ code in there?

---

<div class="post-metadata">

### Author: ![ZelboK](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/zelbok/32/1310_2.png) [@ZelboK](https://dev-discuss.pytorch.org/u/ZelboK)
#### Post date: [May 5, 2024, 1:59am UTC](https://dev-discuss.pytorch.org/t/how-to-get-a-fast-debug-build/1597/5 "2024-05-05T01:59:22Z")

</div>

> [@albanD](#):
>
> If you’re using regular gdb, can it find the debug info for the c++ code in there?

Wdym? Like use `info functions` ? Curious to know why you mention specifically gdb and not cuda-gdb though.  
Even with a full debug build it’s kind of painful stepping through the kernel code atm. Working on my 3rd PR so I’m still very new to the internals, I use the debugger to better visualize the flow.

Tangential - is there a slack or discord that is available? Sometimes I have questions that could be easily answered in a few minutes but take a few hours to figure out on my own since I’m new to pytorch internals so it would be helpful to have an avenue for that. Are the forums the only place?
