Create standalone CUDA Extension

Surya_J: <p>Hi,</p>
<p>I’m trying to compile CUDA Extension from set of .cu and .cpp files in Kaggle environment. I followed this <a href="https://pytorch.org/tutorials/advanced/cpp_extension.html#using-accessors" rel="noopener nofollow ugc">tutorial</a> and was able to load as python module. I want to save the built module to a file and be able to load it in another instance (same Notebook different time / different notebook), so that I don’t need to build the module every time. The HW will be the same in all scenarios (P100).</p>
<p>I tried using giving the <strong>is_python_module=False, is_standalone=True</strong> arguments in <a href="https://pytorch.org/docs/stable/cpp_extension.html#torch.utils.cpp_extension.load" rel="noopener nofollow ugc">cpp_extension.load() function</a> , assuming it’d give an executable which can be reused. Is my understanding of the argument correct?</p>
<p>Another thing, I get a bunch of undefined reference errors and so the build fails</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/1/812d5ce00e3c2c6454db55c71715f2edeb0ca3e5.png" data-download-href="https://discuss.pytorch.org/uploads/default/812d5ce00e3c2c6454db55c71715f2edeb0ca3e5" title="load_error_1"><img src="https://discuss.pytorch.org/uploads/default/original/3X/8/1/812d5ce00e3c2c6454db55c71715f2edeb0ca3e5.png" alt="load_error_1" data-base62-sha1="iqKMxWT7WEQa9bwJiY5s5peIqAB" width="690" height="288" data-dominant-color="F0F0F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">load_error_1</span><span class="informations">1722×721 64.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/8/d854c06777644fdbe82e07467374b63bf1b9eb11.png" data-download-href="https://discuss.pytorch.org/uploads/default/d854c06777644fdbe82e07467374b63bf1b9eb11" title="load_error_2"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/8/d854c06777644fdbe82e07467374b63bf1b9eb11.png" alt="load_error_2" data-base62-sha1="uRKIcUHrNNwMDT5utMwQoGbKr6N" width="690" height="215" data-dominant-color="EDEDED"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">load_error_2</span><span class="informations">1712×535 39.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Is there any other source file / argument that I need to set to build an executable that can be save to file and later imported as Python module in some other environment (same platform)?</p>
<p>I tried referring to <a href="https://discuss.pytorch.org/t/cuda-extension-install-without-rebuilding/74419">this post</a>, but unable to use the build_directory option</p>
<p>It’d very helpful if someone can help me out on this</p>

Surya_J: <p>I tried copying the .o and .so files to file and extracting it in new instance.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/4/340355fd769d9918440a810cb620801991e45bbc.png" data-download-href="https://discuss.pytorch.org/uploads/default/340355fd769d9918440a810cb620801991e45bbc" title="testDir_unzipped"><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/4/340355fd769d9918440a810cb620801991e45bbc.png" alt="testDir_unzipped" data-base62-sha1="7q7Yubg9uCmcmqcw0uZTr5xO46o" width="690" height="426" data-dominant-color="F7F8F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">testDir_unzipped</span><span class="informations">980×606 23.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>After extracting the contents, I try to add the module path to sys.path and import it. But it throws <code>cannot find so : No such file or directory</code> error. ldd on the so shows its not able to find 3 dependencies.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/a/1a7749e9007d9341cd5e8f4053a4469ab789bff1.png" data-download-href="https://discuss.pytorch.org/uploads/default/1a7749e9007d9341cd5e8f4053a4469ab789bff1" title="ldd_path_error"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/a/1a7749e9007d9341cd5e8f4053a4469ab789bff1.png" alt="ldd_path_error" data-base62-sha1="3M7ZkaoYsjh60GSlFL6XrVriyxH" width="561" height="500" data-dominant-color="F3EEEE"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">ldd_path_error</span><span class="informations">792×705 37.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>