<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Now the problem is that you somehow ended up targeting x86 during GPU-side compilation. </div><div class="gmail_default" style="font-family:verdana,sans-serif">One thing you need to keep in mind when using libclang or libtooling with CUDA is that compiling a CUDA file is actually N different compilations - one for the host and one per specified GPU architecture.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">I'm not quite sure what libclang or libtooling does in this case. You may want to avoid the ambiguity and use --cuda-host-only or --cuda-device-only with only one GPU variant specified. I'm not sure if that's going to fix this particular problem, but it's something you will probably need to do in any case.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">--Artem</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Nov 10, 2018 at 4:22 PM Franklin He <<a href="mailto:He_Franklin@hotmail.com">He_Franklin@hotmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks for the help Artem.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
A<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">fter a bit of fumbling around, adding the resource directory results in the same error as directly including the clang directory via -I</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">I was hoping to use libclang as libTooling is restricted to either host or device code in a single pass from my understanding. In the meantime, I'll proceed with
 libTooling.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
-- Franklin</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Error message attached below:</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span>$ ./cuda_libclang_sa /tmp/<a href="http://test.cu" target="_blank">test.cu</a> -v --cuda-gpu-arch=sm_35 -resource-dir=/home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0<br>
</span>
<div>clang version 8.0.0 (<a href="http://llvm.org/git/clang.git" target="_blank">http://llvm.org/git/clang.git</a> 3129a82102a7de23d44f02c0df89c1d6a535f7a7) (<a href="http://llvm.org/git/llvm.git" target="_blank">http://llvm.org/git/llvm.git</a> 00233291cf25baa54e5d058610e8a985deaac9e4)<br>
</div>
<div>Target: x86_64-unknown-linux-gnu<br>
</div>
<div>Thread model: posix<br>
</div>
<div>InstalledDir: /home/n0mad/CLionProjects/cudadadadadadadadadada/cmake-build-debug/libclang<br>
</div>
<div>Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/8<br>
</div>
<div>Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/8<br>
</div>
<div>Candidate multilib: .;@m64<br>
</div>
<div>Candidate multilib: 32;@m32<br>
</div>
<div>Selected multilib: .;@m64<br>
</div>
<div>Found CUDA installation: /usr/local/cuda-10.0, version 10.0<br>
</div>
<div>ignoring nonexistent directory "/include"<br>
</div>
<div>ignoring nonexistent directory "/include"<br>
</div>
<div>ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8"<br>
</div>
<div>ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux"<br>
</div>
<div>ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward"<br>
</div>
<div>ignoring duplicate directory "/usr/local/include"<br>
</div>
<div>ignoring duplicate directory "/home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include"<br>
</div>
<div>ignoring duplicate directory "/usr/include"<br>
</div>
<div>#include "..." search starts here:<br>
</div>
<div>#include <...> search starts here:<br>
</div>
<div> /home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include/cuda_wrappers<br>
</div>
<div> /usr/local/cuda-10.0/include<br>
</div>
<div> /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8<br>
</div>
<div> /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux<br>
</div>
<div> /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward<br>
</div>
<div> /usr/local/include<br>
</div>
<div> /home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include<br>
</div>
<div> /usr/include<br>
</div>
<div>End of search list.<br>
</div>
<div>/home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include/__clang_cuda_builtin_vars.h:67:27: error: use of undeclared identifier '__nvvm_read_ptx_sreg_tid_x'<br>
</div>
<div>/home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include/__clang_cuda_builtin_vars.h:68:27: error: use of undeclared identifier '__nvvm_read_ptx_sreg_tid_y'<br>
</div>
<span>/home/n0mad/code_libs/llvm_trunk/lib/clang/8.0.0/include/__clang_cuda_builtin_vars.h:69:27: error: use of undeclared identifier '__nvvm_read_ptx_sreg_tid_z'</span><br>
</div>
<hr style="display:inline-block;width:98%">
<div id="m_-8371096238785122977divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Artem Belevich <<a href="mailto:tra@google.com" target="_blank">tra@google.com</a>><br>
<b>Sent:</b> Sunday, 11 November 2018 12:29 PM<br>
<b>To:</b> <a href="mailto:He_Franklin@hotmail.com" target="_blank">He_Franklin@hotmail.com</a><br>
<b>Cc:</b> cfe-dev<br>
<b>Subject:</b> Re: [cfe-dev] libtooling/libclang cannot find "__clang_cuda_runtime_wrapper.h"</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif">It looks like -resource-dir is missing in case of libclang tool.</div>
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif">Try passing -Xclang -resource-dir=/path/to/clang/installation/root</div>
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif"><br>
</div>
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif">You can get resouce dir with 'clang -print-resource-dir'</div>
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif"><br>
</div>
<div class="m_-8371096238785122977x_gmail_default" style="font-family:verdana,sans-serif">--Artem</div>
</div>
</div>
<br>
<div class="m_-8371096238785122977x_gmail_quote">
<div dir="ltr">On Sat, Nov 10, 2018 at 2:25 PM Franklin He <<a href="mailto:He_Franklin@hotmail.com" target="_blank">He_Franklin@hotmail.com</a>> wrote:<br>
</div>
<blockquote class="m_-8371096238785122977x_gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">I did some more testing and t</span><span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">he problem does not occur if I put the libTooling-based
 executable in the $LLVM_INSTALL_DIR/bin directory. I originally did an out of source build which would have put the executable not in tree with the rest of the LLVM library.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">The libclang-based tool still exhibit the same issue no matter where I put the final executable.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt">I've attached the terminal output using the -v flag with tools I've made using libtooling, libclang, and also the output if I compile a test CUDA file using Clang. For
 some reason they all check different include directories.....</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I've also attached what would happen if you force the include of the CUDA wrappers using the -I flag, in short: A lot of weird errors.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div></div>
<div>-- Franklin</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:12pt"><span></span><br>
</span></div>
<hr style="display:inline-block;width:98%">
<div id="m_-8371096238785122977x_m_4475540440823131211divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Artem Belevich <<a href="mailto:tra@google.com" target="_blank">tra@google.com</a>><br>
<b>Sent:</b> Thursday, 8 November 2018 12:19 PM<br>
<b>To:</b> <a href="mailto:He_Franklin@hotmail.com" target="_blank">He_Franklin@hotmail.com</a><br>
<b>Cc:</b> cfe-dev<br>
<b>Subject:</b> Re: [cfe-dev] libtooling/libclang cannot find "__clang_cuda_runtime_wrapper.h"</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_default" style="font-family:verdana,sans-serif">
It would help a lot if you could figure out what compiler options we end up using when the file is handled by libtooling or libclang. The fact that you've got the error means that the file *is* treated as a CUDA file (good news) but we either didn't add include
 path to clang headers, or the headers are not where they should be.</div>
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_default" style="font-family:verdana,sans-serif">
<br>
</div>
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_default" style="font-family:verdana,sans-serif">
I don't know if there's an easy way to do it libtooling or libclang. In the past I dug these options out with debugger. You can try passing '-v' and see if you get back the usual printout of header search path.</div>
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_default" style="font-family:verdana,sans-serif">
<br>
</div>
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_default" style="font-family:verdana,sans-serif">
--Artem</div>
</div>
<br>
<div class="m_-8371096238785122977x_m_4475540440823131211x_gmail_quote">
<div dir="ltr">On Sun, Oct 14, 2018 at 2:13 AM Franklin He via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="m_-8371096238785122977x_m_4475540440823131211x_gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hello<br>
<br>
I am attempting to write a static analyzer for CUDA using the Clang infrastructure.<br>
<br>
After writing a simple tool, and giving it the example CUDA file in <a href="https://llvm.org/docs/CompileCudaWithLLVM.html" rel="noreferrer" target="_blank">
https://llvm.org/docs/CompileCudaWithLLVM.html</a> , I get the following error:<br>
<br>
fatal error: '__clang_cuda_runtime_wrapper.h' file not found<br>
<br>
so far this happens with both libtooling and libclang. I have tried using clang to compile the same CUDA file and it works.<br>
I am currently linking against clang sources from the trunk, but this also happens with Clang version 6.<br>
I currently have CUDA 10 installed on this computer. <br>
<br>
Any help would be appreciated.<br>
<br>
Regards<br>
Franklin<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="m_-8371096238785122977x_m_4475540440823131211x_gmail_signature">
<div dir="ltr">--Artem Belevich</div>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="m_-8371096238785122977x_gmail_signature">
<div dir="ltr">--Artem Belevich</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Artem Belevich</div></div>