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

Enable updated Accelerate headers for Darin kernel >= 22.4 #8099

Merged
merged 7 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ endif (GSHHG_PATH)
message(
"*\n"
"* GMT Version: : ${GMT_PACKAGE_VERSION_WITH_GIT_REVISION}\n"
"* System: : ${CMAKE_HOST_SYSTEM_NAME} (${CMAKE_HOST_SYSTEM_VERSION})\n"
"*\n"
"* Options:\n"
"* Found GSHHG database : ${GMT_CONFIG_GSHHG_MESSAGE}\n"
Expand Down
1 change: 1 addition & 0 deletions cmake/ConfigUserAdvancedTemplate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ set (GMT_ENABLE_OPENMP TRUE)
# add_definitions(-DDEBUG_MODERN) # To set PPID == 0 during Xcode test
# message("Add Xcode definition for GMT")
#endif()

# Uncomment these two statements if you are a developer debugging GMT:
#add_definitions(-DDEBUG)
#add_definitions(-DMEMDEBUG) # Turn on memory tracking; see gmt_memory .c on MEMDEBUG for information
Expand Down
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ else (LAPACK_FOUND)
endif (LAPACK_LIBRARY)
endif (LAPACK_FOUND)

# Need to know if macOS and kernel is >= 22.4.0 for newLapack syntax
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
execute_process (COMMAND bash "-c" "echo ${CMAKE_HOST_SYSTEM_VERSION} | awk -F. '{if ($1 > 22 || ($1 == 22 && $2 > 3)) {print 1} else {print 0}}'"
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ACCELERATE_NEW_LAPACK)
else (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set (ACCELERATE_NEW_LAPACK 0)
endif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")

if (HAVE_LAPACK AND ACCELERATE_NEW_LAPACK GREATER 0)
# Recent macOS with Aarwin kernel > 22.4 needs this compiler flag:
add_compile_definitions(ACCELERATE_NEW_LAPACK)
message("-- Must add compiler flag -DACCELERATE_NEW_LAPACK definition for macOS kernel version ${CMAKE_HOST_SYSTEM_VERSION}")
endif (HAVE_LAPACK AND ACCELERATE_NEW_LAPACK GREATER 0)

if (NOT DEFINED GMT_EXCLUDE_BLAS)
find_package (BLAS)
endif (NOT DEFINED GMT_EXCLUDE_BLAS)
Expand Down
17 changes: 17 additions & 0 deletions src/gmt_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,14 @@ void gmt_matrix_vect_mult (struct GMT_CTRL *GMT, unsigned int dim, double a[3][3
* Then, if LAPACK is true then gmt_matrix_matrix_mult should call dgemm_ instead of plain code.
*/

#ifndef ACCELERATE_NEW_LAPACK
/* This BLAS function is updated on macos 22.4 and higher but still included in the Accelerate Framework header.
* Otherwise we declare it as an extern function here. dsyev_ is not in BLAS so remains the same so far. */

extern int dgemm_ (char* tra, char* trb, int* na, int* nb, int* nc, double* alpha, double* a, int *nd, double* b, int *ne, double* beta, double* c, int* nf);

#endif

void gmt_matrix_vector_mult (struct GMT_CTRL *GMT, double *A, double *b, uint64_t n_rowsA, uint64_t n_colsA, double *c) {
uint64_t row, col, ij;
gmt_M_unused(GMT);
Expand Down Expand Up @@ -1361,7 +1367,18 @@ void gmt_matrix_matrix_mult (struct GMT_CTRL *GMT, double *A, double *B, uint64_
ne = nf = (int)n_rowsB;
}
#endif

#ifdef ACCELERATE_NEW_LAPACK
/* Must cast the arguemnts to avoid a tantrum from Apple */
dgemm_ ((const char * _Nonnull)"t", (const char * _Nonnull)tr,
(const __LAPACK_int * _Nonnull)&na, (const __LAPACK_int * _Nonnull)&nb, (const __LAPACK_int * _Nonnull)&nc,
(const double * _Nonnull)&one, (const double * _Nullable) A, (const __LAPACK_int * _Nonnull)&nd,
(const double * _Nullable) B, (const __LAPACK_int * _Nonnull)&ne,
(const double * _Nonnull)&zero, (double * _Nullable)C, (const __LAPACK_int * _Nonnull)&nf);
#else
dgemm_ ("t", tr, &na, &nb, &nc, &one, A, &nd, B, &ne, &zero, C, &nf);
#endif

#else
/* Plain matrix multiplication, no speed up; space must exist */
uint64_t row, col, k, a_ij, b_ij, c_ij, n_colsA = n_rowsB;
Expand Down