<div dir="ltr"><div>Dear clang developers,</div>thanks to the recent work by Alexey Bataev, Jonas Hahnfeld, and others, the trunk version of clang includes support for compiling device code into relocatable object files [1].<br><div><br></div><div>These object files can be linked with nvlink (once per GPU architecture), combined with fatbin, embedded in a host object file, and linked with the other host code by the host linker.</div><div>Usually nvcc can take care of this part - but it refuses to do so for unsupported host compilers (gcc 8, clang 6).<br></div><div><br></div><div>It would be great if support for this "device link" step could be added to the clang driver.</div><div>I am interested to work on it myself, but I would need some guidance on how to start.<br></div><div><br></div><div>In the meantime, to show each step and validate that different approaches are equivalent, I have adapted the original example by NVIDIA and set up an example on GitHub at <a href="https://github.com/fwyzard/cuda-linking/">https://github.com/fwyzard/cuda-linking/</a> :</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"># clone the repository<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">git clone git@github.com:fwyzard/cuda-linking.git<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">cd cuda-linking</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"># build and link with nvcc</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">make clean nvcc</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">./app<br></span></div><div style="margin-left:40px"><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace"># build with nvcc, link explicitly with nvlink/fatbin</span></div><div><span style="font-family:monospace,monospace">make clean nvlink</span></div><div><div><div><span style="font-family:monospace,monospace">./app<br></span></div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace"># build with clang, link explicitly with nvlink/fatbin</span></div><span style="font-family:monospace,monospace">make clean clang<br></span></div><div><span style="font-family:monospace,monospace">./app<br></span></div></div><div><br></div><div><br></div><div>Best regards,</div><div>.Andrea<br></div><br><div><br></div><div>[1] Separate Compilation and Linking of CUDA C++ Device Code, 
<a href="https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/" target="_blank">https://devblogs.nvidia.com/<wbr>separate-compilation-linking-<wbr>cuda-device-code/</a></div></div>