Permalink
Browse files

Revised and improved handling on Windows.

I managed to install Windows on my nVidia box and discovered that
although nvcc works with Visual Studio, it does not work with gcc.
I have documented this in multiple locations and I have included
checks in Build.PL and the Backend.
  • Loading branch information...
1 parent 99aeb4a commit 720a7beaaf976ea93bc3db53b113c5f839f13392 @run4flat committed Jun 23, 2011
Showing with 117 additions and 25 deletions.
  1. +4 −0 .gitignore
  2. +15 −0 Build.PL
  3. +6 −7 MYMETA.yml
  4. +26 −9 README
  5. +39 −9 lib/ExtUtils/nvcc.pm
  6. +27 −0 lib/ExtUtils/nvcc/Backend.pm
View
@@ -6,3 +6,7 @@ _build/
blib/
_Inline/
*.tar.gz
+
+# Ignore windows build files
+*.bat
+MYMETA.json
View
@@ -4,6 +4,21 @@ use Module::Build;
my $nvcc_version = `nvcc -V`;
$nvcc_version =~ /NVIDIA/ or die "You must have nvcc (from nVidia's CUDA Toolkit) installed\n";
+# check that we have access cl.exe if we're on a Windows system. (I suppose I
+# should also check for gcc on Linux machines, but I don't expect that to ever
+# be lacking.)
+use Config;
+if ($Config{osname} =~ /MSWin/) {
+ my $cl_version = `cl /help`;
+ $cl_version =~ /Microsoft/
+ or die ("You must have cl.exe (Microsoft's compiler) installed\n"
+ . "in order to run ExtUtils::nvcc\n");
+
+ # Warn if they have cl.exe but used gcc to compile perl
+ warn "You used gcc to compile perl, but nvcc will use cl.exe; proceed with caution\n"
+ if $Config{cc} eq 'gcc';
+}
+
my $build = Module::Build->new
(
module_name => 'ExtUtils::nvcc',
View
@@ -1,11 +1,10 @@
---
-abstract: 'the library that will eventually be behind C<perl_nvcc>'
+abstract: "CUDA compiler and linker wrapper for Perl's toolchain"
author:
- - 'David Mertens <dcmertens.perl@gmail.com>'
-configure_requires:
- Module::Build: 0.36
+ - 'David Mertens <dcmertens.perl.csharp@gmail.com>'
+build_requires: {}
dynamic_config: 0
-generated_by: 'Module::Build version 0.3607'
+generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110930'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -14,7 +13,7 @@ name: ExtUtils-nvcc
provides:
ExtUtils::nvcc:
file: lib/ExtUtils/nvcc.pm
- version: 0.01
+ version: 0.02
resources:
license: http://dev.perl.org/licenses/
-version: 0.01
+version: 0.02
View
35 README
@@ -5,10 +5,10 @@ ExtUtils::nvcc is a CUDA compiler and linker wrapper for Perl's toolchain.
Modern compilers take a lot of options. Perl has learned to use many of these
options. The problem is that nvcc, nVidia's compiler wrapper---which must be
-used to write CUDA code---doesn't like most of those extra flags and options. It
-has a special set of command-line arguments that allow you to pass compiler and
-linker flags on to the actual compiler and linker, but it does not send those
-options along by default. That makes life harder than it ought to be.
+used to compile CUDA code---doesn't like most of those extra flags and options.
+It has a special set of command-line arguments that allow you to pass compiler
+and linker flags on to the actual compiler and linker, but it does not send
+those options along by default. That makes life harder than it ought to be.
Hence ExtUtils::nvcc. The main goal of this project is to provide a compiler and
linker acceptable to the common Perl build tools, Inline::C, ExtUtils::MakeMaker,
@@ -32,6 +32,21 @@ The last line requires that you have root priveleges unless you are using
local::lib.
+Windows Restrictions
+====================
+
+The people at nVidia decided to only support gcc on Linux machines, and cl.exe
+(MS Visual Studio's compiler) on Windows machines. This is truly unfortunate
+since the code is clearly in place to support gcc. In practice, this means that
+ExtUtils::nvcc will not work properly on Strawberry Perl or Cygwin's perl. I'm
+afraid you'll have to get a version of Perl compiled with Visual Studio, and
+you'll need a copy of Visual Studio to compile nVidia code. The good news is
+that Microsoft allows you to download a free copy of any single componenet of
+the Visual Studio suite: you can download Visual C/C++ for free. You will likely
+need to compile your own perl, but once that's in place, you'll have a fully
+operating CPAN and ExtUtils::nvcc will work correctly.
+
+
Dependencies
============
@@ -41,6 +56,8 @@ You can use this module outside of the Perl toolchain (by wrapping the awkward
command-line invocation, perhaps), but it's really meant to operate with
ExtUtils::MakeMaker, Inline::C, and Module::Build.
+Although not necessary for use, the installation requires Module::Build.
+
Usage
=====
@@ -52,11 +69,11 @@ ExtUtils::nvcc
Bugs
====
-At the moment, Perl modules (and by extension scripts that use ExtUtils::nvcc
-together with Inline::C) die with a segmentation fault. The death occurrs after
-the last END block, so I don't think it's a problem, functionally speaking.
-However, clearly something is messed up with the bookkeeping, and I'm not sure
-what's going one. Help here would be appreciated.
+At the moment, Perl modules built using ExtUtils::nvcc (and by extension scripts
+that use ExtUtils::nvcc together with Inline::C) die with a segmentation fault.
+The death occurrs after the last END block, so I don't think it's a problem,
+functionally speaking. However, clearly something is messed up with the
+bookkeeping, and I'm not sure what's going one. Help here would be appreciated.
Feedback Welcome
View
@@ -13,11 +13,11 @@ use vars qw($VERSION);
=head1 VERSION
-This documentation explains the use of ExtUtils::nvcc version 0.02.
+This documentation explains the use of ExtUtils::nvcc version 0.03.
=cut
-$VERSION = '0.02';
+$VERSION = '0.03';
# For errors, of course:
use Carp qw(croak);
@@ -346,6 +346,33 @@ sub build_args {
1;
+=head1 WIDNOWS ISSUES
+
+Windows usage presents a couple of difficulties, as described in this section.
+
+=head2 Visual Studio Only
+
+Unfortunately, nVidia's compiler wrapper (nvcc) only supports the use of cl.exe
+on Windows. This means that Cygwin and Strawberry Perl users are out of luck for
+using ExtUtils::nvcc.
+
+There may be a way to install Visual Studio alongside your Strawberry Perl or
+Cygwin installations. In that case, assuming you run the build process in a
+Visual Studio Command Prompt, nvcc will be happy because it will be able to find
+cl.exe. However, I have not tested this method, and I expect that perl will have
+trouble loading the resulting libraries. Please let me know if you get this to
+work.
+
+=head2 Visual Studio Command Prompt
+
+When you install Visual Studio (as of Visual Studio 2010), you will get a Start
+Menu entry for Visual Studio Command Prompt. You should run your build processes
+(i.e. cpan) from one of these command prompts. Among other things, this command
+prompt sets all of the necessary environment variables to ensure that the
+compiler can be found, and that the compiler can find all the necessary
+libraries.
+
+
=head1 DIAGNOSTICS
ExtUtils::nvcc could croak for a number of reasons. To keep things concise, I
@@ -439,6 +466,11 @@ backend.) If you are in an environment in which you do not have these tools,
you will be able to use L<ExtUtils::nvcc::Backend>, but you'll have a hard time
tying anything into Perl.
+=item gcc (Linux) or Visual Studio (Windows)
+
+The nvcc compiler only supports gcc on Linux, and cl.exe on Windows. You cannot
+specify an alternative compiler.
+
=back
=head1 BUGS AND LIMITATIONS
@@ -454,13 +486,11 @@ runtime for arguments that it accepts so that there could never be a version
skew for the arguments that the Backend parses and the arguments that nvcc
accepts.
-I believe C<ExtUtils::nvcc> will operate on Windows machines under Cygwin and
-under Strawberry Perl, since they use gcc. Furthermore, I believe that
-C<ExtUtils::nvcc> does in fact work with Microsoft's compiler as well, but I do
-not have a Windows machine or the Microsoft toolchain so I cannot develop or
-test for that system. If you are a developer with an interest in ensuring that
-L<ExtUtils::nvcc::Backend> works with Microsoft's compiler, I welcome your
-contributions!
+For Windows users, a third major dilema is that nvcc only works with Microsoft's
+compiler, cl.exe, on Windows machines. As such, C<ExtUtils::nvcc> will not
+operate correctly under Cygwin or Strawberry Perl (unless, possibly, if you
+install Visual Studio also). I would like to remedy this situation. Please let
+me know if you find a work-around for Strawberry Perl or Cygwin.
The code for ExtUtils::nvcc is hosted at github, but please file bugs at
L<https://rt.cpan.org/Public/Bug/Report.html?Queue=ExtUtils-nvcc>.
@@ -12,6 +12,9 @@ package ExtUtils::nvcc::Backend;
# For errors, of course:
use Carp qw(croak);
+# To check if this is a windows perl built with gcc:
+use Config;
+
=head1 SYNOPSIS
This is meant to be used from the command-line, invoking either the C<compiler>
@@ -193,6 +196,30 @@ To use, try something like this:
# See also : compiler, linker
sub run_nvcc {
+ # XXX nvcc does not play nicely with gcc on Windows. It requires cl (from
+ # Visual Studio). There might be a heroic way to get around this, but the
+ # obvious/historic answer (using --foreign) does not work:
+ if ($Config{cc} eq 'gcc' and $Config{osname} =~ /MSWin/) {
+# push @_, '--foreign=gcc' unless grep {/^--foreign/} @_;
+ warn join("\n", '', '*'x61
+ , '* This will very likely not compile. You compiled your perl *'
+ , '* using gcc (either with mingw, Cygwin, or Strawberry) but *'
+ , '* nvcc on Windows requires Visual Studio, i.e. cl.exe. If *'
+ , '* you have Visual Studio, this may compile, but it is *'
+ , '* unlikely to link correctly. I will attempt, with fingers *'
+ , '* crossed... *'
+ , '*'x61, '');
+
+ }
+ # See these forum discussions:
+ # http://forums.nvidia.com/index.php?showtopic=78531
+ # http://forums.nvidia.com/index.php?showtopic=182655
+
+ # The heroic ways to get around this would be to write a wrapper around gcc
+ # that accepts cl arguments, or to create a blank cl.bat and manually
+ # seperate the kernel code from the host code and send only the kernel code
+ # through nvcc.
+
our $verbose;
print "Running nvcc with args [[", join(']], [[', @_), "]]\n" if $verbose;

0 comments on commit 720a7be

Please sign in to comment.