In general, the NVCC can not compile anything “standalone”. There always has to be one of the supported C compilers in the background. When having installed, for example, MS Visual Studio, the required environment variables should already have been set automatically. Thus, when MS Visual Studio is installed, it should in general be possible to execute the NVCC directly from the command line.
I once started creating a set of classes which should provide an object-oriented abstraction layer for CUDA (delegating the calls directly to JCuda, of course). Although this project lies dormant at the moment, here is a short snippet showing how I compiled CUBIN files by calling NVCC from Java during runtime:
Process process = null;
try
{
String command = "nvcc -cubin "+cuFile.getPath()+" -o "+cubinFileName;
System.out.println("Executing
"+command);
process = Runtime.getRuntime().exec(command);
}
catch (IOException e)
{
throw new RuntimeException("Could not execute nvcc compiler", e);
}
String errorMessage = new String(toByteArray(process.getErrorStream()));
String outputMessage = new String(toByteArray(process.getInputStream()));
int exitValue = 0;
try
{
exitValue = process.waitFor();
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
throw new RuntimeException("Interrupted while waiting for nvcc output", e);
}
System.out.println("nvcc process exitValue "+exitValue);
EDIT >> The ‘toByteArray’ method just reads an inputStream until its end, and returns the contents as a byte array <<
The command line should actually be something like
nvcc -cubin theKernel.cu -o theKernel.cubin
This basically worked, when MSVS is installed. I assume that you’re using something similar in your case.
If no supported C compiler is installed (or it cannot be found, because the path to its executable is not located in the PATH environment variable), calling the NVCC in the way described above will most likely return an ‘exitValue’ which is !=0. In this case, I could not think of any way to create a CUBIN file at runtime…
Maybe someone has a good idea what to do in this case, except for printing a helpful error message and urging the user to install an appropriate compiler…