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.
This commit is contained in:
Zhang Xianyi 2014-01-24 02:05:59 +08:00
parent 3e0a7b931c
commit 8c7687b419
3 changed files with 68 additions and 8 deletions

View File

@ -1,7 +1,7 @@
TOPDIR = ../.. TOPDIR = ../..
include ../../Makefile.system include ../../Makefile.system
COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) 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)
COMMONOBJS += slamch.$(SUFFIX) slamc3.$(SUFFIX) dlamch.$(SUFFIX) dlamc3.$(SUFFIX) COMMONOBJS += slamch.$(SUFFIX) slamc3.$(SUFFIX) dlamch.$(SUFFIX) dlamc3.$(SUFFIX)
@ -109,6 +109,9 @@ openblas_get_config.$(SUFFIX) : openblas_get_config.c
openblas_get_parallel.$(SUFFIX) : openblas_get_parallel.c openblas_get_parallel.$(SUFFIX) : openblas_get_parallel.c
$(CC) $(CFLAGS) -c $< -o $(@F) $(CC) $(CFLAGS) -c $< -o $(@F)
openblas_error_handle.$(SUFFIX) : openblas_error_handle.c
$(CC) $(CFLAGS) -c $< -o $(@F)
blasL1thread.$(SUFFIX) : blas_l1_thread.c ../../common.h ../../common_thread.h blasL1thread.$(SUFFIX) : blas_l1_thread.c ../../common.h ../../common_thread.h
$(CC) $(CFLAGS) -c $< -o $(@F) $(CC) $(CFLAGS) -c $< -o $(@F)

View File

@ -38,6 +38,7 @@
#include "common.h" #include "common.h"
#ifdef ARCH_X86 #ifdef ARCH_X86
#define EXTERN extern #define EXTERN extern
#else #else
@ -108,6 +109,11 @@ int support_avx(){
#endif #endif
} }
extern void openblas_warning(int verbose, const char * msg);
#define FALLBACK_VERBOSE 1
#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"
#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"
static int get_vendor(void){ static int get_vendor(void){
int eax, ebx, ecx, edx; int eax, ebx, ecx, edx;
char vendor[13]; char vendor[13];
@ -179,7 +185,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_SANDYBRIDGE; return &gotoblas_SANDYBRIDGE;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
} }
} }
@ -190,7 +196,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_SANDYBRIDGE; return &gotoblas_SANDYBRIDGE;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
} }
} }
@ -199,7 +205,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_HASWELL; return &gotoblas_HASWELL;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
} }
} }
@ -210,7 +216,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_HASWELL; return &gotoblas_HASWELL;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, NEHALEM_FALLBACK);
return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels. return &gotoblas_NEHALEM; //OS doesn't support AVX. Use old kernels.
} }
} }
@ -248,7 +254,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_BULLDOZER; return &gotoblas_BULLDOZER;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
} }
}else if(model == 2){ }else if(model == 2){
@ -256,7 +262,7 @@ static gotoblas_t *get_coretype(void){
if(support_avx()) if(support_avx())
return &gotoblas_PILEDRIVER; return &gotoblas_PILEDRIVER;
else{ else{
fprintf(stderr, "OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Barcelona kernels as a fallback, which may give poorer performance.\n"); openblas_warning(FALLBACK_VERBOSE, BARCELONA_FALLBACK);
return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels. return &gotoblas_BARCELONA; //OS doesn't support AVX. Use old kernels.
} }
} }
@ -351,7 +357,7 @@ void gotoblas_dynamic_init(void) {
if (gotoblas && gotoblas -> init) { if (gotoblas && gotoblas -> init) {
gotoblas -> init(); gotoblas -> init();
} else { } else {
fprintf(stderr, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n"); openblas_warning(0, "OpenBLAS : Architecture Initialization failed. No initialization function found.\n");
exit(1); exit(1);
} }

View File

@ -0,0 +1,51 @@
/***************************************************************************
Copyright (c) 2013, The OpenBLAS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. Neither the name of the OpenBLAS project nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "common.h"
int openblas_verbose() {
int ret=0;
char *p;
p = getenv("OPENBLAS_VERBOSE");
if (p) ret = atoi(p);
if(ret<0) ret=0;
return ret;
}
void openblas_warning(int verbose, const char * msg) {
int current_verbose;
current_verbose=openblas_verbose();
if(current_verbose >= verbose){
fprintf(stderr, "%s", msg);
}
}