Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into hari/optional_fix_1
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharans29 committed Jun 24, 2022
2 parents 465d0b5 + f4ba199 commit 68cecd8
Show file tree
Hide file tree
Showing 410 changed files with 18,705 additions and 8,036 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
[submodule "cmake/external/onnx-tensorrt"]
path = cmake/external/onnx-tensorrt
url = https://github.com/onnx/onnx-tensorrt.git
branch = 8.2-GA
branch = 8.4-GA
[submodule "cmake/external/pthreadpool"]
path = cmake/external/pthreadpool
url = https://github.com/Maratyszcza/pthreadpool.git
Expand All @@ -77,4 +77,4 @@
url = https://github.com/Maratyszcza/FP16.git
[submodule "cmake/external/XNNPACK"]
path = cmake/external/XNNPACK
url = https://github.com/google/XNNPACK.git
url = https://github.com/google/XNNPACK.git
2 changes: 1 addition & 1 deletion .pipelines/nuget_config/x64/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="python" version="3.7.9" targetFramework="native" />
<package id="Microsoft.AI.DirectML" version="1.8.2" targetFramework="native" />
<package id="Microsoft.AI.DirectML.Preview" version="1.9.0-devb9b146539f535988728c8eb4791840db54add4a7" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.201201.7" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion .pipelines/nuget_config/x86/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="pythonx86" version="3.7.9" targetFramework="native" />
<package id="Microsoft.AI.DirectML" version="1.8.2" targetFramework="native" />
<package id="Microsoft.AI.DirectML.Preview" version="1.9.0-devb9b146539f535988728c8eb4791840db54add4a7" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.201201.7" targetFramework="native" />
</packages>
14 changes: 7 additions & 7 deletions cgmanifests/generated/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"type": "git",
"git": {
"commitHash": "db78ac1d7716f56fc9f1b030b715f872f93964e4",
"repositoryUrl": "https://github.com/nlohmann/json.git"
"repositoryUrl": "https://github.com/nlohmann/json"
},
"comments": "git submodule at cmake/external/json"
}
Expand Down Expand Up @@ -265,7 +265,7 @@
"type": "git",
"git": {
"commitHash": "436617053d0f39a1019a371c3a9aa599b3cb2cea",
"repositoryUrl": "https://github.com/google/nsync.git"
"repositoryUrl": "https://github.com/google/nsync"
},
"comments": "git submodule at cmake/external/nsync"
}
Expand All @@ -274,8 +274,8 @@
"component": {
"type": "git",
"git": {
"commitHash": "850a81b0b77786bf99ea90580242b084f86a6235",
"repositoryUrl": "https://github.com/onnx/onnx.git"
"commitHash": "f7ee1ac60d06abe8e26c9b6bbe1e3db5286b614b",
"repositoryUrl": "https://github.com/onnx/onnx"
},
"comments": "git submodule at cmake/external/onnx"
}
Expand All @@ -284,7 +284,7 @@
"component": {
"type": "git",
"git": {
"commitHash": "e776aa0275e293707b6a0901e0e8d8a8a3679508",
"commitHash": "0d98dba29d66e93259db7daa53a9327df767a415",
"repositoryUrl": "https://github.com/google/benchmark.git"
},
"comments": "git submodule at cmake/external/onnx/third_party/benchmark"
Expand All @@ -294,7 +294,7 @@
"component": {
"type": "git",
"git": {
"commitHash": "59a2ac2745d8a57ac94c6accced73620d59fb844",
"commitHash": "ffa346860b306c9bbfb341aed9c14c067751feb8",
"repositoryUrl": "https://github.com/pybind/pybind11.git"
},
"comments": "git submodule at cmake/external/onnx/third_party/pybind11"
Expand Down Expand Up @@ -425,7 +425,7 @@
"type": "git",
"git": {
"commitHash": "e8c599bca6c56c44b6730ad93f6abbc9ecd60fc1",
"repositoryUrl": "https://github.com/microsoft/wil.git"
"repositoryUrl": "https://github.com/microsoft/wil"
},
"comments": "git submodule at cmake/external/wil"
}
Expand Down
71 changes: 9 additions & 62 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ option(onnxruntime_ENABLE_MICROSOFT_INTERNAL "Use this option to enable/disable
option(onnxruntime_USE_NUPHAR "Build with Nuphar" OFF)
option(onnxruntime_USE_VITISAI "Build with Vitis-AI" OFF)
option(onnxruntime_USE_TENSORRT "Build with TensorRT support" OFF)
option(onnxruntime_TENSORRT_PLACEHOLDER_BUILDER "Instantiate Placeholder TensorRT Builder" OFF)
option(onnxruntime_ENABLE_LTO "Enable link time optimization" OFF)
option(onnxruntime_CROSS_COMPILING "Cross compiling onnx runtime" OFF)
option(onnxruntime_GCOV_COVERAGE "Compile with options necessary to run code coverage" OFF)
Expand Down Expand Up @@ -434,6 +435,7 @@ if (onnxruntime_DISABLE_EXCEPTIONS)
add_compile_definitions("ORT_NO_EXCEPTIONS")
add_compile_definitions("MLAS_NO_EXCEPTION")
add_compile_definitions("ONNX_NO_EXCEPTIONS")
add_compile_definitions("JSON_NOEXCEPTION") # https://json.nlohmann.me/api/macros/json_noexception/

if (MSVC)
string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -1523,62 +1525,7 @@ if (onnxruntime_USE_XNNPACK)
"but onnxruntime_DISABLE_CONTRIB_OPS is ON")
endif()

set(XNNPACK_DIR external/XNNPACK)
set(XNNPACK_INCLUDE_DIR ${XNNPACK_DIR}/include)
set(XNNPACK_USE_SYSTEM_LIBS ON CACHE INTERNAL "")
set(XNNPACK_BUILD_TESTS OFF CACHE INTERNAL "")
set(XNNPACK_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
set(FP16_BUILD_TESTS OFF CACHE INTERNAL "")
set(FP16_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
set(CLOG_SOURCE_DIR "${PYTORCH_CPUINFO_DIR}/deps/clog")
set(CPUINFO_SOURCE_DIR ${PYTORCH_CPUINFO_DIR})

add_subdirectory(external/FP16)
add_subdirectory(external/pthreadpool)
add_subdirectory(external/XNNPACK)

set_target_properties(fp16 PROPERTIES FOLDER "External/Xnnpack")
set_target_properties(pthreadpool PROPERTIES FOLDER "External/Xnnpack")
set_target_properties(XNNPACK PROPERTIES FOLDER "External/Xnnpack")

set(onnxruntime_EXTERNAL_LIBRARIES_XNNPACK XNNPACK pthreadpool)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK})

# the XNNPACK CMake setup doesn't include the WASM kernels so we have to manually set those up
if (onnxruntime_BUILD_WEBASSEMBLY)
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
target_compile_options(XNNPACK PRIVATE "-pthread")
endif()

message("Adding WebAssembly Source Files to XNNPACK")
set(wasm_src_patterns "${XNNPACK_DIR}/src/wasm-*.c"
"${XNNPACK_DIR}/src/*-wasm-*.c"
"${XNNPACK_DIR}/src/*-wasm.c")
set(wasm32_asm_src_patterns "${XNNPACK_DIR}/src/wasm_shr_*.S")

file(GLOB_RECURSE XNNPACK_WASM_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasm_src_patterns})
file(GLOB_RECURSE XNNPACK_WASM32_ASM_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasm32_asm_src_patterns})

message(DEBUG "XNNPACK_WASM_MICROKERNEL_SRCS:${XNNPACK_WASM_MICROKERNEL_SRCS}")
message(DEBUG "XNNPACK_WASM32_ASM_MICROKERNEL_SRCS:${XNNPACK_WASM32_ASM_MICROKERNEL_SRCS}")

target_sources(XNNPACK PRIVATE ${XNNPACK_WASM_MICROKERNEL_SRCS}
${XNNPACK_WASM32_ASM_MICROKERNEL_SRCS})

if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
target_compile_options(XNNPACK PRIVATE "-msimd128")

set(wasmsimd_src_patterns "${XNNPACK_DIR}/src/wasmsimd-*.c"
"${XNNPACK_DIR}/src/*-wasmsimd-*.c"
"${XNNPACK_DIR}/src/*-wasmsimd.c"
"${XNNPACK_DIR}/src/*/wasmsimd.c")

file(GLOB_RECURSE XNNPACK_WASMSIMD_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasmsimd_src_patterns})
message(DEBUG "XNNPACK_WASMSIMD_MICROKERNEL_SRCS:${XNNPACK_WASMSIMD_MICROKERNEL_SRCS}")

target_sources(XNNPACK PRIVATE ${XNNPACK_WASMSIMD_MICROKERNEL_SRCS})
endif()
endif()
include(xnnpack)
endif()

# onnxruntime-extensions
Expand Down Expand Up @@ -2021,6 +1968,12 @@ if (onnxruntime_ENABLE_TRAINING)
set(onnxruntime_ENABLE_ATEN ON)
endif()

# Default version parts for Microsoft.AI.MachineLearning.dll, onnxruntime.dll, onnxruntime_providers_openvino.dll and onnxruntime_providers_shared.dll in non-ADO pipeline local builds
set(VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.")
set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product version.")
set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.")
set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.")
set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.")

set(ONNXRUNTIME_TARGETS onnxruntime_common onnxruntime_graph onnxruntime_framework onnxruntime_util onnxruntime_providers onnxruntime_optimizer onnxruntime_session onnxruntime_mlas onnxruntime_flatbuffers)
if (onnxruntime_USE_NUPHAR_TVM)
Expand Down Expand Up @@ -2069,12 +2022,6 @@ if (WIN32 AND NOT GDK_PLATFORM)
endif()
endif()

# Default version parts for Microsoft.AI.MachineLearning.dll and onnxruntime.dll in non-ADO pipeline local builds
set(VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.")
set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product version.")
set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.")
set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.")
set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.")
include(wil.cmake)

if (onnxruntime_USE_WINML)
Expand Down
75 changes: 68 additions & 7 deletions cmake/external/dml.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# There are effectively three ways to consume DirectML in this repo:
#
# 1) Public = the build points at a pre-built copy of DirectML distributed as a NuGet package.
# 2) Custom = the build points at a local copy of DirectML (bin/, include/, lib/). The dml_INCLUDE_DIR and
# dml_LIB_DIR variables are also expected to be set to the custom build location.
# 3) Internal = the build points at the DirectML source repo and builds it as part of the main project.
#
# Build Type | onnxruntime_USE_CUSTOM_DIRECTML | dml_EXTERNAL_PROJECT
# -----------|---------------------------------|---------------------
# Public | OFF | OFF
# Custom | ON | OFF
# Internal | ON | ON
#
# The "Public" build type is the default, and any mainline branches (e.g. master, rel-*) subject to CI
# should use the public build configuration. Topic branches can use the internal build type for testing,
# but they must be buildable with a public NuGet package before merging with a mainline branch.

set(onnxruntime_USE_CUSTOM_DIRECTML OFF CACHE BOOL "Depend on a custom/internal build of DirectML.")
set(dml_EXTERNAL_PROJECT OFF CACHE BOOL "Build DirectML as a source dependency.")

if (NOT onnxruntime_USE_CUSTOM_DIRECTML)
if (NOT(MSVC) OR NOT(WIN32))
message(FATAL_ERROR "NuGet packages are only supported for MSVC on Windows.")
Expand All @@ -20,19 +40,60 @@ if (NOT onnxruntime_USE_CUSTOM_DIRECTML)
set(NUGET_CONFIG ${PROJECT_SOURCE_DIR}/../NuGet.config)
set(PACKAGES_CONFIG ${PROJECT_SOURCE_DIR}/../packages.config)
get_filename_component(PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/../packages ABSOLUTE)
set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.1.8.2)
set(DML_PACKAGE_DIR ${PACKAGES_DIR}/Microsoft.AI.DirectML.Preview.1.9.0-devb9b146539f535988728c8eb4791840db54add4a7)
set(DML_SHARED_LIB DirectML.dll)

# Restore nuget packages, which will pull down the DirectML redist package
# Restore nuget packages, which will pull down the DirectML redist package.
add_custom_command(
OUTPUT ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib
DEPENDS ${PACKAGES_CONFIG} ${NUGET_CONFIG}
OUTPUT
${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib
DEPENDS
${PACKAGES_CONFIG}
${NUGET_CONFIG}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/nuget/src/nuget restore ${PACKAGES_CONFIG} -PackagesDirectory ${PACKAGES_DIR} -ConfigFile ${NUGET_CONFIG}
VERBATIM)
VERBATIM
)

include_directories(BEFORE "${DML_PACKAGE_DIR}/include")
add_custom_target(RESTORE_PACKAGES ALL DEPENDS ${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib ${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib)
add_custom_target(
RESTORE_PACKAGES ALL
DEPENDS
${DML_PACKAGE_DIR}/bin/x64-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/x86-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/arm-win/DirectML.lib
${DML_PACKAGE_DIR}/bin/arm64-win/DirectML.lib
)

add_dependencies(RESTORE_PACKAGES nuget)
else()
include_directories(${dml_INCLUDE_DIR})
if (dml_EXTERNAL_PROJECT)
set(dml_preset_config $<IF:$<CONFIG:Debug>,debug,release>)
set(dml_preset_name ${onnxruntime_target_platform}-win-redist-${dml_preset_config})

include(ExternalProject)
ExternalProject_Add(
directml_repo
GIT_REPOSITORY https://dev.azure.com/microsoft/WindowsAI/_git/DirectML
GIT_TAG 2290bd6495fdf8c35822816213516d13f3742cc9
GIT_SHALLOW OFF # not allowed when GIT_TAG is a commit SHA, which is preferred (it's stable, unlike branches)
GIT_PROGRESS ON
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ${CMAKE_COMMAND} --preset ${dml_preset_name} -DDML_BUILD_TESTS=OFF
BUILD_COMMAND ${CMAKE_COMMAND} --build --preset ${dml_preset_name}
INSTALL_COMMAND ${CMAKE_COMMAND} --install build/${dml_preset_name}
STEP_TARGETS install
)

# Target that consumers can use to link with the internal build of DirectML.
set(directml_install_path ${CMAKE_BINARY_DIR}/directml_repo-prefix/src/directml_repo/build/${dml_preset_name}/install)
add_library(DirectML INTERFACE)
target_link_libraries(DirectML INTERFACE ${directml_install_path}/lib/DirectML.lib)
add_dependencies(DirectML directml_repo-install)
include_directories(BEFORE ${directml_install_path}/include)
else()
include_directories(${dml_INCLUDE_DIR})
endif()
endif()
2 changes: 1 addition & 1 deletion cmake/external/json
Submodule json updated 627 files
2 changes: 1 addition & 1 deletion cmake/external/onnx
Submodule onnx updated 1757 files
60 changes: 60 additions & 0 deletions cmake/external/xnnpack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
set(XNNPACK_DIR external/XNNPACK)
set(XNNPACK_INCLUDE_DIR ${XNNPACK_DIR}/include)
set(XNNPACK_USE_SYSTEM_LIBS ON CACHE INTERNAL "")
set(XNNPACK_BUILD_TESTS OFF CACHE INTERNAL "")
set(XNNPACK_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
set(FP16_BUILD_TESTS OFF CACHE INTERNAL "")
set(FP16_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
set(CLOG_SOURCE_DIR "${PYTORCH_CPUINFO_DIR}/deps/clog")
set(CPUINFO_SOURCE_DIR ${PYTORCH_CPUINFO_DIR})

if (onnxruntime_BUILD_WEBASSEMBLY)
execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenSupport.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${XNNPACK_DIR})
endif()

add_subdirectory(external/FP16)
add_subdirectory(external/pthreadpool)
add_subdirectory(external/XNNPACK)

set_target_properties(fp16 PROPERTIES FOLDER "External/Xnnpack")
set_target_properties(pthreadpool PROPERTIES FOLDER "External/Xnnpack")
set_target_properties(XNNPACK PROPERTIES FOLDER "External/Xnnpack")

set(onnxruntime_EXTERNAL_LIBRARIES_XNNPACK XNNPACK pthreadpool)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK})

# the XNNPACK CMake setup doesn't include the WASM kernels so we have to manually set those up
if (onnxruntime_BUILD_WEBASSEMBLY)
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
target_compile_options(XNNPACK PRIVATE "-pthread")
endif()

message("Adding WebAssembly Source Files to XNNPACK")
set(wasm_src_patterns "${XNNPACK_DIR}/src/wasm-*.c"
"${XNNPACK_DIR}/src/*-wasm-*.c"
"${XNNPACK_DIR}/src/*-wasm.c")
set(wasm32_asm_src_patterns "${XNNPACK_DIR}/src/wasm_shr_*.S")

file(GLOB_RECURSE XNNPACK_WASM_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasm_src_patterns})
file(GLOB_RECURSE XNNPACK_WASM32_ASM_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasm32_asm_src_patterns})

message(DEBUG "XNNPACK_WASM_MICROKERNEL_SRCS:${XNNPACK_WASM_MICROKERNEL_SRCS}")
message(DEBUG "XNNPACK_WASM32_ASM_MICROKERNEL_SRCS:${XNNPACK_WASM32_ASM_MICROKERNEL_SRCS}")

target_sources(XNNPACK PRIVATE ${XNNPACK_WASM_MICROKERNEL_SRCS}
${XNNPACK_WASM32_ASM_MICROKERNEL_SRCS})

if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
target_compile_options(XNNPACK PRIVATE "-msimd128")

set(wasmsimd_src_patterns "${XNNPACK_DIR}/src/wasmsimd-*.c"
"${XNNPACK_DIR}/src/*-wasmsimd-*.c"
"${XNNPACK_DIR}/src/*-wasmsimd.c"
"${XNNPACK_DIR}/src/*/wasmsimd.c")

file(GLOB_RECURSE XNNPACK_WASMSIMD_MICROKERNEL_SRCS CONFIGURE_DEPENDS ${wasmsimd_src_patterns})
message(DEBUG "XNNPACK_WASMSIMD_MICROKERNEL_SRCS:${XNNPACK_WASMSIMD_MICROKERNEL_SRCS}")

target_sources(XNNPACK PRIVATE ${XNNPACK_WASMSIMD_MICROKERNEL_SRCS})
endif()
endif()
1 change: 1 addition & 0 deletions cmake/onnxruntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ target_compile_definitions(onnxruntime PRIVATE VER_MINOR=${VERSION_MINOR_PART})
target_compile_definitions(onnxruntime PRIVATE VER_BUILD=${VERSION_BUILD_PART})
target_compile_definitions(onnxruntime PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART})
target_compile_definitions(onnxruntime PRIVATE VER_STRING=\"${VERSION_STRING}\")
target_compile_definitions(onnxruntime PRIVATE FILE_NAME=\"onnxruntime.dll\")

if(UNIX)
if (APPLE)
Expand Down
4 changes: 4 additions & 0 deletions cmake/onnxruntime_csharp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ if (onnxruntime_USE_TENSORRT)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_TENSORRT;")
endif()

if (onnxruntime_USE_XNNPACK)
STRING(APPEND CSHARP_PREPROCESSOR_DEFINES "USE_XNNPACK;")
endif()

include(CSharpUtilities)

# generate Directory.Build.props
Expand Down
Loading

0 comments on commit 68cecd8

Please sign in to comment.