Пример #1
0
def openblas_version():
    '''
    Check for OpenBLAS version via OPENBLAS_VERSION constant.
    '''
    config.print_test( 'OpenBLAS version' )
    (rc, out, err) = config.compile_run( 'config/openblas_version.cc' )
    s = re.search( r'^OPENBLAS_VERSION=.*?((\d+)\.(\d+)\.(\d+))', out )
    if (rc == 0 and s):
        config.environ.append( 'CXXFLAGS', '-DHAVE_OPENBLAS' )
        config.print_result( 'OpenBLAS', rc, '(' + s.group(1) + ')' )
    else:
        config.print_result( 'OpenBLAS', rc )
Пример #2
0
def essl_version():
    '''
    Check for ESSL version via iessl().
    '''
    config.print_test( 'ESSL version' )
    (rc, out, err) = config.compile_run( 'config/essl_version.cc' )
    s = re.search( r'^ESSL_VERSION=((\d+)\.(\d+)\.(\d+)\.(\d+))', out )
    if (rc == 0 and s):
        config.environ.append( 'CXXFLAGS', '-DHAVE_ESSL' )
        config.print_result( 'ESSL', rc, '(' + s.group(1) + ')' )
    else:
        config.print_result( 'ESSL', rc )
Пример #3
0
def lapack_version():
    '''
    Check for LAPACK version using ilaver().
    '''
    config.print_test( 'LAPACK version' )
    (rc, out, err) = config.compile_run( 'config/lapack_version.cc' )
    s = re.search( r'^LAPACK_VERSION=((\d+)\.(\d+)\.(\d+))', out )
    if (rc == 0 and s):
        v = '%d%02d%02d' % (int(s.group(2)), int(s.group(3)), int(s.group(4)))
        config.environ.append( 'CXXFLAGS', '-DLAPACK_VERSION=%s' % v )
        config.print_result( 'LAPACK', rc, '(' + s.group(1) + ')' )
    else:
        config.print_result( 'LAPACK', rc )
Пример #4
0
def compile_with_manglings( src, env, manglings, int_sizes ):
    '''
    Tries to compile, link, and run source file src with each of the given
    manglings and integer sizes.
    Returns (returncode, stdout, stderr, env_copy)
    from either the successful run or the last unsuccessful run.

    Ex: compile_with_manglings( 'test.cc', {'CXXFLAGS': '-Wall'},
                                ['-DFORTRAN_ADD_', '-DFORTRAN_LOWER'],
                                ['', '-DBLAS_ILP64'] )
    tests:
        CXX -Wall -DFORTRAN_ADD_               test.cc
        CXX -Wall -DFORTRAN_ADD_ -DBLAS_ILP64  test.cc
        CXX -Wall -DFORTRAN_LOWER              test.cc
        CXX -Wall -DFORTRAN_LOWER -DBLAS_ILP64 test.cc
    '''
    rc = -1
    for mangling in manglings:
        for size in int_sizes:
            print_test( '    ' + mangling +' '+ size )
            # modify a copy to save in passed
            env2 = env.copy()
            env2['CXXFLAGS'] = get(env2, 'CXXFLAGS') +' '+ mangling +' '+ size
            (rc_link, out, err) = config.compile_exe( 'config/hello.cc', env2 )
            # if hello didn't link, assume library not found
            if (rc_link != 0):
                print_result( 'label', rc_link )
                break

            (rc, out, err) = config.compile_exe( src, env2 )
            # if int32 didn't link, int64 won't either
            if (rc != 0):
                print_result( 'label', rc )
                break

            # if int32 runs, skip int64
            (rc, out, err) = config.run_exe( src )
            print_result( 'label', rc )
            if (rc == 0):
                break
        # end
        # break if library not found or on first mangling that works
        if (rc_link != 0 or rc == 0):
            break
    # end
    return (rc, out, err, env2)
Пример #5
0
def test_lapack( src, label, append=False ):
    '''
    Used by lapack() and lapack_uncommon() to search for LAPACK routines,
    first in already found libraries, then in -llapack.
    Rechecks Fortran name mangling if -llapack exists but linking fails.
    '''
    # try in BLAS library
    print_test( label + ' available' )
    (rc, out, err) = config.compile_obj( src )
    if (rc != 0):
        raise Error

    (rc, out, err) = config.link_exe( src )
    if (rc == 0):
        (rc, out, err) = config.run_exe( src )
        print_result( 'label', rc )
        if (rc != 0):
            raise Error( 'LAPACK linked, but failed to run' )
        # Otherwise, success! See also lapack().
    else:
        # Default failed, try with -llapack
        print_result( 'label', rc )
        print_test( label + ' in -llapack' )
        env = {'LIBS': '-llapack'}
        (rc, out, err) = config.compile_exe( 'config/hello.cc', env )
        if (rc == 0):
            # -llapack exists
            (rc, out, err) = config.compile_obj( src, env )
            if (rc != 0):
                raise Error( 'Unexpected error: ' + src + ' failed to compile' )

            (rc, out, err) = config.link_exe( src, env )
            if (rc == 0):
                # -llapack linked
                (rc, out, err) = config.run_exe( src, env )
                print_result( 'label', rc )
                if (rc == 0):
                    # Success! -llapack worked. See also lapack().
                    if (append):
                        config.environ.append( 'LIBS', env['LIBS'] )
                    else:
                        config.environ.merge( env )
                else:
                    raise Error( 'LAPACK linked -llapack, but failed to run' )
                # end
            else:
                print_result( 'label', rc )
                # -llapack exists but didn't link
                print_subhead( '-llapack exists, but linking failed. Re-checking Fortran mangling.' )
                # Get, then undef, original mangling & int_sizes.
                cxxflags = config.environ['CXXFLAGS']
                old_mangling_sizes = re.findall(
                    r'-D(FORTRAN_(?:ADD_|LOWER|UPPER)|\w*ILP64)\b', cxxflags )
                config.environ['CXXFLAGS'] = re.sub(
                    r'-D(FORTRAN_(?:ADD_|LOWER|UPPER)|\w*ILP64|ADD_|NOCHANGE|UPCASE)\b',
                    r'', cxxflags )
                manglings = get_fortran_manglings()
                int_sizes = get_int_sizes()
                (rc, out, err, env) = compile_with_manglings(
                    src, env, manglings, int_sizes )
                if (rc == 0):
                    (rc, out, err) = config.compile_run( 'config/blas.cc', env,
                        'Re-checking Fortran mangling for BLAS' )
                    if (rc == 0):
                        # Success! See also lapack().
                        new_mangling_sizes = re.findall(
                            r'-D(FORTRAN_(?:ADD_|LOWER|UPPER)|\w*ILP64)\b',
                            env['CXXFLAGS'])
                        print( font.red(
                               'Changing Fortran name mangling for both BLAS and LAPACK to '
                               + ' '.join( new_mangling_sizes ) ) )
                        config.environ.merge( env )

                    else:
                        raise Error( 'BLAS and LAPACK require different Fortran name manglings' )
                    # end
                else:
                    raise Error( 'No Fortran name mangling worked for LAPACK (seems odd).' )
                # end
            # end
        else:
            # -llapack doesn't exist
            print_result( 'label', rc )
            raise Error( 'LAPACK not found' )