introduced OPENBLAS_USES_OPENMP variable to handle OpenBLAS threaded with OpenMP

This commit is contained in:
edoapra 2023-11-15 18:02:09 -08:00
parent c016d842be
commit 7ffbf689ce
No known key found for this signature in database
GPG key ID: 48E12DA1EDE9E1B0
2 changed files with 69 additions and 1 deletions

View file

@ -1385,6 +1385,9 @@ ifeq ($(TARGET),MACX64)
FOPTIONS += -fsanitize=address -fsanitize-recover=address
LDOPTIONS += -fsanitize=address -fsanitize-recover=address
endif
ifdef OPENBLAS_USES_OPENMP
LDOPTIONS += -fopenmp
endif
ifdef USE_FPE
FOPTIONS += -ffpe-trap=invalid,zero,overflow -fbacktrace
@ -2246,6 +2249,9 @@ ifneq ($(TARGET),LINUX)
# DEFINES +=-DUSE_F90_ALLOCATABLE -DUSE_OMP_TEAMS_DISTRIBUTE
endif
endif
ifdef OPENBLAS_USES_OPENMP
LDOPTIONS += -fopenmp
endif
endif
@ -2400,6 +2406,9 @@ ifneq ($(TARGET),LINUX)
FOPTIONS += -fopenmp-targets=spirv64
endif
endif
ifdef OPENBLAS_USES_OPENMP
LDOPTIONS += -fopenmp
endif
ifdef IFX_DEBUG
# debugging remove at some point
FOPTIONS += -std95 -what
@ -2933,6 +2942,9 @@ ifneq ($(TARGET),LINUX)
FOPTIONS += -fopenmp
LDOPTIONS += -fopenmp
endif
ifdef OPENBLAS_USES_OPENMP
LDOPTIONS += -fopenmp
endif
DEFINES += -DARMFLANG
LINK.f = $(FC) $(LDFLAGS)
@ -3890,7 +3902,15 @@ ifdef BUILD_OPENBLAS
DEFINES += -DOPENBLAS
endif
ifeq ($(shell echo $(BLASOPT) |awk '/openblas/ {print "Y"; exit}'),Y)
DEFINES += -DOPENBLAS
ifeq ($(shell bash $(NWCHEM_TOP)/src/config/oblas_ompcheck.sh $(NWCHEM_TOP)),1)
OPENBLAS_USES_OPENMP = 1
LDOPTIONS += -fopenmp
endif
ifdef OPENBLAS_USES_OPENMP
DEFINES += -DBLAS_OPENMP
else
DEFINES += -DOPENBLAS
endif
endif
# NVHPC compilers are distributed wtih OpenBLAS named as libblas/liblapack
ifeq ($(shell echo $(BLASOPT) |awk '/\/nvidia\/hpc_sdk\// {print "Y"; exit}'),Y)

48
src/config/oblas_ompcheck.sh Executable file
View file

@ -0,0 +1,48 @@
#!/bin/bash
# oblas_dir directory where libopenblas is located
# oblas_name "openblas" suffix in lib"openblas".
# e.g. for debian pkg libopenblas64-pthread-dev
# oblas_dir=/usr/lib/x86_64-linux-gnu/openblas64-pthread/
# oblas_name=openblas64
#echo "USE_OPENMP is equal to " $USE_OPENMP
mylog=/tmp/mylog.txt
NWCHEM_TOP=$1
file_check=$NWCHEM_TOP/src/oblas_ompcheck_done.txt
if [ -f $file_check ]; then
echo $file_check present >> $mylog
cat $file_check
exit 0
fi
#extract oblas_dir & oblas_name from BLASOPT
#
oblas_dir=$(echo $BLASOPT | awk 'sub(/.*-L */,""){f=1} f{if ( sub(/ * .*/,"") ) f=0; print}')
oblas_name=$(echo $BLASOPT | awk 'sub(/.* -l */,""){f=1} f{if ( sub(/ * .*/,"") ) f=0; print}')
echo oblas_dir is $oblas_dir oblas_name is $oblas_name >> $mylog
find $oblas_dir -name "lib*openblas*.*"|| true
if [ $(uname -s) == 'Darwin' ]; then
MYLDD='otool -L'
SOSUFFIX=dylib
else
MYLDD=ldd
SOSUFFIX=so
fi
# check first against clang libomp
gotomp=$($MYLDD $oblas_dir/lib$oblas_name.$SOSUFFIX | grep libomp | wc -l )
# next check against gcc libgomp
if [ $gotomp -eq 0 ]
then
gotomp=$($MYLDD $oblas_dir/lib$oblas_name.$SOSUFFIX | grep libgomp | wc -l )
fi
echo gotomp $gotomp >> $mylog
#conda packages might use OpenMP to thread OpenBLAS
if [ $gotomp -ne 0 ]
then
echo openblas built with OpenMP >> $mylog
export OPENBLAS_USES_OPENMP=1
unset USE_OPENMP
else
echo openblas built without OpenMP >> $mylog
fi
echo $gotomp > $NWCHEM_TOP/src/oblas_ompcheck_done.txt
echo $gotomp
exit 0