mbrookhart closed pull request #12483: [DO NOT MERGE] staging area for upstream 
PR
URL: https://github.com/apache/incubator-mxnet/pull/12483
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitmodules b/.gitmodules
index 836d824a6f5..c7c9cb0de5c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -29,3 +29,9 @@
 [submodule "3rdparty/onnx-tensorrt"]
        path = 3rdparty/onnx-tensorrt
        url = https://github.com/onnx/onnx-tensorrt.git
+[submodule "ngraph-mxnet-bridge"]
+       path = ngraph-mxnet-bridge
+       url = https://github.com/NervanaSystems/ngraph-mxnet-bridge
+[submodule "3rdparty/ngraph-mxnet-bridge"]
+       path = 3rdparty/ngraph-mxnet-bridge
+       url = https://github.com/NervanaSystems/ngraph-mxnet-bridge
diff --git a/3rdparty/ngraph-mxnet-bridge b/3rdparty/ngraph-mxnet-bridge
new file mode 160000
index 00000000000..321f815d694
--- /dev/null
+++ b/3rdparty/ngraph-mxnet-bridge
@@ -0,0 +1 @@
+Subproject commit 321f815d6945512ea83e36e155c165dc2f2f7c56
diff --git a/CMakeLists.txt b/CMakeLists.txt
index adff5333665..e8af87d1c0f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,9 +18,10 @@ mxnet_option(USE_CUDNN            "Build with cudnn support" 
 ON) # one could se
 mxnet_option(USE_SSE              "Build with x86 SSE instruction support" ON 
IF NOT ARM)
 mxnet_option(USE_F16C             "Build with x86 F16C instruction support" 
ON) # autodetects support if ON
 mxnet_option(USE_LAPACK           "Build with lapack support" ON)
+mxnet_option(USE_NGRAPH           "Build with nGraph support" ON)
 mxnet_option(USE_MKL_IF_AVAILABLE "Use MKL if found" ON)
 mxnet_option(USE_MKLML_MKL        "Use MKLDNN variant of MKL (if MKL found)" 
ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE))
-mxnet_option(USE_MKLDNN           "Use MKLDNN variant of MKL (if MKL found)" 
ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE))
+mxnet_option(USE_MKLDNN           "Use MKLDNN variant of MKL (if MKL found)" 
ON IF USE_MKL_IF_AVAILABLE AND (NOT APPLE) AND (NOT USE_NGRAPH))
 mxnet_option(USE_OPERATOR_TUNING  "Enable auto-tuning of operators" ON IF NOT 
MSVC)
 mxnet_option(USE_GPERFTOOLS       "Build with GPerfTools support (if found)" 
ON)
 mxnet_option(USE_JEMALLOC         "Build with Jemalloc support"   ON)
@@ -166,6 +167,35 @@ if(NOT mxnet_LINKER_LIBS)
   set(mxnet_LINKER_LIBS "")
 endif(NOT mxnet_LINKER_LIBS)
 
+if(USE_NGRAPH AND NOT MSVC)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment")
+  set(NGRAPH_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/3rdparty/ngraph-mxnet-bridge)
+
+  if(NOT MSVC)
+    set(ARCH_OPT_FLAGS "-mtune=generic")
+  endif()
+  add_subdirectory(3rdparty/ngraph-mxnet-bridge)
+
+  include_directories(3rdparty/ngraph-mxnet-bridge/src)
+  include_directories(${CMAKE_BINARY_DIR}/3rdparty/ngraph-mxnet-bridge/include)
+  
+  add_definitions(-DMXNET_USE_NGRAPH=1)
+  
+  list(APPEND mxnet_LINKER_LIBS ${NGRAPH_INSTALL_PREFIX}/lib/libngraph.so)
+  list(APPEND mxnet_LINKER_LIBS ${NGRAPH_INSTALL_PREFIX}/lib/libmkldnn.so)
+  list(APPEND mxnet_LINKER_LIBS ${NGRAPH_INSTALL_PREFIX}/lib/libiomp5.so)
+  list(APPEND mxnet_LINKER_LIBS ${NGRAPH_INSTALL_PREFIX}/lib/libmklml_intel.so)
+  list(APPEND mxnet_LINKER_LIBS ${NGRAPH_INSTALL_PREFIX}/lib/libcpu_backend.so)
+  
+  if(USE_NGRAPH_DISTRIBUTED)
+    find_package(MPI REQUIRED)
+    include_directories(SYSTEM ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
+    link_directories(${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
+    list(APPEND mxnet_LINKER_LIBS ${MPI_CXX_LIBRARIES})
+    add_definitions(-DMXNET_USE_NGRAPH_DISTRIBUTED=1)
+  endif(USE_NGRAPH_DISTRIBUTED)
+endif()
+
 if(USE_GPROF)
   message(STATUS "Using GPROF")
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -g -pg")
@@ -404,13 +434,13 @@ endif()
 
 # ---[ LAPack
 if(USE_LAPACK)
-  message("USE_LAPACK is ON")
   add_definitions(-DMXNET_USE_LAPACK=1)
   if (NOT MSVC)
     list(APPEND mxnet_LINKER_LIBS lapack)
   endif()
 endif()
 
+message("USE LAPACK ${USE_LAPACK}")
 
 # ---[ jemalloc
 if(USE_JEMALLOC)
@@ -635,8 +665,12 @@ if(UNIX)
   set(DUMMY_SOURCE ${CMAKE_BINARY_DIR}/dummy.c)
   file(WRITE ${DUMMY_SOURCE} "")
   list(APPEND MXNET_INSTALL_TARGETS mxnet_static)
-  add_library(mxnet_static STATIC ${SOURCE})
   add_library(mxnet SHARED ${DUMMY_SOURCE})
+  if(USE_NGRAPH AND NOT MSVC)
+    add_library(mxnet_static STATIC ${SOURCE} 
$<TARGET_OBJECTS:ngraph-mxnet-bridge>)
+  else()
+    add_library(mxnet_static STATIC ${SOURCE})
+  endif()
   target_link_libraries(mxnet PRIVATE ${BEGIN_WHOLE_ARCHIVE} 
$<TARGET_FILE:mxnet_static> ${END_WHOLE_ARCHIVE})
   target_link_libraries(mxnet PRIVATE mxnet_static)
   set_target_properties(mxnet_static PROPERTIES OUTPUT_NAME mxnet)
@@ -644,6 +678,12 @@ else()
   add_library(mxnet SHARED ${SOURCE})
 endif()
 
+if(USE_NGRAPH AND NOT MSVC)
+  if(UNIX)
+    add_dependencies(mxnet_static ngraph-mxnet-bridge)
+  endif()
+endif()
+
 if(USE_CUDA)
   if(FIRST_CUDA AND MSVC)
     target_compile_options(mxnet PUBLIC "$<$<CONFIG:DEBUG>:-Xcompiler=-MTd 
-Gy>")
diff --git a/Makefile b/Makefile
index 7aa7867f7c1..62a63118c38 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,15 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# To assist with Makefile debugging.  Print any Make variable's value using
+# make ... print-VARNAME
+#
+# For example: "make print-NNVM_PATH"
+print-%:
+       @echo '$*=$($*)'
+
+.DEFAULT_GOAL := all
+
 ROOTDIR = $(CURDIR)
 TPARTYDIR = $(ROOTDIR)/3rdparty
 
@@ -71,11 +80,14 @@ ifeq ($(USE_MKLDNN), 1)
        export USE_MKLML = 1
 endif
 
+
 include $(TPARTYDIR)/mshadow/make/mshadow.mk
 include $(DMLC_CORE)/make/dmlc.mk
 
+include 3rdparty/ngraph-mxnet-bridge/ngraph.mk
+
 # all tge possible warning tread
-WARNFLAGS= -Wall -Wsign-compare
+WARNFLAGS= -Wall -Wsign-compare -Wno-comment
 CFLAGS = -DMSHADOW_FORCE_STREAM $(WARNFLAGS)
 
 ifeq ($(DEV), 1)
@@ -90,14 +102,19 @@ else
        CFLAGS += -O3 -DNDEBUG=1
 endif
 CFLAGS += -I$(TPARTYDIR)/mshadow/ -I$(TPARTYDIR)/dmlc-core/include -fPIC 
-I$(NNVM_PATH)/include -I$(DLPACK_PATH)/include -I$(TPARTYDIR)/tvm/include 
-Iinclude $(MSHADOW_CFLAGS)
-LDFLAGS = -pthread $(MSHADOW_LDFLAGS) $(DMLC_LDFLAGS)
 
+LDFLAGS =
+
+ifeq ($(USE_NGRAPH),1)
+    CFLAGS += $(NGRAPH_CFLAGS)
+endif
+
+LDFLAGS += -pthread $(MSHADOW_LDFLAGS) $(DMLC_LDFLAGS)
 
 ifeq ($(USE_TENSORRT), 1)
        CFLAGS +=  -I$(ROOTDIR) -I$(TPARTYDIR) 
-DONNX_NAMESPACE=$(ONNX_NAMESPACE) -DMXNET_USE_TENSORRT=1
        LDFLAGS += -lprotobuf -pthread -lonnx -lonnx_proto -lnvonnxparser 
-lnvonnxparser_runtime -lnvinfer -lnvinfer_plugin
 endif
-# -L/usr/local/lib
 
 ifeq ($(DEBUG), 1)
        NVCCFLAGS += -std=c++11 -Xcompiler -D_FORCE_INLINES -g -G -O0 -ccbin 
$(CXX) $(MSHADOW_NVCCFLAGS)
@@ -290,6 +307,11 @@ ifeq ($(USE_THREADED_ENGINE), 1)
        CFLAGS += -DMXNET_USE_THREADED_ENGINE
 endif
 
+ifeq ($(USE_ASAN), 1)
+  CFLAGS += -fsanitize=address -fno-omit-frame-pointer
+  LDFLAGS += -lasan
+endif
+
 ifneq ($(ADD_CFLAGS), NONE)
        CFLAGS += $(ADD_CFLAGS)
 endif
@@ -382,6 +404,10 @@ else
        EXTRA_CUOBJ =
 endif
 
+ifeq ($(USE_NGRAPH), 1)
+       EXTRA_OBJ += $(NGRAPH_BRIDGE_OBJ)
+endif
+
 # plugin
 PLUGIN_OBJ =
 PLUGIN_CUOBJ =
@@ -447,23 +473,23 @@ endif
 # For quick compile test, used smaller subset
 ALLX_DEP= $(ALL_DEP)
 
-build/src/%.o: src/%.cc | mkldnn
+build/src/%.o: src/%.cc | mkldnn ngraph
        @mkdir -p $(@D)
        $(CXX) -std=c++11 -c $(CFLAGS) -MMD -c $< -o $@
 
-build/src/%_gpu.o: src/%.cu | mkldnn
+build/src/%_gpu.o: src/%.cu | mkldnn ngraph
        @mkdir -p $(@D)
        $(NVCC) $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" -M -MT 
build/src/$*_gpu.o $< >build/src/$*_gpu.d
        $(NVCC) -c -o $@ $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" $<
 
 # A nvcc bug cause it to generate "generic/xxx.h" dependencies from torch 
headers.
 # Use CXX to generate dependency instead.
-build/plugin/%_gpu.o: plugin/%.cu
+build/plugin/%_gpu.o: plugin/%.cu | ngraph
        @mkdir -p $(@D)
        $(CXX) -std=c++11 $(CFLAGS) -MM -MT build/plugin/$*_gpu.o $< 
>build/plugin/$*_gpu.d
        $(NVCC) -c -o $@ $(NVCCFLAGS) $(CUDA_ARCH) -Xcompiler "$(CFLAGS)" $<
 
-build/plugin/%.o: plugin/%.cc
+build/plugin/%.o: plugin/%.cc | ngraph
        @mkdir -p $(@D)
        $(CXX) -std=c++11 -c $(CFLAGS) -MMD -c $< -o $@
 
@@ -484,7 +510,9 @@ lib/libmxnet.a: $(ALLX_DEP)
 
 lib/libmxnet.so: $(ALLX_DEP)
        @mkdir -p $(@D)
-       $(CXX) $(CFLAGS) -shared -o $@ $(filter-out %libnnvm.a, $(filter %.o 
%.a, $^)) $(LDFLAGS) \
+       $(CXX) $(CFLAGS) -shared -o $@ $(filter-out %libnnvm.a, $(filter %.o 
%.a, $^)) \
+         $(NGRAPH_LDFLAGS_FOR_SHARED_LIBS) \
+         $(LDFLAGS) \
        -Wl,${WHOLE_ARCH} $(filter %libnnvm.a, $^) -Wl,${NO_WHOLE_ARCH}
 ifeq ($(USE_MKLDNN), 1)
 ifeq ($(UNAME_S), Darwin)
@@ -511,9 +539,13 @@ $(NNVM_PATH)/lib/libnnvm.a: $(NNVM_INC) $(NNVM_SRC)
 
 bin/im2rec: tools/im2rec.cc $(ALLX_DEP)
 
+MXNET_RELATIVE_PATH_TO_RUNTIME_LIB_DIR := "../lib"
+
 $(BIN) :
        @mkdir -p $(@D)
-       $(CXX) $(CFLAGS) -std=c++11  -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) 
$(LDFLAGS)
+       $(CXX) $(CFLAGS) -std=c++11  -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) 
\
+         $(LDFLAGS) \
+         $(NGRAPH_LDFLAGS_FOR_PROGS_IN_BIN)
 
 # CPP Package
 ifeq ($(USE_CPP_PACKAGE), 1)
@@ -536,6 +568,10 @@ cpplint:
 pylint:
        pylint --rcfile=$(ROOTDIR)/ci/other/pylintrc 
--ignore-patterns=".*\.so$$,.*\.dll$$,.*\.dylib$$" python/mxnet 
tools/caffe_converter/*.py
 
+python_clean:
+       $(RM) -r python/build
+       $(RM) -r python/dist
+
 doc: docs
 
 docs:
@@ -660,7 +696,7 @@ clean: cyclean $(EXTRA_PACKAGES_CLEAN)
        $(RM) -r  $(patsubst %, %/*.d, $(EXTRA_OPERATORS)) $(patsubst %, 
%/*/*.d, $(EXTRA_OPERATORS))
        $(RM) -r  $(patsubst %, %/*.o, $(EXTRA_OPERATORS)) $(patsubst %, 
%/*/*.o, $(EXTRA_OPERATORS))
 else
-clean: mkldnn_clean cyclean testclean $(EXTRA_PACKAGES_CLEAN)
+clean: ngraph_clean mkldnn_clean cyclean testclean $(EXTRA_PACKAGES_CLEAN)
        $(RM) -r build lib bin *~ */*~ */*/*~ */*/*/*~ R-package/NAMESPACE 
R-package/man R-package/R/mxnet_generated.R \
                R-package/inst R-package/src/image_recordio.h R-package/src/*.o 
R-package/src/*.so mxnet_*.tar.gz
        cd $(DMLC_CORE); $(MAKE) clean; cd -
diff --git a/make/config.mk b/make/config.mk
index b65f77c605f..47196a5e123 100644
--- a/make/config.mk
+++ b/make/config.mk
@@ -92,6 +92,7 @@ USE_OPENCV = 1
 
 #whether use libjpeg-turbo for image decode without OpenCV wrapper
 USE_LIBJPEG_TURBO = 0
+
 #add the path to libjpeg-turbo library
 USE_LIBJPEG_TURBO_PATH = NONE
 
@@ -101,6 +102,36 @@ USE_OPENMP = 1
 # whether use MKL-DNN library
 USE_MKLDNN = 0
 
+# The following variables influence if/how MXnet is built with nGraph support:
+#
+# USE_NGRAPH - If 1, then MXnet will built with nGraph support.
+#
+# USE_NGRAPH_IE - If 1, then if/when nGraph is built it will contain support 
for inference-engine
+#   processing.
+#
+# USE_NGRAPH_DISTRIBUTED - If 1, then if/when nGraph is built it will contain 
support for
+#   distributed processing.
+#
+# NGRAPH_EXTRA_CMAKE_FLAGS - Additional command-line arguments passed to the 
'cmake' invocation
+#   used to configure the nGraph build.
+#
+# NGRAPH_EXTRA_MAKE_FLAGS - Additional command-line arugments passed to the 
'make' invocation
+#   used to build nGraph.
+#
+# ADD_NGRAPH_LIBDIR_TO_MXNET_RPATH - If USE_NGRAPH=1 and 
ADD_NGRAPH_LIBDIR_TO_MXNET_RPATH=1, then
+#   'libmxnet.so' will be linked with linker option `-rpath=D`, where "D" is 
whatever directory
+#   contains the copy of `libngraph.so` used by MXnet's build system.
+
+USE_NGRAPH = 0
+USE_NGRAPH_IE = 0
+USE_NGRAPH_DISTRIBUTED = 0
+
+# use prebuilt mkldnn if set
+ifneq ($(MKLDNNROOT),)
+  override NGRAPH_EXTRA_CMAKE_FLAGS += 
-DMKLDNN_INCLUDE_DIR=$(MKLDNNROOT)/include
+  override NGRAPH_EXTRA_CMAKE_FLAGS += -DMKLDNN_LIB_DIR=$(MKLDNNROOT)/lib
+endif
+
 # whether use NNPACK library
 USE_NNPACK = 0
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to