Skip to content

Commit 113410d

Browse files
authored
Merge pull request #5904 from moluopro/fix/xerbla-handler
Add a portable XERBLA handler API
2 parents b668c9a + 6720959 commit 113410d

36 files changed

Lines changed: 452 additions & 328 deletions

CMakeLists.txt

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -734,18 +734,46 @@ if(NOT NO_CBLAS)
734734
set(CBLAS_H ${CMAKE_BINARY_DIR}/generated/cblas.h)
735735
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cblas.h CBLAS_H_CONTENTS)
736736
string(REPLACE "common" "openblas_config" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
737+
738+
# Symbol prefix/suffix settings rename exported functions, not C typedefs.
739+
# Protect callback type names from the textual function-name rewriting below.
740+
string(REPLACE "openblas_dojob_callback" "OPENBLAS_DOJOB_CALLBACK_TYPE"
741+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
742+
string(REPLACE "openblas_threads_callback" "OPENBLAS_THREADS_CALLBACK_TYPE"
743+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
744+
string(REPLACE "openblas_xerbla_handler" "OPENBLAS_XERBLA_HANDLER_TYPE"
745+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
746+
737747
if (NOT ${SYMBOLPREFIX} STREQUAL "")
738-
string(REPLACE " cblas" " ${SYMBOLPREFIX}cblas" CBLAS_H_CONTENTS "${CBLAS_H_CONTENTS_NEW}")
739-
string(REPLACE " openblas" " ${SYMBOLPREFIX}openblas" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
740-
string (REPLACE " ${SYMBOLPREFIX}openblas_complex" " openblas_complex" CBLAS_H_CONTENTS "${CBLAS_H_CONTENTS_NEW}")
741-
string(REPLACE " goto" " ${SYMBOLPREFIX}goto" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
748+
string(REPLACE " cblas" " ${SYMBOLPREFIX}cblas"
749+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
750+
string(REPLACE " openblas" " ${SYMBOLPREFIX}openblas"
751+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
752+
string(REPLACE " ${SYMBOLPREFIX}openblas_complex" " openblas_complex"
753+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
754+
string(REPLACE " goto" " ${SYMBOLPREFIX}goto"
755+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
742756
endif()
743757
if (NOT ${SYMBOLSUFFIX} STREQUAL "")
744-
string(REGEX REPLACE "(cblas[^ (]*)" "\\1${SYMBOLSUFFIX}" CBLAS_H_CONTENTS "${CBLAS_H_CONTENTS_NEW}")
745-
string(REGEX REPLACE "(openblas[^ (]*)" "\\1${SYMBOLSUFFIX}" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
746-
string(REGEX REPLACE "(openblas_complex[^ ]*)${SYMBOLSUFFIX}" "\\1" CBLAS_H_CONTENTS "${CBLAS_H_CONTENTS_NEW}")
747-
string(REGEX REPLACE "(goto[^ (]*)" "\\1${SYMBOLSUFFIX}" CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS}")
748-
endif()
758+
string(REGEX REPLACE "(cblas[A-Za-z0-9_]*)" "\\1${SYMBOLSUFFIX}"
759+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
760+
string(REGEX REPLACE "(openblas[A-Za-z0-9_]*)" "\\1${SYMBOLSUFFIX}"
761+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
762+
string(REPLACE "openblas_config${SYMBOLSUFFIX}" "openblas_config"
763+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
764+
string(REGEX REPLACE "(openblas_complex[A-Za-z0-9_]*)${SYMBOLSUFFIX}" "\\1"
765+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
766+
string(REGEX REPLACE "(goto[A-Za-z0-9_]*)" "\\1${SYMBOLSUFFIX}"
767+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
768+
endif()
769+
770+
string(REPLACE "OPENBLAS_DOJOB_CALLBACK_TYPE" "openblas_dojob_callback"
771+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
772+
string(REPLACE "OPENBLAS_THREADS_CALLBACK_TYPE" "openblas_threads_callback"
773+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
774+
string(REPLACE "OPENBLAS_XERBLA_HANDLER_TYPE" "openblas_xerbla_handler"
775+
CBLAS_H_CONTENTS_NEW "${CBLAS_H_CONTENTS_NEW}")
776+
749777
file(WRITE ${CBLAS_H} "${CBLAS_H_CONTENTS_NEW}")
750778
install (FILES ${CBLAS_H} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
751779
endif()

Makefile.install

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ install : lib.grd
7373

7474
ifneq ($(NO_CBLAS),1)
7575
@echo Generating cblas.h in $(DESTDIR)$(OPENBLAS_INCLUDE_DIR)
76-
@cp cblas.h cblas.tmp
76+
@sed -e 's/openblas_dojob_callback/OPENBLAS_DOJOB_CALLBACK_TYPE/g' \
77+
-e 's/openblas_threads_callback/OPENBLAS_THREADS_CALLBACK_TYPE/g' \
78+
-e 's/openblas_xerbla_handler/OPENBLAS_XERBLA_HANDLER_TYPE/g' \
79+
cblas.h > cblas.tmp
7780
ifdef SYMBOLPREFIX
7881
@sed 's/cblas[^() ]*/$(SYMBOLPREFIX)&/g' cblas.tmp > cblas.tmp2
7982
@sed 's/openblas[^() ]*/$(SYMBOLPREFIX)&/g' cblas.tmp2 > cblas.tmp
@@ -88,7 +91,11 @@ ifdef SYMBOLSUFFIX
8891
@sed 's/\(openblas_complex_\)\([^ ]*\)$(SYMBOLSUFFIX)/\1\2 /g' cblas.tmp > cblas.tmp2
8992
@sed 's/goto[^() ]*/&$(SYMBOLSUFFIX)/g' cblas.tmp2 > cblas.tmp
9093
endif
91-
@sed 's/common/openblas_config/g' cblas.tmp > "$(DESTDIR)$(OPENBLAS_INCLUDE_DIR)/cblas.h"
94+
@sed -e 's/OPENBLAS_DOJOB_CALLBACK_TYPE/openblas_dojob_callback/g' \
95+
-e 's/OPENBLAS_THREADS_CALLBACK_TYPE/openblas_threads_callback/g' \
96+
-e 's/OPENBLAS_XERBLA_HANDLER_TYPE/openblas_xerbla_handler/g' \
97+
-e 's/common/openblas_config/g' \
98+
cblas.tmp > "$(DESTDIR)$(OPENBLAS_INCLUDE_DIR)/cblas.h"
9299
endif
93100

94101
ifneq ($(OSNAME), AIX)

cblas.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ typedef void (*openblas_dojob_callback)(int thread_num, void *jobdata, int dojob
5959
typedef void (*openblas_threads_callback)(int sync, openblas_dojob_callback dojob, int numjobs, size_t jobdata_elsize, void *jobdata, int dojob_data);
6060
void openblas_set_threads_callback_function(openblas_threads_callback callback);
6161

62+
/* Replace the XERBLA handler for this OpenBLAS instance and return the
63+
* previous handler. Passing NULL restores the default. Callbacks may run
64+
* concurrently and must be thread-safe. The name and info pointers are valid
65+
* only during the callback; name spans name_length bytes and need not be
66+
* NUL-terminated. Replacement is thread-safe but does not wait for in-flight
67+
* calls, so the previous handler must remain loaded until they complete. */
68+
#ifndef OPENBLAS_XERBLA_HANDLER_DEFINED
69+
#define OPENBLAS_XERBLA_HANDLER_DEFINED
70+
typedef void (*openblas_xerbla_handler)(const char *name,
71+
const blasint *info,
72+
size_t name_length);
73+
#endif
74+
openblas_xerbla_handler openblas_set_xerbla(openblas_xerbla_handler handler);
75+
6276
#ifdef OPENBLAS_OS_LINUX
6377
/* Sets thread affinity for OpenBLAS threads. `thread_idx` is in [0, openblas_get_num_threads()-1]. */
6478
int openblas_setaffinity(int thread_idx, size_t cpusetsize, cpu_set_t* cpu_set);

common.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,26 @@ typedef struct {
880880
#endif
881881

882882
#include "common_interface.h"
883+
884+
/* Internal declaration of the public C XERBLA callback API. Keep this out of
885+
* common_interface.h, whose contents are copied verbatim into f77blas.h and
886+
* are not adjusted for SYMBOLPREFIX/SYMBOLSUFFIX by the CMake build. */
887+
#ifndef ASSEMBLER
888+
#ifdef __cplusplus
889+
extern "C" {
890+
#endif
891+
#ifndef OPENBLAS_XERBLA_HANDLER_DEFINED
892+
#define OPENBLAS_XERBLA_HANDLER_DEFINED
893+
typedef void (*openblas_xerbla_handler)(const char *name,
894+
const blasint *info,
895+
size_t name_length);
896+
#endif
897+
openblas_xerbla_handler openblas_set_xerbla(openblas_xerbla_handler handler);
898+
#ifdef __cplusplus
899+
}
900+
#endif
901+
#endif
902+
883903
#ifdef SANITY_CHECK
884904
#include "common_reference.h"
885905
#endif

ctest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if(WIN32)
1818
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_cblas_helper.ps1
1919
"$ErrorActionPreference = \"Stop\"\n"
2020
"Get-Content $args[1] | & $args[0]\n"
21+
"exit $LASTEXITCODE\n"
2122
)
2223
set(test_helper powershell -ExecutionPolicy Bypass "${CMAKE_CURRENT_BINARY_DIR}/test_cblas_helper.ps1")
2324
else()

ctest/c_c2chke.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
#include "cblas_test.h"
55

66
int cblas_ok, cblas_lerr, cblas_info;
7-
int link_xerbla=TRUE;
87
char *cblas_rout;
98

10-
#ifdef F77_Char
11-
void F77_xerbla(F77_Char F77_srname, void *vinfo);
12-
#else
13-
void F77_xerbla(char *srname, void *vinfo);
14-
#endif
15-
169
void chkxer(void) {
1710
extern int cblas_ok, cblas_lerr, cblas_info;
18-
extern int link_xerbla;
1911
extern char *cblas_rout;
2012
if (cblas_lerr == 1 ) {
21-
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %d NOT DETECTED BY %s *****\n", cblas_info, cblas_rout);
13+
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %lld NOT DETECTED BY %s *****\n",
14+
(long long)cblas_info, cblas_rout);
2215
cblas_ok = 0 ;
2316
}
2417
cblas_lerr = 1 ;
@@ -36,11 +29,7 @@ void F77_c2chke(char *rout) {
3629
extern int RowMajorStrg;
3730
extern char *cblas_rout;
3831

39-
if (link_xerbla) /* call these first to link */
40-
{
41-
cblas_xerbla(cblas_info,cblas_rout,"");
42-
F77_xerbla(cblas_rout,&cblas_info);
43-
}
32+
cblas_test_set_xerbla();
4433

4534
cblas_ok = TRUE ;
4635
cblas_lerr = PASSED ;
@@ -821,6 +810,8 @@ void F77_c2chke(char *rout) {
821810
}
822811
if (cblas_ok == TRUE)
823812
printf(" %-12s PASSED THE TESTS OF ERROR-EXITS\n", cblas_rout);
824-
else
813+
else {
825814
printf("******* %s FAILED THE TESTS OF ERROR-EXITS *******\n",cblas_rout);
815+
cblas_test_fail();
816+
}
826817
}

ctest/c_c3chke.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
#include "cblas_test.h"
55

66
int cblas_ok, cblas_lerr, cblas_info;
7-
int link_xerbla=TRUE;
87
char *cblas_rout;
98

10-
#ifdef F77_Char
11-
void F77_xerbla(F77_Char F77_srname, void *vinfo);
12-
#else
13-
void F77_xerbla(char *srname, void *vinfo);
14-
#endif
15-
169
void chkxer(void) {
1710
extern int cblas_ok, cblas_lerr, cblas_info;
18-
extern int link_xerbla;
1911
extern char *cblas_rout;
2012
if (cblas_lerr == 1 ) {
21-
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %d NOT DETECTED BY %s *****\n", cblas_info, cblas_rout);
13+
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %lld NOT DETECTED BY %s *****\n",
14+
(long long)cblas_info, cblas_rout);
2215
cblas_ok = 0 ;
2316
}
2417
cblas_lerr = 1 ;
@@ -39,11 +32,7 @@ void F77_c3chke(char * rout) {
3932
cblas_ok = TRUE ;
4033
cblas_lerr = PASSED ;
4134

42-
if (link_xerbla) /* call these first to link */
43-
{
44-
cblas_xerbla(cblas_info,cblas_rout,"");
45-
F77_xerbla(cblas_rout,&cblas_info);
46-
}
35+
cblas_test_set_xerbla();
4736

4837

4938
if (strncmp( sf,"cblas_cgemm" ,11)==0) {
@@ -1703,6 +1692,8 @@ void F77_c3chke(char * rout) {
17031692

17041693
if (cblas_ok == 1 )
17051694
printf(" %-12s PASSED THE TESTS OF ERROR-EXITS\n", cblas_rout);
1706-
else
1695+
else {
17071696
printf("***** %s FAILED THE TESTS OF ERROR-EXITS *******\n",cblas_rout);
1697+
cblas_test_fail();
1698+
}
17081699
}

ctest/c_c3chke_3m.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
#include "cblas_test.h"
55

66
int cblas_ok, cblas_lerr, cblas_info;
7-
int link_xerbla=TRUE;
87
char *cblas_rout;
98

10-
#ifdef F77_Char
11-
void F77_xerbla(F77_Char F77_srname, void *vinfo);
12-
#else
13-
void F77_xerbla(char *srname, void *vinfo);
14-
#endif
15-
169
void chkxer(void) {
1710
extern int cblas_ok, cblas_lerr, cblas_info;
18-
extern int link_xerbla;
1911
extern char *cblas_rout;
2012
if (cblas_lerr == 1 ) {
21-
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %d NOT DETECTED BY %s *****\n", cblas_info, cblas_rout);
13+
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %lld NOT DETECTED BY %s *****\n",
14+
(long long)cblas_info, cblas_rout);
2215
cblas_ok = 0 ;
2316
}
2417
cblas_lerr = 1 ;
@@ -39,11 +32,7 @@ void F77_c3chke(char * rout) {
3932
cblas_ok = TRUE ;
4033
cblas_lerr = PASSED ;
4134

42-
if (link_xerbla) /* call these first to link */
43-
{
44-
cblas_xerbla(cblas_info,cblas_rout,"");
45-
F77_xerbla(cblas_rout,&cblas_info);
46-
}
35+
cblas_test_set_xerbla();
4736

4837

4938
if (strncmp( sf,"cblas_cgemm3m" ,13)==0) {
@@ -1931,6 +1920,8 @@ void F77_c3chke(char * rout) {
19311920

19321921
if (cblas_ok == 1 )
19331922
printf(" %-12s PASSED THE TESTS OF ERROR-EXITS\n", cblas_rout);
1934-
else
1923+
else {
19351924
printf("***** %s FAILED THE TESTS OF ERROR-EXITS *******\n",cblas_rout);
1925+
cblas_test_fail();
1926+
}
19361927
}

ctest/c_d2chke.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
#include "cblas_test.h"
55

66
int cblas_ok, cblas_lerr, cblas_info;
7-
int link_xerbla=TRUE;
87
char *cblas_rout;
98

10-
#ifdef F77_Char
11-
void F77_xerbla(F77_Char F77_srname, void *vinfo);
12-
#else
13-
void F77_xerbla(char *srname, void *vinfo);
14-
#endif
15-
169
void chkxer(void) {
1710
extern int cblas_ok, cblas_lerr, cblas_info;
18-
extern int link_xerbla;
1911
extern char *cblas_rout;
2012
if (cblas_lerr == 1 ) {
21-
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %d NOT DETECTED BY %s *****\n", cblas_info, cblas_rout);
13+
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %lld NOT DETECTED BY %s *****\n",
14+
(long long)cblas_info, cblas_rout);
2215
cblas_ok = 0 ;
2316
}
2417
cblas_lerr = 1 ;
@@ -34,11 +27,7 @@ void F77_d2chke(char *rout) {
3427
extern int RowMajorStrg;
3528
extern char *cblas_rout;
3629

37-
if (link_xerbla) /* call these first to link */
38-
{
39-
cblas_xerbla(cblas_info,cblas_rout,"");
40-
F77_xerbla(cblas_rout,&cblas_info);
41-
}
30+
cblas_test_set_xerbla();
4231

4332
cblas_ok = TRUE ;
4433
cblas_lerr = PASSED ;
@@ -784,6 +773,8 @@ void F77_d2chke(char *rout) {
784773
}
785774
if (cblas_ok == TRUE)
786775
printf(" %-12s PASSED THE TESTS OF ERROR-EXITS\n", cblas_rout);
787-
else
776+
else {
788777
printf("******* %s FAILED THE TESTS OF ERROR-EXITS *******\n",cblas_rout);
778+
cblas_test_fail();
779+
}
789780
}

ctest/c_d3chke.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
#include "cblas_test.h"
55

66
int cblas_ok, cblas_lerr, cblas_info;
7-
int link_xerbla=TRUE;
87
char *cblas_rout;
98

10-
#ifdef F77_Char
11-
void F77_xerbla(F77_Char F77_srname, void *vinfo);
12-
#else
13-
void F77_xerbla(char *srname, void *vinfo);
14-
#endif
15-
169
void chkxer(void) {
1710
extern int cblas_ok, cblas_lerr, cblas_info;
18-
extern int link_xerbla;
1911
extern char *cblas_rout;
2012
if (cblas_lerr == 1 ) {
21-
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %d NOT DETECTED BY %s *****\n", cblas_info, cblas_rout);
13+
printf("***** ILLEGAL VALUE OF PARAMETER NUMBER %lld NOT DETECTED BY %s *****\n",
14+
(long long)cblas_info, cblas_rout);
2215
cblas_ok = 0 ;
2316
}
2417
cblas_lerr = 1 ;
@@ -34,11 +27,7 @@ void F77_d3chke(char *rout) {
3427
extern int RowMajorStrg;
3528
extern char *cblas_rout;
3629

37-
if (link_xerbla) /* call these first to link */
38-
{
39-
cblas_xerbla(cblas_info,cblas_rout,"");
40-
F77_xerbla(cblas_rout,&cblas_info);
41-
}
30+
cblas_test_set_xerbla();
4231

4332
cblas_ok = TRUE ;
4433
cblas_lerr = PASSED ;
@@ -1266,6 +1255,8 @@ void F77_d3chke(char *rout) {
12661255
}
12671256
if (cblas_ok == TRUE )
12681257
printf(" %-12s PASSED THE TESTS OF ERROR-EXITS\n", cblas_rout);
1269-
else
1258+
else {
12701259
printf("***** %s FAILED THE TESTS OF ERROR-EXITS *******\n",cblas_rout);
1260+
cblas_test_fail();
1261+
}
12711262
}

0 commit comments

Comments
 (0)