ExtUtils::nvcc::Backend - Backend to CUDA compiler and linker wrapper for Perl's toolchain
This is meant to be used from the command-line,
invoking either the
linker functions like so:
prompt> perl -MExtUtils::nvcc::Backend \ -eExtUtils::nvcc::Backend::compiler -- \ source.c -o test_prog
For verbosity, supply the -v flag (after the double-dash) or call the
prompt> perl -MExtUtils::nvcc::Backend \ -eExtUtils::nvcc::Backend::compiler -- \ source.c -v -o test_prog prompt> perl -MExtUtils::nvcc::Backend \ -e"ExtUtils::nvcc::Backend::verbose;ExtUtils::nvcc::Backend::compiler" -- source.c -o test_prog
This module provides functions to convert arbitrary command-line arguments to acceptable nvcc arguments and invoke nvcc to compile or link your code. Generally speaking, you won't need to worry about this module and should stick with functions from ExtUtils::nvcc that provide configuration options for the common Perl toolchains.
However, if you are working on your own toolchain and need to invoke nvcc with Perl's original build arguments, you'll probably want to use this module. The command-line examples in the SYNOPSIS hopefully give you enough to get started playing around.
At this point, you may be curious why I didn't just put the command-line processing in the front-end library, ExtUtils::nvcc. The reason is simple: nvcc's behavior depends on the filename's ending (can't set it with a flag, as far as I can tell), so filenames with CUDA code must have a .cu ending. I could subclass each of Perl's toolchains (Inline::C, ExtUtils::MakeMaker, and Module::Build) to accomodate CUDA, but I decided it would be better to create this drop-in replacement for gcc. Since I have to have a layer between the toolchains and nvcc to rename .c files to .cu files, and since I need to process arguments, I decided to roll the whole thing into one.
The compiler function processes all arguments in
@ARGS, wraps them in such a way that nvcc knows how to process them, and ensures that nvcc compiles the source files as cuda files (even if they have a .c extension).
The linker function processes all arguments in
@ARGS, and invokes nvcc as a linker with properly modified arguments.
Runs nvcc with the supplied list of nvcc-compatible command-line arguments, using the system Perl function.
If the system call fails, run_nvcc checks that it can find nvcc in the first place, and croaks with one of two messages:
This message means that nvcc is in your path but the system call failed, which means that the compile didn't like what you sent it.
This message means that nvcc cannot be found. Make sure you've installed nVidia's toolkit and double-check your path settings.
To use, try something like this:
run_nvcc qw(my_source.cu -o my_program);
Processes the list of supplied (gcc-style) arguments, seperating out nvcc-compatible arguments, and nvcc-incompatible arguments, and source file names. The resulting lists are returned by reference in that order.
Here's a usage example:
# Get the nvcc args, the compiler args, and the source files: my ($nvcc_args, $other_args, $source_files) = process_args(@ARGV); # Unpack array refs into normal arrays my @nvcc_args = @$nvcc_args; my @other_args = @$other_args; my @source_files = @$source_files;
This function simply sets the package global variable
$verbose to a true value, enabling verbose printouts from the compiler, linker, and other functions. See the "SYNOPSIS" for an example of use.
Please see "DIAGNOSTICS" in ExtUtils::nvcc for help on error messages.
I have obfuscated my email address. Simply remove the portion that would not be sensible for a Perl developer.
David Mertens <email@example.com>
ExtUtils::nvcc and references therein
Copyright (c) 2010-2011 David Mertens. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This software is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.