1
votes

I have a CUDA C/C++ programm for CUDA 7.5. And as known: libNVVM Library - an optimizing compiler library that generates PTX from NVVM IR.

I can get PTX by using: nvcc -ptx <file>.cu -o <file>.ptx

But how can I get NVVM IR (LLVM IR) from <file>.cu?

And how can I compile NVVM IR (LLVM IR) or Optimized IR for the target architecture?

Do I need for this third-party libraries or programs such as: libcuda.lang, ...?

enter image description here

enter image description here

The NVVM compiler (which is based on LLVM) generates PTX code from NVVM IR.

NVVM IR and NVVM compilers are mostly agnostic about the source language being used. The PTX codegen part of a NVVM compiler needs to know the source language because of the difference in DCI (driver/compiler interface).

Technically speaking, NVVM IR is LLVM IR with a set of rules, restrictions, and conventions, plus a set of supported intrinsic functions. A program specified in NVVM IR is always a legal LLVM program. A legal LLVM program may not be a legal NVVM program.

1
Hi Alex, could you get LLVM IR with clang++/llvm for CUDA code? I too was wondering about this: clang++ -S -emit-llvm -o axpy -I<CUDA install path>/samples/common/inc -L<CUDA install path>/<lib64 or lib> axpy.cu -lcudart_static -lcuda -ldl -lrt -pthread!algoProg

1 Answers

3
votes

The very short answer is that you cannot do this. NVIDIA's parser is proprietary and closed source, and they have not exposed the IR code generator in a way which can be used as you are asking about.

That said, you are not the first person to wonder about this, and you might be able to find some useful, but completely unofficial and unsupported information here.