<div dir="ltr">Hi,<div><br></div><div>Thank you Justin for your prompt reply. I was able to generate an LLVM IR.</div><div><br></div><div>For the error reproduction purposes, I have listed below all the commands which worked and which did not work.</div><div><br></div><div>Works (I have not yet checked if files generated by all of them are same or not):</div><div><br></div><div>    <i> clang++ -O3 -emit-llvm -c <a href="http://axpy.cu">axpy.cu</a> -o axpy.bc --cuda-gpu-arch=sm_35 --cuda-path=/usr/local/cuda/ --cuda-device-only</i>     </div><div><br></div><div>     <i>clang++ -O3 -emit-llvm -c <a href="http://axpy.cu">axpy.cu</a> -o axpy.bc --cuda-device-only</i><br></div><div><br></div><div>Does not work:</div><div><br></div><div>      <i>clang++ -O3 -emit-llvm -c <a href="http://axpy.cu">axpy.cu</a> --cuda-gpu-arch=sm_35 -o axpy.bc</i></div><div><br></div><div>I think <i>--cuda-gpu-arch=sm_35</i> and <i>--cuda-path=/usr/local/cuda/</i> should be included, as the resulting code might be optimized for that architecture. I might be wrong though.</div><div><br></div><div>Thank you again.</div><div><br></div><div>-Guru</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 4:38 PM, Justin Lebar <span dir="ltr"><<a href="mailto:jlebar@google.com" target="_blank">jlebar@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you add -### to your original command, you'll see that for CUDA<br>
compilations, we invoke clang -cc1 twice: Once for the host, and once<br>
for the device.  We can't emit llvm or asm for both host and device at<br>
once, so you need to tell clang which one you want.<br>
<br>
The flag to do this is --cuda-device-only (or --cuda-host-only).<br>
<br>
Alternatively, you could compile with -save-temps to get everything.<br>
<br>
Feel free to send me a patch adding this information to<br>
<a href="http://llvm.org/docs/CompileCudaWithLLVM.html" rel="noreferrer" target="_blank">http://llvm.org/docs/<wbr>CompileCudaWithLLVM.html</a> so that we can help<br>
others avoid this hiccup.  The document lives in<br>
llvm/docs/CompileCudaWithLLVM.<wbr>rst.<br>
<span class=""><br>
> I tried adding -S -emit-llvm and changed the output file name, but I keep getting following error:<br>
<br>
</span>That is a bug -- we should give you a meaningful error.  It looks like<br>
this bug was probably introduced by the generic offloading driver<br>
changes.<br>
<br>
I am having difficulty reproducing the assertion failure, however.<br>
Can you please provide a concrete steps to reproduce?<br>
<br>
Regards,<br>
-Justin<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, Oct 13, 2016 at 1:28 PM, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br>
> Moving to cfe-dev<br>
><br>
> +Art and Justin<br>
><br>
> On Thu, Oct 13, 2016 at 1:13 PM, Gurunath Kadam via llvm-dev<br>
> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> So for a c program we do:<br>
>><br>
>>         clang -O3 -emit-llvm hello.c -c -o hello.bc<br>
>><br>
>> But how to generate an LLVM IR when working with CUDA.<br>
>><br>
>> for normal compilation:<br>
>>          clang++ <a href="http://axpy.cu" rel="noreferrer" target="_blank">axpy.cu</a> -o axpy --cuda-gpu-arch=<GPU arch> -L<CUDA<br>
>> install path>/<lib64 or lib> -lcudart_static -ldl -lrt -pthread<br>
>><br>
>> I tried adding -S -emit-llvm and changed the output file name, but I keep<br>
>> getting following error:<br>
>><br>
>> clang++:<br>
>> /stor/gakadam/llvm_projects/<wbr>llvm/tools/clang/lib/Driver/<wbr>Driver.cpp:1618:<br>
>> virtual<br>
>> {anonymous}::<wbr>OffloadingActionBuilder::<wbr>DeviceActionBuilder::<wbr>ActionBuilderReturnCode<br>
>> {anonymous}::<wbr>OffloadingActionBuilder::<wbr>CudaActionBuilder::<wbr>getDeviceDepences(clang::<wbr>driver::OffloadAction::<wbr>DeviceDependences&,<br>
>> clang::driver::phases::ID, clang::driver::phases::ID,<br>
>> {anonymous}::<wbr>OffloadingActionBuilder::<wbr>DeviceActionBuilder::PhasesTy&<wbr>):<br>
>> Assertion `CurPhase < phases::Backend && "Generating single CUDA "<br>
>> "instructions should only occur " "before the backend phase!"' failed.<br>
>><br>
>> I tried several combinations but no avail!<br>
>><br>
>> Any suggestions?<br>
>><br>
>> Thank you.<br>
>><br>
>> Sincerely,<br>
>> Guru<br>
>><br>
>> ______________________________<wbr>_________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
>><br>
><br>
</div></div></blockquote></div><br></div>