Long build time for custom c++/cuda extension

username: ymtanga
cooked: <p>I followed the official tutorials to write a custom c++/cuda extension for pytorch.</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://docs.pytorch.org/tutorials/advanced/cpp_custom_ops.html">
  <header class="source">

      <a href="https://docs.pytorch.org/tutorials/advanced/cpp_custom_ops.html" target="_blank" rel="noopener nofollow ugc">docs.pytorch.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://docs.pytorch.org/tutorials/advanced/cpp_custom_ops.html" target="_blank" rel="noopener nofollow ugc">Custom C++ and CUDA Operators — PyTorch Tutorials 2.8.0+cu128 documentation</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>The newest tutorial suggests using <code>pip install --no-build-isolation</code> to build and install the extension module. However, during development, I frequently update my CUDA code. I’ve found that <code>pip install</code> recompiles everything from scratch each time, even when most of the code hasn’t changed. It takes me over 6 hours to recompile tens custom operators for just a small modification…</p>
<p>I also tried directly running <code>python setup.py install</code> to build my extension as described in the deprecated c++/cuda extension tutorial. This method keeps the build folder, which stores all object files that can be reused in subsequent compilations. So, I’m currently using this approach for development. However, I know that directly running python setup.py is a deprecated way to build a Python module, so I’m still looking for a better solution.</p>
<p>I’m hoping to find ways to speed up both the initial and subsequent compilation times for my project. I’ve seen some Stack Overflow discussions suggesting <strong>ccache</strong> for this, but unfortunately, I don’t have the sudo privileges needed to install it on the server right now.</p>
<p>I use this image to build my torch extension with PyTorch 2.6.</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/rel-24-12.html">
  <header class="source">
      <img src="https://docs.nvidia.com/favicon-32x32.png" class="site-icon" alt="" width="32" height="32">

      <a href="https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/rel-24-12.html" target="_blank" rel="noopener nofollow ugc">NVIDIA Docs</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/rel-24-12.html" target="_blank" rel="noopener nofollow ugc">PyTorch Release 24.12 - NVIDIA Docs</a></h3>

  <p>NVIDIA Optimized Frameworks such as Kaldi, NVIDIA Optimized Deep Learning Framework (powered by Apache MXNet), NVCaffe, PyTorch, and TensorFlow (which includes DLProf and TF-TRT) offer flexibility with designing and training custom (DNNs for machine...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Any suggestion would be very helpful. Thank you for reading my question!</p>