Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,38 @@

//------------------------------------------------------------------------------
#if defined(BLAS_ILP64) || defined(LAPACK_ILP64)
typedef int64_t blas_int;
typedef int64_t lapack_int;
// long is >= 32 bits, long long is >= 64 bits
// macOS Accelerate uses long, Intel MKL uses long long,
// prefer int64_t (which can be long or long long).
#ifdef BLAS_HAVE_ACCELERATE
#pragma message "Accelerate ilp64 (long)"
#define ACCELERATE_LAPACK_ILP64
typedef long blas_int;
typedef long lapack_int;
#else
#pragma message "ilp64 (int64_t)"
typedef int64_t blas_int;
typedef int64_t lapack_int;
#endif
#else
typedef int blas_int;
typedef int lapack_int;
#endif

//------------------------------------------------------------------------------
#ifndef BLAS_FORTRAN_STRLEN_END
#define BLAS_FORTRAN_STRLEN_END
#endif
#ifdef BLAS_HAVE_ACCELERATE
// Neither old nor new macOS Accelerate API passes strlen.
#pragma message "Accelerate undef strlen"
#undef BLAS_FORTRAN_STRLEN_END
#undef LAPACK_FORTRAN_STRLEN_END
#else
#ifndef BLAS_FORTRAN_STRLEN_END
#define BLAS_FORTRAN_STRLEN_END
#endif

#ifndef LAPACK_FORTRAN_STRLEN_END
#define LAPACK_FORTRAN_STRLEN_END
#ifndef LAPACK_FORTRAN_STRLEN_END
#define LAPACK_FORTRAN_STRLEN_END
#endif
#endif

#endif // CONFIG_H
25 changes: 23 additions & 2 deletions config/lapack.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,31 @@ def blas():
inc = '-I' + p + ' ' + define('HAVE_ACCELERATE_CBLAS_H') + ' '
break

flags = inc + define('HAVE_ACCELERATE')
new_lapack = ' -DACCELERATE_NEW_LAPACK'
# macOS 13.3, g++ 12.2 requires extra flags to parse Apple's headers.
version = ' -mmacosx-version-min=13.3'
extra = ' -flax-vector-conversions'

choices.append(
['macOS Accelerate (new)',
{'LIBS': '-framework Accelerate',
'CXXFLAGS': flags + new_lapack }])

choices.append(
['macOS Accelerate (new, -flax-vector-conversions)',
{'LIBS': '-framework Accelerate',
'CXXFLAGS': flags + new_lapack + version + extra }])

choices.append(
['macOS Accelerate (old, pre 13.3)',
{'LIBS': '-framework Accelerate',
'CXXFLAGS': flags }])

choices.append(
['MacOS Accelerate',
['macOS Accelerate (old, pre 13.3, -flax-vector-conversions)',
{'LIBS': '-framework Accelerate',
'CXXFLAGS': inc + define('HAVE_ACCELERATE')}])
'CXXFLAGS': flags + extra }])
# end

#-------------------- generic -lblas
Expand Down
31 changes: 19 additions & 12 deletions config/lapack_potrf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@

#include "config.h"

//------------------------------------------------------------------------------
#define LAPACK_dpotrf_base FORTRAN_NAME( dpotrf, DPOTRF )

#ifdef __cplusplus
extern "C"
#endif
void LAPACK_dpotrf_base(
const char* uplo, const lapack_int* n,
double* A, const lapack_int* lda,
lapack_int* info
#ifdef LAPACK_FORTRAN_STRLEN_END
, size_t uplo_len
#endif
);

#ifdef LAPACK_FORTRAN_STRLEN_END
#define LAPACK_dpotrf( ... ) LAPACK_dpotrf_base( __VA_ARGS__, 1 )
#else
#define LAPACK_dpotrf( ... ) LAPACK_dpotrf_base( __VA_ARGS__ )
#endif

#ifdef ACCELERATE_NEW_LAPACK
#pragma message "include Accelerate.h"
#include <stdlib.h> // workaround
Comment thread
mmelnich marked this conversation as resolved.
Outdated
#include <Accelerate/Accelerate.h>
#else
#ifdef __cplusplus
extern "C"
#endif
void LAPACK_dpotrf_base(
const char* uplo, const lapack_int* n,
double* A, const lapack_int* lda,
lapack_int* info
#ifdef LAPACK_FORTRAN_STRLEN_END
, size_t uplo_len
#endif
);
#endif

//------------------------------------------------------------------------------
int main()
{
Expand Down
37 changes: 22 additions & 15 deletions config/lapack_pstrf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@

#include "config.h"

//------------------------------------------------------------------------------
#define LAPACK_dpstrf_base FORTRAN_NAME( dpstrf, DPSTRF )

#ifdef __cplusplus
extern "C"
#endif
void LAPACK_dpstrf_base(
const char* uplo, const lapack_int* n,
double* A, const lapack_int* lda,
lapack_int* ipiv, lapack_int* rank,
const double* tol,
double* work,
lapack_int* info
#ifdef LAPACK_FORTRAN_STRLEN_END
, size_t uplo_len
#endif
);

#ifdef LAPACK_FORTRAN_STRLEN_END
#define LAPACK_dpstrf( ... ) LAPACK_dpstrf_base( __VA_ARGS__, 1 )
#else
#define LAPACK_dpstrf( ... ) LAPACK_dpstrf_base( __VA_ARGS__ )
#endif

#ifdef ACCELERATE_NEW_LAPACK
#pragma message "include Accelerate.h"
#include <stdlib.h> // workaround
#include <Accelerate/Accelerate.h>
#else
#ifdef __cplusplus
extern "C"
#endif
void LAPACK_dpstrf_base(
const char* uplo, const lapack_int* n,
double* A, const lapack_int* lda,
lapack_int* ipiv, lapack_int* rank,
const double* tol,
double* work,
lapack_int* info
#ifdef LAPACK_FORTRAN_STRLEN_END
, size_t uplo_len
#endif
);
#endif

//------------------------------------------------------------------------------
int main()
{
Expand Down
15 changes: 12 additions & 3 deletions config/lapack_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@

#define LAPACK_ilaver FORTRAN_NAME( ilaver, ILAVER )

#ifdef __cplusplus
extern "C"
#ifdef ACCELERATE_NEW_LAPACK
// A self-declared undecorated prototype would silently bind the legacy
// LAPACK 3.2.1 symbol; Apple's header carries the $NEWLAPACK asm-label
// decoration on ilaver_.
#pragma message "include Accelerate.h"
#include <stdlib.h> // workaround
#include <Accelerate/Accelerate.h>
#else
#ifdef __cplusplus
extern "C"
#endif
void LAPACK_ilaver( lapack_int* major, lapack_int* minor, lapack_int* patch );
#endif
void LAPACK_ilaver( lapack_int* major, lapack_int* minor, lapack_int* patch );

int main( int argc, char** argv )
{
Expand Down
18 changes: 16 additions & 2 deletions include/lapack/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@
#define LAPACK_ILP64
#endif

#ifdef ACCELERATE_NEW_LAPACK
// Apple's headers use std::complex in C++ and, for ILP64, `long`
// (a distinct type from int64_t == long long on LP64 Darwin).
#if defined(__cplusplus) && ! defined(LAPACK_COMPLEX_CPP)
#define LAPACK_COMPLEX_CPP
#endif
#if defined(LAPACK_ILP64) && ! defined(ACCELERATE_LAPACK_ILP64)
#define ACCELERATE_LAPACK_ILP64
#endif
#endif

#ifndef lapack_int
#ifdef LAPACK_ILP64
#if defined(LAPACK_ILP64) && defined(ACCELERATE_NEW_LAPACK)
typedef long lapack_int; // matches Apple's __LAPACK_int
#elif defined(LAPACK_ILP64)
typedef int64_t lapack_int;
#else
typedef int lapack_int;
Expand All @@ -34,7 +47,8 @@
// for sdot, slange, clange, etc.
// LAPACKE's lapack.h is missing #define to protect against multiple
// definitions, so use lapackpp prefix.
#if defined(BLAS_HAVE_ACCELERATE) || defined(BLAS_HAVE_F2C)
#if (defined(BLAS_HAVE_ACCELERATE) && ! defined(ACCELERATE_NEW_LAPACK)) \
|| defined(BLAS_HAVE_F2C)
typedef double lapackpp_float_return;
#else
typedef float lapackpp_float_return;
Expand Down
Loading
Loading