[cfe-dev] [llvm-dev] LLVM/CUDA generate LLVM IR

Justin Lebar via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 13 13:38:23 PDT 2016


If you add -### to your original command, you'll see that for CUDA
compilations, we invoke clang -cc1 twice: Once for the host, and once
for the device.  We can't emit llvm or asm for both host and device at
once, so you need to tell clang which one you want.

The flag to do this is --cuda-device-only (or --cuda-host-only).

Alternatively, you could compile with -save-temps to get everything.

Feel free to send me a patch adding this information to
http://llvm.org/docs/CompileCudaWithLLVM.html so that we can help
others avoid this hiccup.  The document lives in
llvm/docs/CompileCudaWithLLVM.rst.

> I tried adding -S -emit-llvm and changed the output file name, but I keep getting following error:

That is a bug -- we should give you a meaningful error.  It looks like
this bug was probably introduced by the generic offloading driver
changes.

I am having difficulty reproducing the assertion failure, however.
Can you please provide a concrete steps to reproduce?

Regards,
-Justin

On Thu, Oct 13, 2016 at 1:28 PM, Reid Kleckner <rnk at google.com> wrote:
> Moving to cfe-dev
>
> +Art and Justin
>
> On Thu, Oct 13, 2016 at 1:13 PM, Gurunath Kadam via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
>>
>> So for a c program we do:
>>
>>         clang -O3 -emit-llvm hello.c -c -o hello.bc
>>
>> But how to generate an LLVM IR when working with CUDA.
>>
>> for normal compilation:
>>          clang++ axpy.cu -o axpy --cuda-gpu-arch=<GPU arch> -L<CUDA
>> install path>/<lib64 or lib> -lcudart_static -ldl -lrt -pthread
>>
>> I tried adding -S -emit-llvm and changed the output file name, but I keep
>> getting following error:
>>
>> clang++:
>> /stor/gakadam/llvm_projects/llvm/tools/clang/lib/Driver/Driver.cpp:1618:
>> virtual
>> {anonymous}::OffloadingActionBuilder::DeviceActionBuilder::ActionBuilderReturnCode
>> {anonymous}::OffloadingActionBuilder::CudaActionBuilder::getDeviceDepences(clang::driver::OffloadAction::DeviceDependences&,
>> clang::driver::phases::ID, clang::driver::phases::ID,
>> {anonymous}::OffloadingActionBuilder::DeviceActionBuilder::PhasesTy&):
>> Assertion `CurPhase < phases::Backend && "Generating single CUDA "
>> "instructions should only occur " "before the backend phase!"' failed.
>>
>> I tried several combinations but no avail!
>>
>> Any suggestions?
>>
>> Thank you.
>>
>> Sincerely,
>> Guru
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>



More information about the cfe-dev mailing list