Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unrecognised emulation mode: arch=native" when running 'perl Build.PL' #3

Closed
jnareb opened this issue Jul 3, 2011 · 10 comments
Closed

Comments

@jnareb
Copy link

jnareb commented Jul 3, 2011

When running 'perl Build.PL' I got the following errors:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognised emulation mode: arch=native
Supported emulations: elf_x86_64 elf_i386 i386linux elf_l1om
collect2: ld returned 1 exit status
nvcc encountered a problem

Is there any way to work around this issue? Running with

config => {ExtUtils::nvcc::MB('verbose')},

I get the folowing output

Making verbose
ExtUtils::nvcc found nvcc args [[-I/usr/lib64/perl5/5.12.3/x86_64-linux/CORE]], [[-c]], [[-D_LARGEFILE_SOURCE]], [[-D_FILE_OFFSET_BITS=64]], [[-O2]], [[-o]], [[compilet-yvJH2.o]]
ExtUtils::nvcc found other args [[-fPIC]], [[-fno-strict-aliasing]], [[-pipe]], [[-pipe]], [[-march=native]]
ExtUtils::nvcc found source files [[compilet-yvJH2.c]]
Running nvcc with args [[-Xcompiler=-fPIC,-fno-strict-aliasing,-pipe,-pipe,-march=native]], [[-I/usr/lib64/perl5/5.12.3/x86_64-linux/CORE]], [[-c]], [[-D_LARGEFILE_SOURCE]], [[-D_FILE_OFFSET_BITS=64]], [[-O2]], [[-o]], [[compilet-yvJH2.o]], [[--x=cu]], [[compilet-yvJH2.c]]
Making verbose
ExtUtils::nvcc found nvcc args [[-shared]], [[-O2]], [[-o]], [[compilet-yvJH2.so]]
ExtUtils::nvcc found other args [[-pipe]], [[-march=native]], [[-Wl,-O1]], [[-Wl,--as-needed]]
ExtUtils::nvcc found source files [[compilet-yvJH2.o]]
Running nvcc with args [[-Xlinker=-pipe,-march=native,-Wl,-O1,-Wl,--as-needed]], [[-shared]], [[-O2]], [[-o]], [[compilet-yvJH2.so]], [[compilet-yvJH2.o]]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognised emulation mode: arch=native
Supported emulations: elf_x86_64 elf_i386 i386linux elf_l1om
collect2: ld returned 1 exit status
nvcc encountered a problem
@run4flat
Copy link
Owner

run4flat commented Jul 3, 2011

Jakub -

Thanks for reporting this, and for figuring out that the verbose output would be helpful! Good bug reports are wonderful.

As you've already figured, this is actually an issue with ExtUtils::nvcc.(Obviously this proves that I need to put better tests in ExtUtils::nvcc.) I don't know if there's any way for me to transfer this bug to that project, but that would be appropriate. If you could reopen this bug in that project, I'd really appreciate it. That having been said, I'll be happy to work on this bug in this issue tracker if you prefer.

My first guess at a workaround would be to try to fiddle with your ccflags. You can try doing something like this for your Build.PL file:

use Module::Build;

use strict;
use warnings;
use ExtUtils::nvcc;

# Create and tweak the config hash
my %build_config = ExtUtils::nvcc::MB;
# Get the ccflags, which we'll tweak and add to %build_config
use Config;
my $ccflags = $Config{ccflags};
$ccflags =~ s/-march=native//;
$build_config{ccflags} = $ccflags;


my $build = Module::Build->new(
    module_name => 'CUDA::Minimal',
    license => 'perl',
    build_requires => {
        'ExtUtils::nvcc' => '0.03',
        # 'ExtUtils::CBuilder' => '0',
    },
    requires => {
        'perl' => '0',
    },
    dist_author => 'David Mertens <dcmertens.perl@gmail.com>',
    config => \%build_config,
    include_dirs => '.',
);

$build->create_build_script;

That simply removes the -march part of ccflags. I think that should do it.

While we're at it, it looks like you have a 64 bit machine. Is this correct? Also, what OS are you running?

David

@jnareb
Copy link
Author

jnareb commented Jul 3, 2011

Unfortunately the -march=native comes from different source. With Build.PL modified to look like below:

use Module::Build;

use strict;
use warnings;
use ExtUtils::nvcc;
use Data::Dumper;

# Create and tweak the config hash
my %build_config = ExtUtils::nvcc::MB('verbose');
# Get the ccflags, which we'll tweak and add to %build_config
use Config;
my $ccflags = $Config{ccflags};
$ccflags =~ s/-march=native//;
$build_config{ccflags} = $ccflags;

print Dumper(\%build_config);
print Dumper({ map { $_ => $Config{$_} }
               grep { defined $Config{$_} && $Config{$_} =~ m/native/; }
               keys %Config });

my $build = Module::Build->new(
    module_name => 'CUDA::Minimal',
    license => 'perl',
    build_requires => {
                'ExtUtils::nvcc' => '0.01',
#               'ExtUtils::CBuilder' => '0',
            },
    requires => {
                'perl' => '0',
            },
    dist_author => 'David Mertens <dcmertens.perl@gmail.com>',
    config => \%build_config,
    include_dirs => '.',
);

print "Compiler is ", $build->config('cc'), "\n";
print "Linker is ", $build->config('ld'), "\n";

$build->create_build_script;

I get

$VAR1 = {
          'ccflags' => '-fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
          'cc' => '/usr/bin/perl5.12.3 -MExtUtils::nvcc::Backend -e"ExtUtils::nvcc::Backend::verbose;ExtUtils::nvcc::Backend::compiler" --',
          'ld' => '/usr/bin/perl5.12.3 -MExtUtils::nvcc::Backend -e"ExtUtils::nvcc::Backend::verbose;ExtUtils::nvcc::Backend::linker" --'
        };
$VAR1 = {
          'lddlflags' => '-shared -O2 -pipe -march=native -Wl,-O1 -Wl,--as-needed',
          'config_args' => '-des -Duseshrplib -Darchname=x86_64-linux -Dcc=x86_64-pc-linux-gnu-gcc -Doptimize=-O2 -pipe -march=native -Dldflags=-Wl,-O1 -Wl,--as-needed -Dprefix=/usr -Dsiteprefix=/usr -Dvendorprefix=/usr -Dscriptdir=/usr/bin -Dprivlib=/usr/lib64/perl5/5.12.3 -Darchlib=/usr/lib64/perl5/5.12.3/x86_64-linux -Dsitelib=/usr/lib64/perl5/site_perl/5.12.3 -Dsitearch=/usr/lib64/perl5/site_perl/5.12.3/x86_64-linux -Dvendorlib=/usr/lib64/perl5/vendor_perl/5.12.3 -Dvendorarch=/usr/lib64/perl5/vendor_perl/5.12.3/x86_64-linux -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/share/man/man1 -Dsiteman3dir=/usr/share/man/man3 -Dvendorman1dir=/usr/share/man/man1 -Dvendorman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3pm -Dlibperl=libperl.so.5.12.3 -Dlocincpth=  -Duselargefiles -Dd_semctl_semun -Dcf_by=Gentoo -Dmyhostname=localhost -Dperladmin=root@localhost -Dinstallusrbinperl=n -Ud_csh -Uusenm -Di_ndbm -Di_gdbm -Di_db -DDEBUGGING=none -Dinc_version_list=5.12.2/x86_64-linux 5.12.2 5.12.1/x86_64-linux 5.12.1 5.12.0/x86_64-linux 5.12.0  -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64',
          'config_arg5' => '-Doptimize=-O2 -pipe -march=native',
          'optimize' => '-O2 -pipe -march=native'
        };
Making verbose
ExtUtils::nvcc found nvcc args [[-I/usr/lib64/perl5/5.12.3/x86_64-linux/CORE]], [[-c]], [[-D_LARGEFILE_SOURCE]], [[-D_FILE_OFFSET_BITS=64]], [[-O2]], [[-o]], [[compilet-HGMU4.o]]
ExtUtils::nvcc found other args [[-fPIC]], [[-fno-strict-aliasing]], [[-pipe]], [[-pipe]], [[-march=native]]
ExtUtils::nvcc found source files [[compilet-HGMU4.c]]
Running nvcc with args [[-Xcompiler=-fPIC,-fno-strict-aliasing,-pipe,-pipe,-march=native]], [[-I/usr/lib64/perl5/5.12.3/x86_64-linux/CORE]], [[-c]], [[-D_LARGEFILE_SOURCE]], [[-D_FILE_OFFSET_BITS=64]], [[-O2]], [[-o]], [[compilet-HGMU4.o]], [[--x=cu]], [[compilet-HGMU4.c]]
Making verbose
ExtUtils::nvcc found nvcc args [[-shared]], [[-O2]], [[-o]], [[compilet-HGMU4.so]]
ExtUtils::nvcc found other args [[-pipe]], [[-march=native]], [[-Wl,-O1]], [[-Wl,--as-needed]]
ExtUtils::nvcc found source files [[compilet-HGMU4.o]]
Running nvcc with args [[-Xlinker=-pipe,-march=native,-Wl,-O1,-Wl,--as-needed]], [[-shared]], [[-O2]], [[-o]], [[compilet-HGMU4.so]], [[compilet-HGMU4.o]]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/../../../../x86_64-pc-linux-gnu/bin/ld: unrecognised emulation mode: arch=native
Supported emulations: elf_x86_64 elf_i386 i386linux elf_l1om
collect2: ld returned 1 exit status
nvcc encountered a problem
Warning: ExtUtils::CBuilder not installed or no compiler detected
Proceeding with configuration, but compilation may fail during Build

Compiler is /usr/bin/perl5.12.3 -MExtUtils::nvcc::Backend -e"ExtUtils::nvcc::Backend::verbose;ExtUtils::nvcc::Backend::compiler" --
Linker is /usr/bin/perl5.12.3 -MExtUtils::nvcc::Backend -e"ExtUtils::nvcc::Backend::verbose;ExtUtils::nvcc::Backend::linker" --
Creating new 'MYMETA.yml' with configuration results
Creating new 'Build' script for 'CUDA-Minimal' version '0.01'

This is Linux 2.6.36-gentoo-r4, on AMD Opteron (x86_64), with GeForce GTX 480, and CUDA 4.0.13

@run4flat
Copy link
Owner

run4flat commented Jul 3, 2011

I'm afraid this may be a much harder problem than I had at first anticipated. Neither Module::Build nor ExtUtils::MakeMaker allow you to tweak all of the compiler settings. (That's one reason why ExtUtils::nvcc attempts to process all the arguments from the command-line invocation.) ExtUtils::MakeMaker might be an easier route for tweaking since you could hack on the Makefile after it's written.

At this point, the easiest route might be to modify ExtUtils::nvcc's argument processing function. It is in ExtUtils/nvcc/Backend.pm, called sub process_args. That function is essentially a series of elsif clauses. (It's a ridiculous hack, but it works for now.) The first elsif is a Fedora 14 hack, and you could put a specific check in there, something like:

        #*#*# Edge case for native architecture flag which gives trouble:
        elsif ($_ eq '-march=native') {
                # Just skip it for now
                next;
        }

Could you try adding that to ExtUtils::nvcc::Backend?

David

@run4flat
Copy link
Owner

run4flat commented Jul 3, 2011

By the way, what version of gcc are you using? nVidia only supports through gcc v. 4.3, I think. See this post for hints if you run into trouble there: http://forums.nvidia.com/index.php?showtopic=199014

@jnareb
Copy link
Author

jnareb commented Jul 3, 2011

Well, I have added exception to sub process_args, then there was ld: unrecognized option '-pipe'. When I added exception for that, then there was ld: unrecognized option '-Wl'... and then I realized that I am looking in wrong place.

What needs to be fixed in ExtUtils::nvcc is the line linker subroutine in ExtUtils::nvcc::Backend module that composes "-Xlinker=<opts>" option. It is:

    # Set up the flags for the compiler arguments:
    unshift @nvcc_args, ("-Xlinker=" . join ',', @other_args)
        if @other_args;

and it should be

    # Set up the flags for the compiler arguments:
    unshift @nvcc_args, ("-Xlinker=" . join ',', map { s/^-Wl,// ? $_ : () } @other_args)
        if @other_args;

I'll try to pass this bugreport to RT for ExtUtils-nvcc ("try to" because I have problems using RT web interface).

@jnareb
Copy link
Author

jnareb commented Jul 3, 2011

gcc (Gentoo 4.4.5 p1.2, pie-0.4.5) 4.4.5

@jnareb
Copy link
Author

jnareb commented Jul 3, 2011

I'll try to pass this bugreport to RT for ExtUtils-nvcc ("try to" because I have problems using RT web interface).

I used GitHub Issues for perl_nvcc instead. You can find bugreport here: run4flat/perl_nvcc#1

@run4flat
Copy link
Owner

run4flat commented Jul 3, 2011

Yeah, tracking this bug on Github may be easier than using CPAN's RT. I'm going to mark this as closed. Anybody following along should refer to run4flat/perl_nvcc#1 for further developments.

@run4flat run4flat closed this as completed Jul 3, 2011
@run4flat
Copy link
Owner

run4flat commented Jul 3, 2011

Hmm... does gentoo offer nvcc in ports? nVidia doesn't seem to officially support gentoo: http://developer.nvidia.com/cuda-toolkit-40

@jnareb
Copy link
Author

jnareb commented Jul 3, 2011

This is university machine, not mine, and not administered by me... but guessing from location of CUDA in /common/ subdirectory on computation nodes it is installed outside of ports (in a few versions: 3.2, 4.0.11, 4.0.13); nvcc is in /common/cuda-4.0.13/bin/nvcc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants