-
Notifications
You must be signed in to change notification settings - Fork 4
Add onnxruntime #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add onnxruntime #19
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6506173
onnxruntime
smanolloff 96f29dc
macos-intel-10.13 and ios-12.0 compat
smanolloff 56f3512
win7 compat
smanolloff ef8b4b1
Revert "win7 compat"
smanolloff 75c2c1e
lower compiler version for win7
smanolloff 80b722a
try suggested patch from PR review
smanolloff 2e849f7
address PR comment
smanolloff 9616cbe
move date/*:use_system_tz_db to conan profile
smanolloff e8f64c6
address review comments
smanolloff 889c121
remove debug line
smanolloff 0fc6e7a
fix comment
smanolloff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| patches: | ||
| "1.16.2": | ||
| - patch_file: "patches/apple-pre-2019.diff" | ||
| patch_description: | | ||
| Fixes errors for older apple targets: | ||
| error: 'basic_fstream' is unavailable: introduced in macOS 10.15 | ||
| error: 'basic_fstream' is unavailable: introduced in iOS 13.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- a/onnx/common/file_utils.h | ||
| +++ b/onnx/common/file_utils.h | ||
| @@ -17,8 +17,7 @@ namespace ONNX_NAMESPACE { | ||
|
|
||
| template <typename T> | ||
| void LoadProtoFromPath(const std::string proto_path, T& proto) { | ||
| - std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path); | ||
| - std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary); | ||
| + std::fstream proto_stream(proto_path, std::ios::in | std::ios::binary); | ||
| if (!proto_stream.good()) { | ||
| fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. "); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| patches: | ||
| "1.18.1": | ||
| - patch_file: "patches/android-64.diff" | ||
| patch_description: | | ||
| Fixes error for arm64-v8a targets: | ||
| onnxruntime/core/mlas/lib/mlasi.h:366:11: error: unknown type name 'bfloat16_t' | ||
kambala-decapitator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - patch_file: "patches/msvc-x86.diff" | ||
| patch_description: | | ||
| Fixes detection of x86 windows targets during cross-compilation. | ||
smanolloff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - patch_file: "patches/win7.diff" | ||
| patch_description: | | ||
| Fixes compile errors on for windows 7 targets: | ||
| error C3861: 'CreateFile2': identifier not found | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- a/cmake/onnxruntime_mlas.cmake | ||
| +++ b/cmake/onnxruntime_mlas.cmake | ||
| @@ -352,7 +362,7 @@ else() | ||
| ${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon.cpp | ||
| ) | ||
| set_source_files_properties(${MLAS_SRC_DIR}/sqnbitgemm_kernel_neon.cpp | ||
| - PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+dotprod") | ||
| + PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+dotprod+bf16") | ||
| if (NOT APPLE) | ||
| set(mlas_platform_srcs | ||
| ${mlas_platform_srcs} | ||
| @@ -368,13 +378,13 @@ else() | ||
| ${MLAS_SRC_DIR}/qgemm_kernel_ummla.cpp | ||
| ${MLAS_SRC_DIR}/sbgemm_kernel_neon.cpp | ||
| ) | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/aarch64/HalfGemmKernelNeon.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16 ") | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/aarch64/QgemmS8S8KernelSmmla.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+i8mm ") | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/aarch64/QgemmU8X8KernelUmmla.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+i8mm ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/aarch64/HalfGemmKernelNeon.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16+bf16 ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/aarch64/QgemmS8S8KernelSmmla.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+i8mm+bf16 ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/aarch64/QgemmU8X8KernelUmmla.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+i8mm+bf16 ") | ||
| set_source_files_properties(${MLAS_SRC_DIR}/aarch64/SbgemmKernelNeon.S PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+bf16 ") | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/activate_fp16.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16 ") | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/dwconv.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16 ") | ||
| - set_source_files_properties(${MLAS_SRC_DIR}/pooling_fp16.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16 ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/activate_fp16.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16+bf16 ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/dwconv.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16+bf16 ") | ||
| + set_source_files_properties(${MLAS_SRC_DIR}/pooling_fp16.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+fp16+bf16 ") | ||
| set_source_files_properties(${MLAS_SRC_DIR}/sbgemm_kernel_neon.cpp PROPERTIES COMPILE_FLAGS " -march=armv8.2-a+bf16 ") | ||
| endif() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- a/cmake/adjust_global_compile_flags.cmake | ||
| +++ b/cmake/adjust_global_compile_flags.cmake | ||
| @@ -226,13 +226,17 @@ endmacro() | ||
|
|
||
| #Set global compile flags for all the source code(including third_party code like protobuf) | ||
| #This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch | ||
| +message(STATUS "MSVC=${MSVC} | CMAKE_VS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME} | CMAKE_C_COMPILER_ARCHITECTURE_ID=${CMAKE_C_COMPILER_ARCHITECTURE_ID} | CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}") | ||
kambala-decapitator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (MSVC) | ||
| if (CMAKE_VS_PLATFORM_NAME) | ||
| # Multi-platform generator | ||
| set(onnxruntime_target_platform ${CMAKE_VS_PLATFORM_NAME}) | ||
| + elseif (CMAKE_C_COMPILER_ARCHITECTURE_ID) | ||
| + set(onnxruntime_target_platform ${CMAKE_C_COMPILER_ARCHITECTURE_ID}) | ||
| else() | ||
| set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) | ||
| endif() | ||
| + message(STATUS "Temporary onnxruntime_target_platform=${onnxruntime_target_platform}") | ||
| if (onnxruntime_target_platform STREQUAL "ARM64") | ||
| set(onnxruntime_target_platform "ARM64") | ||
| enable_language(ASM_MARMASM) | ||
| @@ -241,18 +245,19 @@ if (MSVC) | ||
| elseif (onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") | ||
| set(onnxruntime_target_platform "ARM") | ||
| enable_language(ASM_MARMASM) | ||
| - elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") | ||
| + elseif (onnxruntime_target_platform MATCHES "[Xx]64" OR onnxruntime_target_platform MATCHES "[Xx]86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") | ||
kambala-decapitator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set(onnxruntime_target_platform "x64") | ||
| enable_language(ASM_MASM) | ||
| - elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") | ||
| + elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform MATCHES "[Xx]86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") | ||
| set(onnxruntime_target_platform "x86") | ||
| enable_language(ASM_MASM) | ||
| message("Enabling SAFESEH for x86 build") | ||
| set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh") | ||
| else() | ||
| - message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
| + message(FATAL_ERROR "Unknown onnxruntime_target_platform: ${onnxruntime_target_platform}") | ||
| endif() | ||
|
|
||
| + message(STATUS "Final onnxruntime_target_platform=${onnxruntime_target_platform}") | ||
|
|
||
| #Always enable exception handling, even for Windows ARM | ||
| if (NOT onnxruntime_DISABLE_EXCEPTIONS) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- a/onnxruntime/test/shared_lib/test_model_loading.cc | ||
| +++ b/onnxruntime/test/shared_lib/test_model_loading.cc | ||
| @@ -227,7 +227,7 @@ using ScopedFileDescriptor = ScopedResource<FileDescriptorTraits>; | ||
|
|
||
| void FileMmap(const ORTCHAR_T* file_path, void*& mapped_base) { | ||
| #ifdef _WIN32 | ||
| - wil::unique_hfile file_handle{CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)}; | ||
| + wil::unique_hfile file_handle{CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)}; | ||
| ASSERT_TRUE(file_handle.get() != INVALID_HANDLE_VALUE); | ||
|
|
||
| wil::unique_hfile file_mapping_handle{ | ||
| --- a/onnxruntime/core/platform/windows/env.cc | ||
| +++ b/onnxruntime/core/platform/windows/env.cc | ||
| @@ -314,7 +314,7 @@ PIDType WindowsEnv::GetSelfPid() const { | ||
|
|
||
| Status WindowsEnv::GetFileLength(_In_z_ const ORTCHAR_T* file_path, size_t& length) const { | ||
| wil::unique_hfile file_handle{ | ||
| - CreateFile2(file_path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, OPEN_EXISTING, NULL)}; | ||
| + CreateFileW(file_path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)}; | ||
| if (file_handle.get() == INVALID_HANDLE_VALUE) { | ||
| const auto error_code = GetLastError(); | ||
| return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToUTF8String(Basename(file_path)), " fail, errcode = ", error_code, " - ", std::system_category().message(error_code)); | ||
| @@ -361,7 +361,7 @@ Status WindowsEnv::ReadFileIntoBuffer(_In_z_ const ORTCHAR_T* const file_path, c | ||
| ORT_RETURN_IF_NOT(offset >= 0, "offset < 0"); | ||
| ORT_RETURN_IF_NOT(length <= buffer.size(), "length > buffer.size()"); | ||
| wil::unique_hfile file_handle{ | ||
| - CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)}; | ||
| + CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)}; | ||
| if (file_handle.get() == INVALID_HANDLE_VALUE) { | ||
| const auto error_code = GetLastError(); | ||
| return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToUTF8String(Basename(file_path)), " fail, errcode = ", error_code, " - ", std::system_category().message(error_code)); | ||
| @@ -414,7 +414,7 @@ Status WindowsEnv::MapFileIntoMemory(_In_z_ const ORTCHAR_T* file_path, | ||
| } | ||
|
|
||
| wil::unique_hfile file_handle{ | ||
| - CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)}; | ||
| + CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)}; | ||
| if (file_handle.get() == INVALID_HANDLE_VALUE) { | ||
| const auto error_code = GetLastError(); | ||
| return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, | ||
| @@ -600,16 +600,14 @@ common::Status WindowsEnv::GetCanonicalPath( | ||
| PathString& canonical_path) const { | ||
| // adapted from MSVC STL std::filesystem::canonical() implementation | ||
| // https://github.com/microsoft/STL/blob/ed3cbf36416a385828e7a5987ca52cb42882d84b/stl/inc/filesystem#L2986 | ||
| - CREATEFILE2_EXTENDED_PARAMETERS param; | ||
| - memset(¶m, 0, sizeof(param)); | ||
| - param.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS); | ||
| - param.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS; | ||
| - wil::unique_hfile file_handle{CreateFile2( | ||
| - path.c_str(), | ||
| - FILE_READ_ATTRIBUTES, | ||
| - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | ||
| - OPEN_EXISTING, | ||
| - ¶m)}; | ||
| + wil::unique_hfile file_handle{CreateFileW( | ||
kambala-decapitator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| + path.c_str(), // LPCWSTR lpFileName | ||
| + FILE_READ_ATTRIBUTES, // DWORD dwDesiredAccess | ||
| + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // DWORD dwShareMode | ||
| + nullptr, // LPSECURITY_ATTRIBUTES lpSecurityAttributes | ||
| + OPEN_EXISTING, // DWORD dwCreationDisposition | ||
| + FILE_FLAG_BACKUP_SEMANTICS, // DWORD dwFlagsAndAttributes | ||
| + nullptr)}; // HANDLE hTemplateFile | ||
|
|
||
| if (file_handle.get() == INVALID_HANDLE_VALUE) { | ||
| const auto error_code = GetLastError(); | ||
| --- a/onnxruntime/core/platform/windows/env_time.cc | ||
| +++ b/onnxruntime/core/platform/windows/env_time.cc | ||
| @@ -18,6 +18,7 @@ limitations under the License. | ||
|
|
||
| #include <time.h> | ||
| #include <windows.h> | ||
| +#include <sysinfoapi.h> | ||
| #include <chrono> | ||
| #include <numeric> | ||
| #include <algorithm> | ||
| @@ -28,14 +29,10 @@ namespace { | ||
|
|
||
| class WindowsEnvTime : public EnvTime { | ||
| public: | ||
| - WindowsEnvTime() : GetSystemTimePreciseAsFileTime_(GetSystemTimePreciseAsFileTime) {} | ||
| + WindowsEnvTime() = default; | ||
|
|
||
| uint64_t NowMicros() override { | ||
| - if (GetSystemTimePreciseAsFileTime_ != NULL) { | ||
| - // GetSystemTimePreciseAsFileTime function is only available in latest | ||
| - // versions of Windows, so we need to check for its existence here. | ||
| - // All std::chrono clocks on Windows proved to return | ||
| - // values that may repeat, which is not good enough for some uses. | ||
| + // System time in 100-ns ticks since 1601-01-01 | ||
| constexpr int64_t kUnixEpochStartTicks = 116444736000000000i64; | ||
| constexpr int64_t kFtToMicroSec = 10; | ||
|
|
||
| @@ -43,7 +40,8 @@ class WindowsEnvTime : public EnvTime { | ||
| // just any microseconds because it is often used as an argument | ||
| // to TimedWait() on condition variable | ||
| FILETIME system_time; | ||
| - GetSystemTimePreciseAsFileTime_(&system_time); | ||
| + // Get current system time as FILETIME (available on all supported Windows versions) | ||
| + GetSystemTimeAsFileTime(&system_time); | ||
|
|
||
| LARGE_INTEGER li; | ||
| li.LowPart = system_time.dwLowDateTime; | ||
| @@ -54,16 +52,11 @@ class WindowsEnvTime : public EnvTime { | ||
| li.QuadPart /= kFtToMicroSec; | ||
| return li.QuadPart; | ||
| } | ||
| - using namespace std::chrono; | ||
| - return duration_cast<microseconds>(system_clock::now().time_since_epoch()) | ||
| - .count(); | ||
| - } | ||
| - | ||
| - void SleepForMicroseconds(int64_t micros) { Sleep(static_cast<DWORD>(micros) / 1000); } | ||
|
|
||
| - private: | ||
| - typedef VOID(WINAPI* FnGetSystemTimePreciseAsFileTime)(LPFILETIME); | ||
| - FnGetSystemTimePreciseAsFileTime GetSystemTimePreciseAsFileTime_; | ||
| + void SleepForMicroseconds(int64_t micros) { | ||
| + DWORD ms = static_cast<DWORD>((micros + 999) / 1000); | ||
| + Sleep(ms); | ||
| + } | ||
| }; | ||
|
|
||
| } // namespace | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py | ||
| index 0757ecdc0..bb8cca8bf 100644 | ||
| --- a/recipes/onnxruntime/all/conanfile.py | ||
| +++ b/recipes/onnxruntime/all/conanfile.py | ||
| @@ -34,6 +34,11 @@ class OnnxRuntimeConan(ConanFile): | ||
| "fPIC": True, | ||
| "with_xnnpack": False, | ||
| "with_cuda": False, | ||
| + # Prevents libcurl dependency (fails to build due to system zlib) | ||
| + # NOTE: | ||
| + # 'use_system_tz_db' is specific to date/3.0.1 (version pinned by onnxruntime/1.18.1). | ||
| + # Newer date recipes would need the tz_db=system option instead. | ||
| + "date/*:use_system_tz_db": True, | ||
| } | ||
| short_paths = True | ||
|
|
||
| @@ -47,7 +52,7 @@ class OnnxRuntimeConan(ConanFile): | ||
| def _compilers_minimum_version(self): | ||
| return { | ||
| "Visual Studio": "17", | ||
| - "msvc": "193", | ||
| + "msvc": "192", | ||
| "gcc": "9", | ||
| "clang": "5", | ||
| "apple-clang": "10", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.