Commit ea8407de authored by Robert Kimball's avatar Robert Kimball Committed by Sang Ik Lee

Changes toward compiling the CPU backend on Windows (#2264)

* fix windows build

* wip

* mkldnn seems to build

* address various errors building cpu backend with MSVC

* wip

* wip
parent 7000d7d6
......@@ -331,7 +331,11 @@ else()
include(cmake/external_llvm.cmake)
endif()
include(cmake/external_tbb.cmake)
if (WIN32)
include(cmake/external_tbb_prebuilt.cmake)
else()
include(cmake/external_tbb.cmake)
endif()
if (NGRAPH_DISTRIBUTED_ENABLE)
include(cmake/external_mlsl.cmake)
endif()
......
......@@ -24,7 +24,6 @@ include(ExternalProject)
SET(GTEST_GIT_REPO_URL https://github.com/google/googletest.git)
SET(GTEST_GIT_LABEL release-1.8.1)
set(COMPILE_FLAGS -fPIC)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (DEFINED NGRAPH_USE_CXX_ABI)
set(COMPILE_FLAGS "${COMPILE_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${NGRAPH_USE_CXX_ABI}")
......@@ -33,6 +32,10 @@ endif()
set(GTEST_OUTPUT_DIR ${EXTERNAL_PROJECTS_ROOT}/gtest/build/googlemock/gtest)
if (APPLE OR LINUX)
set(COMPILE_FLAGS -fPIC)
endif()
set(GTEST_CMAKE_ARGS
-DCMAKE_CXX_FLAGS=${COMPILE_FLAGS}
)
......
......@@ -98,40 +98,76 @@ else()
endif()
set(MKLDNN_LIBS ${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/libmkldnn${CMAKE_SHARED_LIBRARY_SUFFIX})
ExternalProject_Add(
ext_mkldnn
DEPENDS ext_mkl
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
CONFIGURE_COMMAND
# Patch gets mad if it applied for a second time so:
# --forward tells patch to ignore if it has already been applied
# --reject-file tells patch to not right a reject file
# || exit 0 changes the exit code for the PATCH_COMMAND to zero so it is not an error
# I don't like it, but it works
PATCH_COMMAND patch -p1 --forward --reject-file=- -i ${CMAKE_SOURCE_DIR}/cmake/${MKLDNN_PATCH_FILE} || exit 0
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
CMAKE_ARGS
${NGRAPH_FORWARD_CMAKE_ARGS}
-DWITH_TEST=FALSE
-DWITH_EXAMPLE=FALSE
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
-DMKLDNN_ENABLE_CONCURRENT_EXEC=ON
-DMKLROOT=${MKL_ROOT}
"-DARCH_OPT_FLAGS=-march=${NGRAPH_TARGET_ARCH} -mtune=${NGRAPH_TARGET_ARCH}"
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
EXCLUDE_FROM_ALL TRUE
)
if (WIN32)
ExternalProject_Add(
ext_mkldnn
DEPENDS ext_mkl
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
CONFIGURE_COMMAND
# Patch gets mad if it applied for a second time so:
# --forward tells patch to ignore if it has already been applied
# --reject-file tells patch to not right a reject file
# || exit 0 changes the exit code for the PATCH_COMMAND to zero so it is not an error
# I don't like it, but it works
PATCH_COMMAND patch -p1 --forward --reject-file=- -i ${CMAKE_SOURCE_DIR}/cmake/${MKLDNN_PATCH_FILE} || exit 0
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
CMAKE_ARGS
${NGRAPH_FORWARD_CMAKE_ARGS}
-DWITH_TEST=FALSE
-DWITH_EXAMPLE=FALSE
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
-DMKLDNN_ENABLE_CONCURRENT_EXEC=ON
-DMKLROOT=${MKL_ROOT}
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
EXCLUDE_FROM_ALL TRUE
)
else()
ExternalProject_Add(
ext_mkldnn
DEPENDS ext_mkl
GIT_REPOSITORY ${MKLDNN_GIT_REPO_URL}
GIT_TAG ${MKLDNN_GIT_TAG}
UPDATE_COMMAND ""
CONFIGURE_COMMAND
# Patch gets mad if it applied for a second time so:
# --forward tells patch to ignore if it has already been applied
# --reject-file tells patch to not right a reject file
# || exit 0 changes the exit code for the PATCH_COMMAND to zero so it is not an error
# I don't like it, but it works
PATCH_COMMAND patch -p1 --forward --reject-file=- -i ${CMAKE_SOURCE_DIR}/cmake/${MKLDNN_PATCH_FILE} || exit 0
# Uncomment below with any in-flight MKL-DNN patches
# PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/third-party/patches/mkldnn-cmake-openmp.patch
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
CMAKE_ARGS
${NGRAPH_FORWARD_CMAKE_ARGS}
-DWITH_TEST=FALSE
-DWITH_EXAMPLE=FALSE
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/mkldnn
-DMKLDNN_ENABLE_CONCURRENT_EXEC=ON
-DMKLROOT=${MKL_ROOT}
"-DARCH_OPT_FLAGS=-march=${NGRAPH_TARGET_ARCH} -mtune=${NGRAPH_TARGET_ARCH}"
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/download"
SOURCE_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/src"
BINARY_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn/build"
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/mkldnn"
EXCLUDE_FROM_ALL TRUE
)
endif()
ExternalProject_Add_Step(
ext_mkldnn
......@@ -150,7 +186,7 @@ add_library(libmkldnn INTERFACE)
add_dependencies(libmkldnn ext_mkldnn)
target_include_directories(libmkldnn SYSTEM INTERFACE ${EXTERNAL_PROJECTS_ROOT}/mkldnn/include)
target_link_libraries(libmkldnn INTERFACE
${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/libmkldnn${CMAKE_SHARED_LIBRARY_SUFFIX}
${EXTERNAL_PROJECTS_ROOT}/mkldnn/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mkldnn${CMAKE_SHARED_LIBRARY_SUFFIX}
libmkl
)
......
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
include(ExternalProject)
if (WIN32)
set(ARCHIVE_FILE_BASE tbb2019_20181203oss)
set(TBB_FILE https://github.com/01org/tbb/releases/download/2019_U3/${ARCHIVE_FILE_BASE}_win.zip)
set(TBB_SHA1_HASH 1989458a49e780d76248edac13b963f80c9a460c)
endif()
ExternalProject_Add(
ext_tbb
URL ${TBB_FILE}
URL_HASH SHA1=${TBB_SHA1_HASH}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
DOWNLOAD_NO_PROGRESS TRUE
EXCLUDE_FROM_ALL TRUE
)
ExternalProject_Get_Property(ext_tbb SOURCE_DIR)
set(SOURCE_DIR ${SOURCE_DIR}/${ARCHIVE_FILE_BASE})
set(TBB_LINK_LIBS
${SOURCE_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangTooling${CMAKE_SHARED_LIBRARY_SUFFIX}
${SOURCE_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangTooling${CMAKE_SHARED_LIBRARY_SUFFIX}
${SOURCE_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}clangTooling${CMAKE_SHARED_LIBRARY_SUFFIX}
)
add_library(libtbb INTERFACE)
add_dependencies(libtbb ext_tbb)
target_include_directories(libtbb SYSTEM INTERFACE ${SOURCE_DIR}/include)
target_link_libraries(libtbb INTERFACE ${TBB_LINK_LIBS})
......@@ -133,7 +133,7 @@ if (NGRAPH_HALIDE)
)
endif()
if (NGRAPH_TBB_ENABLE)
if (NGRAPH_TBB_ENABLE AND NOT WIN32)
include(${TBB_ROOT}/cmake/TBBBuild.cmake)
tbb_build(TBB_ROOT ${TBB_ROOT} MAKE_ARGS tbb_build_dir=${CMAKE_CURRENT_BINARY_DIR}/tbb_build
tbb_build_prefix=tbb CONFIG_DIR TBB_DIR)
......@@ -187,7 +187,9 @@ if (NGRAPH_CPU_ENABLE)
if(OPENMP_FOUND)
target_compile_options(cpu_backend PRIVATE "${OpenMP_CXX_FLAGS}")
target_compile_definitions(cpu_backend PRIVATE EIGEN_OPENMP)
if (NOT WIN32)
target_compile_definitions(cpu_backend PRIVATE EIGEN_OPENMP)
endif()
else()
message(WARNING "The build toolset doesn't support OpenMP. This will impact performance and lead to slowdowns.")
endif()
......@@ -214,5 +216,7 @@ if (NGRAPH_CPU_ENABLE)
set_property(TARGET cpu_backend APPEND PROPERTY LINK_FLAGS "-Wl,-Bsymbolic-functions -Wl,--exclude-libs=ALL")
endif()
install(TARGETS cpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
if (NOT WIN32)
install(TARGETS cpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
endif()
endif()
......@@ -176,12 +176,12 @@ namespace ngraph
k,
1.0f,
static_cast<float*>(arg0_tensor),
max(1UL, lda),
max<size_t>(1UL, lda),
static_cast<float*>(arg1_tensor),
max(1UL, ldb),
max<size_t>(1UL, ldb),
beta,
static_cast<float*>(out_tensor),
max(1UL, result_shape[1]));
max<size_t>(1UL, result_shape[1]));
};
functors.emplace_back(functor);
return;
......
......@@ -79,7 +79,7 @@ static shared_ptr<Node>
{
vector<shared_ptr<Node>> new_args;
bool replace_node = false;
uint index = 0;
uint32_t index = 0;
if (required_mds.size() != node->get_input_size())
{
......@@ -179,7 +179,7 @@ static void set_native_layouts(runtime::cpu::CPU_ExternalFunction* external_func
{
std::vector<shared_ptr<Node>> new_args;
bool replace_node = false;
uint index = 0;
uint32_t index = 0;
for (descriptor::Input& input : node->get_inputs())
{
const auto& output = input.get_output();
......
......@@ -32,8 +32,7 @@ namespace ngraph
void softmax(const T* arg, T* out, const Shape& shape, const AxisSet& axes)
{
auto temp_shape = reduce(shape, axes);
auto temp_elements = std::accumulate(
temp_shape.begin(), temp_shape.end(), 1, std::multiplies<size_t>());
auto temp_elements = shape_size(temp_shape);
auto temp_ptr = new T[temp_elements];
max(arg, temp_ptr, shape, temp_shape, axes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment