README for CUDA Compiler SDK Samples
====================================

Introduction
------------

Here are three simple samples illustrating the use of libNVVM.

simple
   reads in a NVVM IR program from a file, compiles it to PTX, and launches
   the program on GPU using CUDA driver APIs.

ptxgen
   is a standalone NVVM IR program to PTX compiler. It will link the 
   libDevice library with the input NVVM IR program, verify the IR for
   conformance to the NVVM IR specification, and then generate PTX.

cuda-c-linking
   builds an NVVM IR program using the LLVM IR build APIs, links the 
   generated PTX with a PTX generated by nvcc, and launches the linked
   program on GPU using CUDA driver APIs.
   


Steps of Building the Samples
-----------------------------

The following three environment variables can be used to control the build
process for the samples.  If not specified, CUDA_HOME will be derived by
looking for nvcc in your PATH.

CUDA_HOME    : The directory where the CUDA toolkit is installed, 
               e.g. /usr/local/cuda.
LIBNVVM_HOME : The directory where libNVVM components are located. 
               e.g. $CUDA_HOME/nvvm. 
LLVM_HOME    : The directory of CMake-based LLVM install directory. This must
               point to an installation of LLVM 3.2. 

If you don't set LLVM_HOME or do not have CMake-based LLVM installed, then 
the sample 'cuda-c-linking' will not be built. This sample requires LLVM
version 3.2.

After setting the environment variables and adding path to cmake tool in
the PATH environment variable, sample script build.sh (for Linux and Mac OS X)
or build.bat (for Windows) may be executed. This script will use build
directory "build" to build the samples, and then install them in
the "install" directory.

The following shows how to build the samples on Linux and Mac OS X.  Note that
setting CUDA_HOME and LIBNVVM_HOME are not needed if nvcc is in your PATH.

 $ export CUDA_HOME=<cuda_home_dir>
 $ export LIBNVVM_HOME=<libnvvm_home_dir>
 $ export LLVM_HOME=<llvm_install_dir>
 $ mkdir <build_dir>
 $ cd <build_dir>
 $ cmake -DCMAKE_INSTALL_PREFIX=<install_dir> -DCUDA_HOME=$CUDA_HOME -DLIBNVVM_HOME=$LIBNVVM_HOME -DLLVM_HOME=$LLVM_HOME ..
 $ make install

The following shows how to build the samples on Windows.  Note that setting
CUDA_HOME and LIBNVVM_HOME are not needed if nvcc is in your PATH.

 $ set CUDA_HOME=<cuda_home_dir>
 $ set LIBNVVM_HOME=<libnvvm_home_dir>
 $ set LLVM_HOME=<llvm_install_dir>
 $ mkdir <build_dir>
 $ cd <build_dir>
 $ cmake -DCMAKE_INSTALL_PREFIX=<install_dir> -DCUDA_HOME=%CUDA_HOME% -DLIBNVVM_HOME=%LIBNVVM_HOME% -DLLVM_HOME=%LLVM_HOME% -G "NMake Makefiles" ..
 $ nmake install

<install_dir> is the directory where you want the built binaries to be
installed. The built executables will be copied under <install_dir>/bin.
