Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Feature/mkldnn static #13628

Merged
merged 4 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ if(USE_MKLDNN)
include(cmake/DownloadMKLML.cmake)
# CPU architecture (e.g., C5) can't run on another architecture (e.g., g3).
if(NOT MSVC)
set(MKLDNN_LIBRARY_TYPE "STATIC" CACHE INTERNAL "" FORCE)
set(ARCH_OPT_FLAGS "-mtune=generic")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHsc")
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ ifeq ($(USE_MKLDNN), 1)
LDFLAGS += -L$(MKLROOT)/lib
endif
CFLAGS += -I$(MKLDNNROOT)/include
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'
# MKLDNN but to needs to be dynamically linked for windows as not all VS compilers support static linking
ifneq ($(UNAME_S), Windows)
LIB_DEP += $(MKLDNNROOT)/lib/libmkldnn.a
else
LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS compiler doesn't know those flags. Do we support VS build with Makefile?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, windows uses cmake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoabreu Thanks for explanation. This is as I expected. So we don't need to consider Windows build in Makefile.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't remove LDFLAGS += -L$(MKLDNNROOT)/lib -lmkldnn -Wl,-rpath,'$${ORIGIN}'? It doesn't work on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line was there before. I am not trying to change builds on windows.

Copy link
Contributor

@ZhennanQin ZhennanQin Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is used for Linux MKLDNN dynamic build. Then why not remove it? As @marcoabreu said, Windows build doesn't use Makefile.

endif
endif

# setup opencv
Expand Down
3 changes: 0 additions & 3 deletions ci/docker/runtime_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,6 @@ build_ubuntu_gpu_cmake_mkldnn() {
/work/mxnet

ninja -v
# libmkldnn.so.0 is a link file. We need an actual binary file named libmkldnn.so.0.
cp 3rdparty/mkldnn/src/libmkldnn.so.0 3rdparty/mkldnn/src/libmkldnn.so.0.tmp
mv 3rdparty/mkldnn/src/libmkldnn.so.0.tmp 3rdparty/mkldnn/src/libmkldnn.so.0
}

build_ubuntu_gpu_cmake() {
Expand Down
8 changes: 4 additions & 4 deletions ci/jenkins/Jenkins_steps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
utils = load('ci/Jenkinsfile_utils.groovy')

// mxnet libraries
mx_lib = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmklml_intel.so, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'

// Python wheels
mx_pip = 'build/*.whl'

// for scala build, need to pass extra libs when run with dist_kvstore
mx_dist_lib = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a'
mx_dist_lib = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a, lib/libmkldnn.a'
// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so'
// mxnet cmake libraries, in cmake builds we do not produce a libnvvm static library by default.
mx_cmake_lib_debug = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests'
mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so, build/3rdparty/mkldnn/src/libmkldnn.so.0'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmkldnn.so.0, lib/libmklml_intel.so, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_cmake_mkldnn_lib = 'build/libmxnet.so, build/libmxnet.a, build/3rdparty/dmlc-core/libdmlc.a, build/tests/mxnet_unit_tests, build/3rdparty/openmp/runtime/src/libomp.so'
mx_mkldnn_lib = 'lib/libmxnet.so, lib/libmxnet.a, lib/libiomp5.so, lib/libmklml_intel.so, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a'
mx_tensorrt_lib = 'lib/libmxnet.so, lib/libnvonnxparser_runtime.so.0, lib/libnvonnxparser.so.0, lib/libonnx_proto.so, lib/libonnx.so'
mx_lib_cpp_examples = 'lib/libmxnet.so, lib/libmxnet.a, 3rdparty/dmlc-core/libdmlc.a, 3rdparty/tvm/nnvm/lib/libnnvm.a, 3rdparty/ps-lite/build/libps.a, deps/lib/libprotobuf-lite.a, deps/lib/libzmq.a, build/cpp-package/example/*'
mx_lib_cpp_examples_cpu = 'build/libmxnet.so, build/cpp-package/example/*'
Expand Down
12 changes: 9 additions & 3 deletions mkldnn.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ ifeq ($(USE_MKLDNN), 1)
MKLDNN_SUBMODDIR = $(ROOTDIR)/3rdparty/mkldnn
MKLDNN_BUILDDIR = $(MKLDNN_SUBMODDIR)/build
MXNET_LIBDIR = $(ROOTDIR)/lib
MKLDNN_LIBRARY_TYPE=STATIC
ifeq ($(UNAME_S), Darwin)
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.dylib
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.0.dylib
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.a
else ifeq ($(UNAME_S), Windows)
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.so
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml_intel.so
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.so
MKLDNN_LIBRARY_TYPE=SHARED
else
OMP_LIBFILE = $(MKLDNNROOT)/lib/libiomp5.so
MKLML_LIBFILE = $(MKLDNNROOT)/lib/libmklml_intel.so
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.so.0
MKLDNN_LIBFILE = $(MKLDNNROOT)/lib/libmkldnn.a
endif
endif

Expand All @@ -37,7 +43,7 @@ mkldnn_build: $(MKLDNN_LIBFILE)
$(MKLDNN_LIBFILE):
mkdir -p $(MKLDNNROOT)
cd $(MKLDNN_SUBMODDIR) && rm -rf external && cd scripts && ./prepare_mkl.sh && cd .. && cp -a external/*/* $(MKLDNNROOT)/.
cmake $(MKLDNN_SUBMODDIR) -DCMAKE_INSTALL_PREFIX=$(MKLDNNROOT) -B$(MKLDNN_BUILDDIR) -DARCH_OPT_FLAGS="-mtune=generic" -DWITH_TEST=OFF -DWITH_EXAMPLE=OFF
cmake $(MKLDNN_SUBMODDIR) -DCMAKE_INSTALL_PREFIX=$(MKLDNNROOT) -B$(MKLDNN_BUILDDIR) -DARCH_OPT_FLAGS="-mtune=generic" -DWITH_TEST=OFF -DWITH_EXAMPLE=OFF -DMKLDNN_LIBRARY_TYPE=$(MKLDNN_LIBRARY_TYPE)
$(MAKE) -C $(MKLDNN_BUILDDIR) VERBOSE=1
$(MAKE) -C $(MKLDNN_BUILDDIR) install
mkdir -p $(MXNET_LIBDIR)
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp/unittest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ gtest-all.o : $(GTEST_SRCS_)
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^

build/tests/cpp/%.o : tests/cpp/%.cc | mkldnn
build/tests/cpp/%.o : tests/cpp/%.cc
@mkdir -p $(@D)
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/$* $< > build/tests/cpp/$*.d
$(CXX) -c -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o build/tests/cpp/$*.o $(filter %.cc %.a, $^)

build/tests/cpp/operator/%.o : tests/cpp/operator/%.cc | mkldnn
build/tests/cpp/operator/%.o : tests/cpp/operator/%.cc
@mkdir -p $(@D)
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/operator/$* $< > build/tests/cpp/operator/$*.d
$(CXX) -c -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o build/tests/cpp/operator/$*.o $(filter %.cc %.a, $^)

build/tests/cpp/storage/%.o : tests/cpp/storage/%.cc | mkldnn
build/tests/cpp/storage/%.o : tests/cpp/storage/%.cc
@mkdir -p $(@D)
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/storage/$* $< > build/tests/cpp/storage/$*.d
$(CXX) -c -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o build/tests/cpp/storage/$*.o $(filter %.cc %.a, $^)

build/tests/cpp/engine/%.o : tests/cpp/engine/%.cc | mkldnn
build/tests/cpp/engine/%.o : tests/cpp/engine/%.cc
@mkdir -p $(@D)
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/engine/$* $< > build/tests/cpp/engine/$*.d
$(CXX) -c -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o build/tests/cpp/engine/$*.o $(filter %.cc %.a, $^)
Expand Down
6 changes: 1 addition & 5 deletions tests/python/mkl/test_mkldnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from mxnet import gluon
from mxnet.gluon import nn
from mxnet.test_utils import *
import test_mkldnn_install as install
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
sys.path.append(os.path.join(curr_path, '../unittest/'))
from common import with_seed
Expand Down Expand Up @@ -441,7 +440,4 @@ def backward(self, req, out_grad, in_data, out_data, in_grad, aux):
custom = mx.symbol.Custom(name='custom', data=conv, op_type='custom')
exec1 = custom.bind(mx.cpu(), args={'data': mx.nd.ones([10,3,96,96]), 'conv_weight': mx.nd.ones([8,3,5,5])})
exec1.forward()[0].wait_to_read()


if __name__ == '__main__':
install.test_mkldnn_install()

56 changes: 0 additions & 56 deletions tests/python/mkl/test_mkldnn_install.py

This file was deleted.