Skip to content

Commit 8c7687b

Browse files
committed
Refs #338. Added OPENBLAS_VERBOSE environment variable on runtime
By default, OpenBLAS doesn't output the warning message. You can set OPENBLAS_VERBOSE (e.g. export OPENBLAS_VERBOSE=1) to enable the warning message on runtime.
1 parent 3e0a7b9 commit 8c7687b

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

driver/others/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TOPDIR = ../..
22
include ../../Makefile.system
33

4-
COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX)
4+
COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) openblas_error_handle.$(SUFFIX)
55

66
COMMONOBJS += slamch.$(SUFFIX) slamc3.$(SUFFIX) dlamch.$(SUFFIX) dlamc3.$(SUFFIX)
77

@@ -109,6 +109,9 @@ openblas_get_config.$(SUFFIX) : openblas_get_config.c
109109
openblas_get_parallel.$(SUFFIX) : openblas_get_parallel.c
110110
$(CC) $(CFLAGS) -c $< -o $(@F)
111111

112+
openblas_error_handle.$(SUFFIX) : openblas_error_handle.c
113+
$(CC) $(CFLAGS) -c $< -o $(@F)
114+
112115
blasL1thread.$(SUFFIX) : blas_l1_thread.c ../../common.h ../../common_thread.h
113116
$(CC) $(CFLAGS) -c $< -o $(@F)
114117

driver/others/dynamic.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "common.h"
4040

41+
4142
#ifdef ARCH_X86
4243
#define EXTERN extern
4344
#else
@@ -108,6 +109,11 @@ int support_avx(){
108109
#endif
109110
}
110111

112+
extern void openblas_warning(int verbose, const char * msg);
113+
#define FALLBACK_VERBOSE 1
114+
#define NEHALEM_FALLBACK "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"
115+
#define BARCELONA_FALLBACK "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n"
116+
111117
static int get_vendor(void){
112118
int eax, ebx, ecx, edx;
113119
char vendor[13];
@@ -179,7 +185,7 @@ static gotoblas_t *get_coretype(void){
179185
if(support_avx())
180186
return &gotoblas_SANDYBRIDGE;
181187
else{
182-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n");
188+
openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
183189
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
184190
}
185191
}
@@ -190,7 +196,7 @@ static gotoblas_t *get_coretype(void){
190196
if(support_avx())
191197
return &gotoblas_SANDYBRIDGE;
192198
else{
193-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n");
199+
openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
194200
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
195201
}
196202
}
@@ -199,7 +205,7 @@ static gotoblas_t *get_coretype(void){
199205
if(support_avx())
200206
return &gotoblas_HASWELL;
201207
else{
202-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n");
208+
openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
203209
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
204210
}
205211
}
@@ -210,7 +216,7 @@ static gotoblas_t *get_coretype(void){
210216
if(support_avx())
211217
return &gotoblas_HASWELL;
212218
else{
213-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n");
219+
openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
214220
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
215221
}
216222
}
@@ -248,15 +254,15 @@ static gotoblas_t *get_coretype(void){
248254
if(support_avx())
249255
return &gotoblas_BULLDOZER;
250256
else{
251-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n");
257+
openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
252258
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
253259
}
254260
}else if(model == 2){
255261
//AMD Bulldozer Opteron 6300 / Opteron 4300 / Opteron 3300
256262
if(support_avx())
257263
return &gotoblas_PILEDRIVER;
258264
else{
259-
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n");
265+
openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
260266
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
261267
}
262268
}
@@ -351,7 +357,7 @@ void gotoblas_dynamic_init(void) {
351357
if (gotoblas && gotoblas -> init) {
352358
gotoblas -> init();
353359
} else {
354-
fprintf(stderr, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
360+
openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
355361
exit(1);
356362
}
357363

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
Copyright (c) 2013, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
17+
3. Neither the name of the OpenBLAS project nor the names of
18+
its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
*****************************************************************************/
33+
34+
#include "common.h"
35+
36+
int openblas_verbose() {
37+
int ret=0;
38+
char *p;
39+
p = getenv("OPENBLAS_VERBOSE");
40+
if (p) ret = atoi(p);
41+
if(ret<0) ret=0;
42+
return ret;
43+
}
44+
45+
void openblas_warning(int verbose, const char * msg) {
46+
int current_verbose;
47+
current_verbose=openblas_verbose();
48+
if(current_verbose >= verbose){
49+
fprintf(stderr, "%s", msg);
50+
}
51+
}

0 commit comments

Comments
 (0)