提交 e6acc109 authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #6495 from abergeron/fix_mkl

Make sure MKL uses GNU OpenMP.
...@@ -12,6 +12,7 @@ environment: ...@@ -12,6 +12,7 @@ environment:
BINSTAR_TOKEN: BINSTAR_TOKEN:
secure: 58KqJcKtfCBVCuIzpnkLm4XZLQqKq95Hs8Ly20HWaMSla67nusrp3y4sy6XzZOBQ secure: 58KqJcKtfCBVCuIzpnkLm4XZLQqKq95Hs8Ly20HWaMSla67nusrp3y4sy6XzZOBQ
CONDA_LOC: "C:\\Miniconda-x64" CONDA_LOC: "C:\\Miniconda-x64"
MKL_THREADING_LAYER: GNU
install: install:
# This breaks conda-build because of git # This breaks conda-build because of git
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
BUILDBOT_DIR=$WORKSPACE/nightly_build BUILDBOT_DIR=$WORKSPACE/nightly_build
THEANO_PARAM="theano --with-timer --timer-top-n 10" THEANO_PARAM="theano --with-timer --timer-top-n 10"
export MKL_THREADING_LAYER=GNU
export THEANO_FLAGS=init_gpu_device=cuda export THEANO_FLAGS=init_gpu_device=cuda
# CUDA # CUDA
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
BUILDBOT_DIR=$WORKSPACE/nightly_build BUILDBOT_DIR=$WORKSPACE/nightly_build
THEANO_PARAM="theano --with-timer --timer-top-n 10" THEANO_PARAM="theano --with-timer --timer-top-n 10"
export MKL_THREADING_LAYER=GNU
# Set test reports using nosetests xunit # Set test reports using nosetests xunit
XUNIT="--with-xunit --xunit-file=" XUNIT="--with-xunit --xunit-file="
SUITE="--xunit-testsuite-name=" SUITE="--xunit-testsuite-name="
...@@ -15,4 +17,4 @@ echo ...@@ -15,4 +17,4 @@ echo
FILE=${BUILDBOT_DIR}/theano_python32bit_tests.xml FILE=${BUILDBOT_DIR}/theano_python32bit_tests.xml
set -x set -x
NAME=python2_32bit NAME=python2_32bit
THEANO_FLAGS=device=cpu,force_device=true,lib.amdlibm=False,compiledir=$HOME/.theano/buildbot_theano_python2_32bit python bin/theano-nose ${THEANO_PARAM} ${XUNIT}${FILE} ${SUITE}${NAME} THEANO_FLAGS=device=cpu,force_device=true,lib.amdlibm=False,compiledir=$HOME/.theano/buildbot_theano_python2_32bit python bin/theano-nose ${THEANO_PARAM} ${XUNIT}${FILE} ${SUITE}${NAME}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
BUILDBOT_DIR=$WORKSPACE/nightly_build BUILDBOT_DIR=$WORKSPACE/nightly_build
THEANO_PARAM="theano --with-timer --timer-top-n 10 -v" THEANO_PARAM="theano --with-timer --timer-top-n 10 -v"
export MKL_THREADING_LAYER=GNU
export THEANO_FLAGS=init_gpu_device=cuda export THEANO_FLAGS=init_gpu_device=cuda
# CUDA # CUDA
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
BUILDBOT_DIR=$WORKSPACE/nightly_build BUILDBOT_DIR=$WORKSPACE/nightly_build
THEANO_PARAM="theano --with-timer --timer-top-n 10" THEANO_PARAM="theano --with-timer --timer-top-n 10"
COMPILEDIR=$HOME/.theano/buildbot_theano_python3 COMPILEDIR=$HOME/.theano/buildbot_theano_python3
export MKL_THREADING_LAYER=GNU
# Set test reports using nosetests xunit # Set test reports using nosetests xunit
XUNIT="--with-xunit --xunit-file=" XUNIT="--with-xunit --xunit-file="
SUITE="--xunit-testsuite-name=" SUITE="--xunit-testsuite-name="
...@@ -69,4 +71,4 @@ THEANO_FLAGS=$THEANO_FLAGS,compiledir=$COMPILEDIR,mode=FAST_COMPILE,warn.ignore_ ...@@ -69,4 +71,4 @@ THEANO_FLAGS=$THEANO_FLAGS,compiledir=$COMPILEDIR,mode=FAST_COMPILE,warn.ignore_
# Fast run and float32 # Fast run and float32
FILE=${BUILDBOT_DIR}/theano_python3_fastrun_f32_tests.xml FILE=${BUILDBOT_DIR}/theano_python3_fastrun_f32_tests.xml
NAME=python3_fastrun_f32 NAME=python3_fastrun_f32
THEANO_FLAGS=$THEANO_FLAGS,compiledir=$COMPILEDIR,mode=FAST_RUN,warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,magma.enabled=true,floatX=float32 python3 bin/theano-nose ${THEANO_PARAM} ${XUNIT}${FILE} ${SUITE}${NAME} THEANO_FLAGS=$THEANO_FLAGS,compiledir=$COMPILEDIR,mode=FAST_RUN,warn.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,magma.enabled=true,floatX=float32 python3 bin/theano-nose ${THEANO_PARAM} ${XUNIT}${FILE} ${SUITE}${NAME}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
BUILDBOT_DIR=$WORKSPACE/nightly_build BUILDBOT_DIR=$WORKSPACE/nightly_build
THEANO_PARAM="theano --with-timer --timer-top-n 10" THEANO_PARAM="theano --with-timer --timer-top-n 10"
export MKL_THREADING_LAYER=GNU
export THEANO_FLAGS=init_gpu_device=cuda export THEANO_FLAGS=init_gpu_device=cuda
# CUDA # CUDA
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
# Print commands as they are executed # Print commands as they are executed
set -x set -x
# To make MKL work
export MKL_THREADING_LAYER=GNU
# Copy cache from master # Copy cache from master
BASECOMPILEDIR=$HOME/.theano/pr_theano BASECOMPILEDIR=$HOME/.theano/pr_theano
rsync -a $HOME/cache/ $HOME/.theano/pr_theano rsync -a $HOME/cache/ $HOME/.theano/pr_theano
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Print commands as they are executed # Print commands as they are executed
set -x set -x
export MKL_THREADING_LAYER=GNU
# Copy cache from master # Copy cache from master
BASECOMPILEDIR=$HOME/.theano/pr_theano BASECOMPILEDIR=$HOME/.theano/pr_theano
rsync -a $HOME/cache/ $HOME/.theano/pr_theano rsync -a $HOME/cache/ $HOME/.theano/pr_theano
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# Print commands as they are executed # Print commands as they are executed
set -x set -x
export MKL_THREADING_LAYER=GNU
# Test flake8 # Test flake8
echo "===== Testing flake8" echo "===== Testing flake8"
bin/theano-nose theano/tests/test_flake8.py --with-xunit --xunit-file=theano_pre_tests.xml || exit 1 bin/theano-nose theano/tests/test_flake8.py --with-xunit --xunit-file=theano_pre_tests.xml || exit 1
......
...@@ -1238,6 +1238,29 @@ AddConfigVar('cmodule.debug', ...@@ -1238,6 +1238,29 @@ AddConfigVar('cmodule.debug',
in_c_key=True) in_c_key=True)
def check_mkl_openmp():
if not theano.config.blas.check_openmp:
return
import os
if ('MKL_THREADING_LAYER' in os.environ and
os.environ['MKL_THREADING_LAYER'] == 'GNU'):
return
try:
import mkl
if '2018' in mkl.get_version_string():
raise RuntimeError('To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement.')
except ImportError:
raise RuntimeError("""
Could not import 'mkl'. Either install mkl-service with conda or set
MKL_THREADING_LAYER=GNU in your environment for MKL 2018.
If you have MKL 2017 install and are not in a conda environment you
can set the Theano flag blas.check_openmp to False. Be warned that if
you set this flag and don't set the appropriate environment or make
sure you have the right version you *will* get wrong results.
""")
def default_blas_ldflags(): def default_blas_ldflags():
global numpy global numpy
warn_record = [] warn_record = []
...@@ -1366,16 +1389,22 @@ def default_blas_ldflags(): ...@@ -1366,16 +1389,22 @@ def default_blas_ldflags():
flags = [] flags = []
if lib_path: if lib_path:
flags = ['-L%s' % lib_path[0]] flags = ['-L%s' % lib_path[0]]
if '2018' in mkl.get_version_string():
thr = 'mkl_gnu_thread'
else:
thr = 'mkl_intel_thread'
flags += ['-l%s' % l for l in ["mkl_core", flags += ['-l%s' % l for l in ["mkl_core",
"mkl_intel_thread", thr,
"mkl_rt"]] "mkl_rt"]]
res = try_blas_flag(flags) res = try_blas_flag(flags)
if res: if res:
check_mkl_openmp()
return res return res
flags.extend(['-Wl,-rpath,' + l for l in flags.extend(['-Wl,-rpath,' + l for l in
blas_info.get('library_dirs', [])]) blas_info.get('library_dirs', [])])
res = try_blas_flag(flags) res = try_blas_flag(flags)
if res: if res:
check_mkl_openmp()
maybe_add_to_os_environ_pathlist('PATH', lib_path[0]) maybe_add_to_os_environ_pathlist('PATH', lib_path[0])
return res return res
...@@ -1396,6 +1425,8 @@ def default_blas_ldflags(): ...@@ -1396,6 +1425,8 @@ def default_blas_ldflags():
ret.extend(['-lm', '-lm']) ret.extend(['-lm', '-lm'])
res = try_blas_flag(ret) res = try_blas_flag(ret)
if res: if res:
if 'mkl' in res:
check_mkl_openmp()
return res return res
# If we are using conda and can't reuse numpy blas, then doing # If we are using conda and can't reuse numpy blas, then doing
...@@ -1411,6 +1442,8 @@ def default_blas_ldflags(): ...@@ -1411,6 +1442,8 @@ def default_blas_ldflags():
blas_info.get('library_dirs', [])]) blas_info.get('library_dirs', [])])
res = try_blas_flag(ret) res = try_blas_flag(ret)
if res: if res:
if 'mkl' in res:
check_mkl_openmp()
return res return res
# Add sys.prefix/lib to the runtime search path. On # Add sys.prefix/lib to the runtime search path. On
...@@ -1421,6 +1454,8 @@ def default_blas_ldflags(): ...@@ -1421,6 +1454,8 @@ def default_blas_ldflags():
ret.append('-Wl,-rpath,' + lib_path) ret.append('-Wl,-rpath,' + lib_path)
res = try_blas_flag(ret) res = try_blas_flag(ret)
if res: if res:
if 'mkl' in res:
check_mkl_openmp()
return res return res
except KeyError: except KeyError:
...@@ -1473,6 +1508,11 @@ AddConfigVar('blas.ldflags', ...@@ -1473,6 +1508,11 @@ AddConfigVar('blas.ldflags',
# Added elsewhere in the c key only when needed. # Added elsewhere in the c key only when needed.
in_c_key=False) in_c_key=False)
AddConfigVar('blas.check_openmp',
"Check for openmp library conflict.\nWARNING: Setting this to False leaves you open to wrong results in blas-related operations.",
BoolParam(True),
in_c_key=False)
AddConfigVar( AddConfigVar(
'metaopt.verbose', 'metaopt.verbose',
"0 for silent, 1 for only warnings, 2 for full output with" "0 for silent, 1 for only warnings, 2 for full output with"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论