onnxruntime/cmake/onnxruntime_framework.cmake

112 lines
5.1 KiB
CMake
Raw Normal View History

2018-11-20 00:48:22 +00:00
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
2019-04-29 19:58:20 +00:00
file(GLOB_RECURSE onnxruntime_framework_srcs CONFIGURE_DEPENDS
2018-11-20 00:48:22 +00:00
"${ONNXRUNTIME_INCLUDE_DIR}/core/framework/*.h"
"${ONNXRUNTIME_ROOT}/core/framework/*.h"
"${ONNXRUNTIME_ROOT}/core/framework/*.cc"
)
if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
file(GLOB_RECURSE onnxruntime_training_framework_torch_srcs CONFIGURE_DEPENDS
"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/*.h"
"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/*.cc"
)
list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_torch_srcs})
endif()
if (onnxruntime_MINIMAL_BUILD)
set(onnxruntime_framework_src_exclude
"${ONNXRUNTIME_ROOT}/core/framework/fallback_cpu_capability.h"
"${ONNXRUNTIME_ROOT}/core/framework/fallback_cpu_capability.cc"
)
# custom ops support must be explicitly enabled in a minimal build. exclude if not.
if (NOT onnxruntime_MINIMAL_BUILD_CUSTOM_OPS)
list(APPEND onnxruntime_framework_src_exclude
"${ONNXRUNTIME_INCLUDE_DIR}/core/framework/customregistry.h"
"${ONNXRUNTIME_ROOT}/core/framework/customregistry.cc"
)
endif()
list(REMOVE_ITEM onnxruntime_framework_srcs ${onnxruntime_framework_src_exclude})
endif()
2018-11-20 00:48:22 +00:00
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_framework_srcs})
onnxruntime_add_static_library(onnxruntime_framework ${onnxruntime_framework_srcs})
if(onnxruntime_ENABLE_INSTRUMENT)
target_compile_definitions(onnxruntime_framework PRIVATE ONNXRUNTIME_ENABLE_INSTRUMENT)
endif()
if(onnxruntime_USE_TENSORRT OR onnxruntime_USE_NCCL)
# TODO: for now, core framework depends on CUDA. It should be moved to TensorRT EP
# TODO: provider_bridge_ort.cc should not include nccl.h
Ryanunderhill/cuda shared (#7626) * First iteration of making cuda a shared provider. Separated out shared OpKernel change, so doing this to merge with that change. * More cuda shared library refactoring * More cuda shared library refactoring * More build options tested, converted the training ops over. * Fix merge breaks * Fix submodules * Fix submodules * Fix submodules * Fix python * Fix compile errors * Duplicate symbol fix * Test fix for ROCM provider * Another ROCM test workaround * ROCM Build Test * ROCM build fix * ROCM * ROCM * ROCM * ROCM * ROCM * ROCM test * Reduce header dependencies * Remove redundant namespace * Test fix for linux * Fix linux build * Fix Eigen build error * Fix unused parameter warning * Test link error * Another linker test * Linker test * Linker test * Another test * Another build test * Fix linux link error * Build test * Fix control flow ops to use common base class with core code * Remove extra qualifiers * Fix template syntax for linux * Fix cuda memory leak * Fix pybind * Test disabling cast * Cleanup * Restore cuda in test * Remove more header dependencies * Test not adding cuda provider to session * Make GetProviderInfo_CUDA throw * No-op cuda provider creation * Fix some setup issues * Fix memory cleanup on unload * Diagnostics * Don't unload library * Add diagnostics * Fix deleting registry at right time. * Test disabling profiler * Fix merge break * Revert profiler change * Move unloading of shared providers into Environment * Free more global allocations before library unloads * Add more diagnostics * Move unloading back to the OrtEnv as there are multiple Environments created during a session. Remove some library dependencies for tests. * Fix more cmake files * ERROR -> WARNING * Fix python shutdown * Test not using dml in pipeline * Change python version and disable dml * Update python version * Test adding unload method for shared providers * Disable DLL test * Python test * Revert "Python test" This reverts commit c7ec2cfe98e4dcc30e1a54cad71adb89ab18adde. * Revert "Disable DLL test" This reverts commit e901cb93aafd537af088fa29629029a479926362. * Revert "Test adding unload method for shared providers" This reverts commit c427b7879989be93572b09c4662b1fa8b153eec9. * Point to RyanWinGPU * Revert python version * Fix id_to_allocator_map * Another python exit test * Remove extra debug messages Try a more clean python shutdown through DllMain * Revert DllMain idea, it didn't work * Merge conflicts * Fix merge with master issues. * Comments * Undo edit to file * Cleanup + new training ops * Revert yml changes * Fix another merge error * ROCM fix * ROCM fix v2 * Put back Linux hack, it is necessary * Stupid fixes * Fix submodule out of sync * ROCM fix 3 * ROCM 4 * Test java fix * Fix typos * Java test on my VM * Fix build error * Spotless fix * Leave temp file around to load properly * Fix cleanup on exit * Fix break * Java comments * Remove LongformerAttentionBase workaround * Spotless fix * Switch yml back to regular build pool * Revert "Switch yml back to regular build pool" This reverts commit be35fc2a5ab53868568791f1e54320e6c7fc75ce. * Code review feedback * Fix errors due to merge * Spotless fix * Fix minimal build * Java fix for non cuda case * Java fix for CPU build * Fix Nuphar? * Fix nuphar 2 * Fix formatting * Revert "Remove LongformerAttentionBase workaround" This reverts commit 648679b37093740bbefc7b41ff53d3239451333f. * Training fix * Another java fix * Formatting * Formatting * For orttraining * Last orttraining build fix... * training fixes * Fix test provider error * Missing pass command * Removed in wrong spot * Python typo * Python typos * Python crash on exit, possibly due to unloading of libraries. * Remove test_execution_provider from training build Only enable python atexit on windows Remove assert on provider library exit * Still can't unload providers in python, alas. * Disable Nvtx temporarily * MPI Kernels for Training * MPI Kernels part 2 * Patch through INcclService * Oops, wrong CMakeLists * Missing namespace * Fix missing () * Move INcclService::GetInstance around to link nicer * Missing } * Missing MPI libraries for Cuda * Add extra GetType functions used by MPI * Missing Nccl library * Remove LOGS statements as a test * Add in a couple more missing GetType methods * Update comments * Missed a logging reference in mpi_context.h * Convert aten_op to shared (due to marge with master) * Test moving DistributedRunContext instance into shared provider layer (with purpose error to verify it's being built properly) * Test passed, now with fix * Missing static * Oops, scope DistributedRunContext to just NCCL * Merge related issues and code review feedback. * Merge error * Bump to rel-1.9.1 (#7684) * Formatting * Code review feedback for Java build on non Windows * Remove cupti library dependency from core library * Test Java pipeline fix * Linux build fix * Revert "Linux build fix" This reverts commit a73a811516ad2acdbbea890a2ae2143341f915ad. * Revert "Remove cupti library dependency from core library" This reverts commit 6a889ee8bf72f34f44b8a4642728b7bd83f61255. * Packaging pipeline fixes to copy cuda shared provider for tensorrt & standard packages * Add cuda to Tensorrt nuget package * onnxruntime_common still has a cuda header dependency Co-authored-by: ashbhandare <ash.bhandare@gmail.com>
2021-05-20 14:53:47 +00:00
target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${onnxruntime_CUDNN_HOME}/include PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
else()
Ryanunderhill/cuda shared (#7626) * First iteration of making cuda a shared provider. Separated out shared OpKernel change, so doing this to merge with that change. * More cuda shared library refactoring * More cuda shared library refactoring * More build options tested, converted the training ops over. * Fix merge breaks * Fix submodules * Fix submodules * Fix submodules * Fix python * Fix compile errors * Duplicate symbol fix * Test fix for ROCM provider * Another ROCM test workaround * ROCM Build Test * ROCM build fix * ROCM * ROCM * ROCM * ROCM * ROCM * ROCM test * Reduce header dependencies * Remove redundant namespace * Test fix for linux * Fix linux build * Fix Eigen build error * Fix unused parameter warning * Test link error * Another linker test * Linker test * Linker test * Another test * Another build test * Fix linux link error * Build test * Fix control flow ops to use common base class with core code * Remove extra qualifiers * Fix template syntax for linux * Fix cuda memory leak * Fix pybind * Test disabling cast * Cleanup * Restore cuda in test * Remove more header dependencies * Test not adding cuda provider to session * Make GetProviderInfo_CUDA throw * No-op cuda provider creation * Fix some setup issues * Fix memory cleanup on unload * Diagnostics * Don't unload library * Add diagnostics * Fix deleting registry at right time. * Test disabling profiler * Fix merge break * Revert profiler change * Move unloading of shared providers into Environment * Free more global allocations before library unloads * Add more diagnostics * Move unloading back to the OrtEnv as there are multiple Environments created during a session. Remove some library dependencies for tests. * Fix more cmake files * ERROR -> WARNING * Fix python shutdown * Test not using dml in pipeline * Change python version and disable dml * Update python version * Test adding unload method for shared providers * Disable DLL test * Python test * Revert "Python test" This reverts commit c7ec2cfe98e4dcc30e1a54cad71adb89ab18adde. * Revert "Disable DLL test" This reverts commit e901cb93aafd537af088fa29629029a479926362. * Revert "Test adding unload method for shared providers" This reverts commit c427b7879989be93572b09c4662b1fa8b153eec9. * Point to RyanWinGPU * Revert python version * Fix id_to_allocator_map * Another python exit test * Remove extra debug messages Try a more clean python shutdown through DllMain * Revert DllMain idea, it didn't work * Merge conflicts * Fix merge with master issues. * Comments * Undo edit to file * Cleanup + new training ops * Revert yml changes * Fix another merge error * ROCM fix * ROCM fix v2 * Put back Linux hack, it is necessary * Stupid fixes * Fix submodule out of sync * ROCM fix 3 * ROCM 4 * Test java fix * Fix typos * Java test on my VM * Fix build error * Spotless fix * Leave temp file around to load properly * Fix cleanup on exit * Fix break * Java comments * Remove LongformerAttentionBase workaround * Spotless fix * Switch yml back to regular build pool * Revert "Switch yml back to regular build pool" This reverts commit be35fc2a5ab53868568791f1e54320e6c7fc75ce. * Code review feedback * Fix errors due to merge * Spotless fix * Fix minimal build * Java fix for non cuda case * Java fix for CPU build * Fix Nuphar? * Fix nuphar 2 * Fix formatting * Revert "Remove LongformerAttentionBase workaround" This reverts commit 648679b37093740bbefc7b41ff53d3239451333f. * Training fix * Another java fix * Formatting * Formatting * For orttraining * Last orttraining build fix... * training fixes * Fix test provider error * Missing pass command * Removed in wrong spot * Python typo * Python typos * Python crash on exit, possibly due to unloading of libraries. * Remove test_execution_provider from training build Only enable python atexit on windows Remove assert on provider library exit * Still can't unload providers in python, alas. * Disable Nvtx temporarily * MPI Kernels for Training * MPI Kernels part 2 * Patch through INcclService * Oops, wrong CMakeLists * Missing namespace * Fix missing () * Move INcclService::GetInstance around to link nicer * Missing } * Missing MPI libraries for Cuda * Add extra GetType functions used by MPI * Missing Nccl library * Remove LOGS statements as a test * Add in a couple more missing GetType methods * Update comments * Missed a logging reference in mpi_context.h * Convert aten_op to shared (due to marge with master) * Test moving DistributedRunContext instance into shared provider layer (with purpose error to verify it's being built properly) * Test passed, now with fix * Missing static * Oops, scope DistributedRunContext to just NCCL * Merge related issues and code review feedback. * Merge error * Bump to rel-1.9.1 (#7684) * Formatting * Code review feedback for Java build on non Windows * Remove cupti library dependency from core library * Test Java pipeline fix * Linux build fix * Revert "Linux build fix" This reverts commit a73a811516ad2acdbbea890a2ae2143341f915ad. * Revert "Remove cupti library dependency from core library" This reverts commit 6a889ee8bf72f34f44b8a4642728b7bd83f61255. * Packaging pipeline fixes to copy cuda shared provider for tensorrt & standard packages * Add cuda to Tensorrt nuget package * onnxruntime_common still has a cuda header dependency Co-authored-by: ashbhandare <ash.bhandare@gmail.com>
2021-05-20 14:53:47 +00:00
target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
endif()
# Needed for the provider interface, as it includes training headers when training is enabled
if (onnxruntime_ENABLE_TRAINING OR onnxruntime_ENABLE_TRAINING_OPS)
target_include_directories(onnxruntime_framework PRIVATE ${ORTTRAINING_ROOT})
training with custom autograd Functions (#7513) * Register Torch Custom autograd.Function * Add flag to supress pybind11 warning * Avoid unnecessary include in cmake * Add missing reference * Add getter for registerred functions * Format for making subsquent changes cleaner * Fix interop feature build failure * Forward pass, run PyOP on CPU EP * clean up the code * Fix build * Define new ops * refactor pyop - extract PyOpLibProxy class * Hacks to run example * implement the kernel compute func * add back PyOP for comparision experiments * debug info - thread id * refine the kernels * Polish code (cherry picked from commit 4ed606f9a0833592b325a4b40cf917e219845f6f) * Fix a the Tensor address mismatch in C++ side * PythonOpGrad compute * add distributed test case * refine test cases * get dist.get_rank() in Autograd forward pass * Add CUDA kernels * Store float, int, and tuple of them as PythonOp's attributes * Populate local changes * Fix bugs * PythonOp/PythonOpGrad CUDA kernels * Support non-tensor inputs * Single GPU FP16 Run Pass (cherry picked from commit e539989e91e18ee997900292d3493b97d3eafa8a) * Fix segement * add basic test cases * Save progress * fix gradient builder for a Add op who have same inputs * add test cases for auto grad fallback feature * fix ref cnt issue. add thread id for debugging * POC: remove interface class * Remove interface classes * Clean a bit * Coarse-grained clean up after rebase master * reset pyop and language_interop_ops to latest master * Fix missing part during merge * re-structure torch related language interop files * Fix build * Fix tests and build * Fix build and basic unit tests * Fix most of uts * remove unnecessary import * clean up and fix build when enabling language_interop_ops * Fix single-GPU UTs * Move runner register into ORT package * Update dist UTs to new style * Also fix distributed UTs and leaf gradient problem * Static generation for constant args * Move arg_positions_ to static field * Rename some functions * Move arg ceration into a function * Clean output logic in PythonOp * Move PythonOp's ctor * Revise PythonOpGrad * Fix "ORT only supports contiguous tensor for now" for inputs * Fix evaulation mode error, add test & clean up * clean up codes * Fix issues introduced by recent master change (enabled symbolic shape infer) * automatically register forward/backward function pointers && clean up * Fix multi-output case * Add a test back * fix build and clean up * RAII for function params PyObject * Use new exporter * Clean full name in new exporter * Fix UTs * Format a file * Add "inplace" back Remove a legacy comment * Refine TorchProxy 1. Make TorchProxy a formal singleton class. 2. Remove unused Scope class. 3. Simplify the call to Forward and Backward. The two functions now automatically acquire and release GIL state, so user doesn't need any GIL-related calls. * Format * Add lock to avoid racing condition when registering Python objs * Fix Python call param ref issues && Add RefcountTracker for debug build && Clean up * clean up print * Resolve part of comments && clean up * Fix a potential bug * track pyobject consistently * move kernels to cpu provider as base class * Refactor - 1. Extract PythonOpBase/PythonOpGradBase 2. Implement CPU kernels 3. Test coverage for CPU kernels * Refine register code * Add a missing macro * Release python call result objects with PythonObjectPtr && Add UnRegisterContext && Track PyObject for Debugging && Clena up * Fix random segfault issue - relasing a wrong ctx pointer for inplace cases * put ref count in debug macro * Move GIL out * Refine tests * Fix memory leak issue && forward output lifecycle issue: 1. Unregister the OrtValue PythonObject. Currently, the OrtValue shared same buffer with PythonOp/PythonOpGrad's output. So after those kernels outputs are released, the "leaked" OrtValue caused the shared buffer cannot be released. 2. According PyTorch forward+backward execution. The forward outputs (e.g. torch tensors) maintains the context/saved variables/dirty inputs, etc, which are used for backward execution, so its life should be after the backward runs. This change added such a depencencies between PythonOpGrad on PythonOp. * Move dlpack->ortvalue into C++ to avoid temp object registration * Fix the over released Py_False/Py_True && refine tests * Clean up unused functions * Always assume the first forward output is context so we don't need to test unused cases. * Fix a memory leak * move-copy unique_ptr & avoid C-style casting * Use inplace attribute to determine if input tensors are copied * Move DlpackCapsuleDestructor's to a common place * Thread-safe TorchProxy * Use OrtValue instead of OrtValue* * Only keep checks for Debug build * Wrap some long line per comment * onnx_export_type --> kwargs * Use requires_grads to create PythonOpGrad's inputs * add missing files during master merge * Fix build issue after merge * Address two comments. 1. Internalize DlpackCapsuleDestructor 2. Change "(" to "]" for describing closed interval. * Address some comments. 1. "override" -> "overwrite" to avoid using reserved keyword. 2. Call DLPack's helper to create OrtValue for avoiding repeated code. * Address comments. 1. Pass std::mutex to registeration helpers so their callers don't have to lock the mutex expclicitly. 2. Rename "func_context_pool_mutex_" to "mutex_". This mutex is the global mutex for OrtTorchFunctionPool. * Add bridging code to make cuda kernels work with merged master * put debue macro check within RefCountTracker && use default logger for debug info && remove useless ortvalue_ptr interface && typos && revert unncessary blank line changes * fix some comments * Resolve more comments * Capitalize a word * use unique_ptr instead of ObjectPointer for PyObject management && add converntion * Support symbolic shape * Remove unused variable * fix build * Enable function registration for training only && rectify ToDlpack/FromDlpack merge with master. * Don't add context for non-PythonOp opeartors (for example AtenOp) * Fix build error * Polish frontend part. 1. Avoid adding kwargs to ORTModule's ctor 2. Use onnx_export_type rather than kwargs for type safty 3. Fix some build bugs. * Resolve simpler comments * Resolve export related comments * sync master && fix tests && fix non-training build error * Fix build errors * add target link lib * windows build error * Fix orttraining-linux-ci build * disable autograd test && clean up * fix linux orttraining ci build * try fixing win build error * Revise append calls in runner * Enable custom function using a function * Rename to avoid using reservied keyword * Use list comprehension * Set ORT random seed in tests * Remove print code and fix ctx shape * [] -> list() * Move autograd.Function and nn.Module into corresponding functions * Move test helpers * Polish dist test a bit. Tried move helpers to helper file but it causes a deadlock. * trying fix undefined reference * Context is not managed by global pool * Polish dist test * Polish dist test * Add enable_custom_autograd_function * Remove enable_custom_autograd_function from ctors * Add doc strings * Shorter code * Address comments * Add one empty line * revert a minor and not needed change * Address comments * Back to reference * Fix windows builds * Fix windows debug build fail to find "'python39_d.lib'" * fix mac build error * revert _to_contiguous change * add debugging tag for orttraining-cpu-ci * Fix the wrong PYTHON_LIBRARIES which is affected by PYTHON_LIBRARY given in build command * add debugging info * Fix the build in this case: PYTHON_LIBDIR: /opt/_internal/cpython-3.7.10/lib, PYTHON_EXECUTABLE: /opt/python/cp37-cp37m/bin/python3, PYTHON_MULTIARCH: x86_64-linux-gnu PYTHON_LIBRARY_PATH python3.7m * fix build error due to python lib not found * Fixes 1. Release PyObject's 2. Not useing deepcopy because we assume autograd.Function's non-tensor inputs are static (constants) so there should be no side effect after calling any autograd.Function multiple times. * Revert dtoc for decreasing refcnt * add debugging log * add debugging tag * Fix a small leak * Remove ONNX_FALLTHROUGH flag * debug tag * debug tag * fix builds * remove debug tag * fix build * fix builds * fix build * install python3 in centos, in case there is no libpython3.xm.so * build python so for redhat * add training cpu specific docker, build python so inside * revert build-cpython change * try fixing numpy include issue * install_deps after re-installing cpython * fix build && remove debug tag * install openssl before cpython * let's say: builds pass! * add build flag for torch iterop, only enable it when training+Python is enabled * skip ComputeBroadcastBackwardAxesDynamic for the shared inputs * fix build * add debug info for padgrad test * Fix builds * Split dlpack_converter into C++ and Python interfaces respecitively. Then different build use them as needed. * clean up the changes * fix addsubgradient builder * Fix builds * clean up * clean up * Address some comments. 1. Use pointer wraper to avoid calling Py_DECREF 2. Remove unregister_* functions 3. Allow repeated registration by skipping those with existing keys 4. Unregister context in PythonOpGrad * Fix over-released Py_Boolean Co-authored-by: Wei-Sheng Chin <wschin@outlook.com>
2021-06-07 20:01:21 +00:00
if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
onnxruntime_add_include_to_target(onnxruntime_framework Python::Module)
target_include_directories(onnxruntime_framework PRIVATE ${PROJECT_SOURCE_DIR}/external/dlpack/include)
training with custom autograd Functions (#7513) * Register Torch Custom autograd.Function * Add flag to supress pybind11 warning * Avoid unnecessary include in cmake * Add missing reference * Add getter for registerred functions * Format for making subsquent changes cleaner * Fix interop feature build failure * Forward pass, run PyOP on CPU EP * clean up the code * Fix build * Define new ops * refactor pyop - extract PyOpLibProxy class * Hacks to run example * implement the kernel compute func * add back PyOP for comparision experiments * debug info - thread id * refine the kernels * Polish code (cherry picked from commit 4ed606f9a0833592b325a4b40cf917e219845f6f) * Fix a the Tensor address mismatch in C++ side * PythonOpGrad compute * add distributed test case * refine test cases * get dist.get_rank() in Autograd forward pass * Add CUDA kernels * Store float, int, and tuple of them as PythonOp's attributes * Populate local changes * Fix bugs * PythonOp/PythonOpGrad CUDA kernels * Support non-tensor inputs * Single GPU FP16 Run Pass (cherry picked from commit e539989e91e18ee997900292d3493b97d3eafa8a) * Fix segement * add basic test cases * Save progress * fix gradient builder for a Add op who have same inputs * add test cases for auto grad fallback feature * fix ref cnt issue. add thread id for debugging * POC: remove interface class * Remove interface classes * Clean a bit * Coarse-grained clean up after rebase master * reset pyop and language_interop_ops to latest master * Fix missing part during merge * re-structure torch related language interop files * Fix build * Fix tests and build * Fix build and basic unit tests * Fix most of uts * remove unnecessary import * clean up and fix build when enabling language_interop_ops * Fix single-GPU UTs * Move runner register into ORT package * Update dist UTs to new style * Also fix distributed UTs and leaf gradient problem * Static generation for constant args * Move arg_positions_ to static field * Rename some functions * Move arg ceration into a function * Clean output logic in PythonOp * Move PythonOp's ctor * Revise PythonOpGrad * Fix "ORT only supports contiguous tensor for now" for inputs * Fix evaulation mode error, add test & clean up * clean up codes * Fix issues introduced by recent master change (enabled symbolic shape infer) * automatically register forward/backward function pointers && clean up * Fix multi-output case * Add a test back * fix build and clean up * RAII for function params PyObject * Use new exporter * Clean full name in new exporter * Fix UTs * Format a file * Add "inplace" back Remove a legacy comment * Refine TorchProxy 1. Make TorchProxy a formal singleton class. 2. Remove unused Scope class. 3. Simplify the call to Forward and Backward. The two functions now automatically acquire and release GIL state, so user doesn't need any GIL-related calls. * Format * Add lock to avoid racing condition when registering Python objs * Fix Python call param ref issues && Add RefcountTracker for debug build && Clean up * clean up print * Resolve part of comments && clean up * Fix a potential bug * track pyobject consistently * move kernels to cpu provider as base class * Refactor - 1. Extract PythonOpBase/PythonOpGradBase 2. Implement CPU kernels 3. Test coverage for CPU kernels * Refine register code * Add a missing macro * Release python call result objects with PythonObjectPtr && Add UnRegisterContext && Track PyObject for Debugging && Clena up * Fix random segfault issue - relasing a wrong ctx pointer for inplace cases * put ref count in debug macro * Move GIL out * Refine tests * Fix memory leak issue && forward output lifecycle issue: 1. Unregister the OrtValue PythonObject. Currently, the OrtValue shared same buffer with PythonOp/PythonOpGrad's output. So after those kernels outputs are released, the "leaked" OrtValue caused the shared buffer cannot be released. 2. According PyTorch forward+backward execution. The forward outputs (e.g. torch tensors) maintains the context/saved variables/dirty inputs, etc, which are used for backward execution, so its life should be after the backward runs. This change added such a depencencies between PythonOpGrad on PythonOp. * Move dlpack->ortvalue into C++ to avoid temp object registration * Fix the over released Py_False/Py_True && refine tests * Clean up unused functions * Always assume the first forward output is context so we don't need to test unused cases. * Fix a memory leak * move-copy unique_ptr & avoid C-style casting * Use inplace attribute to determine if input tensors are copied * Move DlpackCapsuleDestructor's to a common place * Thread-safe TorchProxy * Use OrtValue instead of OrtValue* * Only keep checks for Debug build * Wrap some long line per comment * onnx_export_type --> kwargs * Use requires_grads to create PythonOpGrad's inputs * add missing files during master merge * Fix build issue after merge * Address two comments. 1. Internalize DlpackCapsuleDestructor 2. Change "(" to "]" for describing closed interval. * Address some comments. 1. "override" -> "overwrite" to avoid using reserved keyword. 2. Call DLPack's helper to create OrtValue for avoiding repeated code. * Address comments. 1. Pass std::mutex to registeration helpers so their callers don't have to lock the mutex expclicitly. 2. Rename "func_context_pool_mutex_" to "mutex_". This mutex is the global mutex for OrtTorchFunctionPool. * Add bridging code to make cuda kernels work with merged master * put debue macro check within RefCountTracker && use default logger for debug info && remove useless ortvalue_ptr interface && typos && revert unncessary blank line changes * fix some comments * Resolve more comments * Capitalize a word * use unique_ptr instead of ObjectPointer for PyObject management && add converntion * Support symbolic shape * Remove unused variable * fix build * Enable function registration for training only && rectify ToDlpack/FromDlpack merge with master. * Don't add context for non-PythonOp opeartors (for example AtenOp) * Fix build error * Polish frontend part. 1. Avoid adding kwargs to ORTModule's ctor 2. Use onnx_export_type rather than kwargs for type safty 3. Fix some build bugs. * Resolve simpler comments * Resolve export related comments * sync master && fix tests && fix non-training build error * Fix build errors * add target link lib * windows build error * Fix orttraining-linux-ci build * disable autograd test && clean up * fix linux orttraining ci build * try fixing win build error * Revise append calls in runner * Enable custom function using a function * Rename to avoid using reservied keyword * Use list comprehension * Set ORT random seed in tests * Remove print code and fix ctx shape * [] -> list() * Move autograd.Function and nn.Module into corresponding functions * Move test helpers * Polish dist test a bit. Tried move helpers to helper file but it causes a deadlock. * trying fix undefined reference * Context is not managed by global pool * Polish dist test * Polish dist test * Add enable_custom_autograd_function * Remove enable_custom_autograd_function from ctors * Add doc strings * Shorter code * Address comments * Add one empty line * revert a minor and not needed change * Address comments * Back to reference * Fix windows builds * Fix windows debug build fail to find "'python39_d.lib'" * fix mac build error * revert _to_contiguous change * add debugging tag for orttraining-cpu-ci * Fix the wrong PYTHON_LIBRARIES which is affected by PYTHON_LIBRARY given in build command * add debugging info * Fix the build in this case: PYTHON_LIBDIR: /opt/_internal/cpython-3.7.10/lib, PYTHON_EXECUTABLE: /opt/python/cp37-cp37m/bin/python3, PYTHON_MULTIARCH: x86_64-linux-gnu PYTHON_LIBRARY_PATH python3.7m * fix build error due to python lib not found * Fixes 1. Release PyObject's 2. Not useing deepcopy because we assume autograd.Function's non-tensor inputs are static (constants) so there should be no side effect after calling any autograd.Function multiple times. * Revert dtoc for decreasing refcnt * add debugging log * add debugging tag * Fix a small leak * Remove ONNX_FALLTHROUGH flag * debug tag * debug tag * fix builds * remove debug tag * fix build * fix builds * fix build * install python3 in centos, in case there is no libpython3.xm.so * build python so for redhat * add training cpu specific docker, build python so inside * revert build-cpython change * try fixing numpy include issue * install_deps after re-installing cpython * fix build && remove debug tag * install openssl before cpython * let's say: builds pass! * add build flag for torch iterop, only enable it when training+Python is enabled * skip ComputeBroadcastBackwardAxesDynamic for the shared inputs * fix build * add debug info for padgrad test * Fix builds * Split dlpack_converter into C++ and Python interfaces respecitively. Then different build use them as needed. * clean up the changes * fix addsubgradient builder * Fix builds * clean up * clean up * Address some comments. 1. Use pointer wraper to avoid calling Py_DECREF 2. Remove unregister_* functions 3. Allow repeated registration by skipping those with existing keys 4. Unregister context in PythonOpGrad * Fix over-released Py_Boolean Co-authored-by: Wei-Sheng Chin <wschin@outlook.com>
2021-06-07 20:01:21 +00:00
endif()
if (onnxruntime_USE_NCCL OR onnxruntime_USE_MPI)
target_include_directories(onnxruntime_framework PUBLIC ${MPI_CXX_INCLUDE_DIRS})
endif()
endif()
if (onnxruntime_ENABLE_ATEN)
# DLPack is a header-only dependency
target_compile_definitions(onnxruntime_framework PRIVATE ENABLE_ATEN)
set(DLPACK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/dlpack/include)
target_include_directories(onnxruntime_framework PRIVATE ${DLPACK_INCLUDE_DIR})
endif()
Update manylinux build scripts and GPU CUDA version from 11.0 to 11.1 (#7632) 1. Update manylinux build scripts. This will add [PEP600](https://www.python.org/dev/peps/pep-0600/)(manylinux2 tags) support. numpy has adopted this new feature, we should do the same. The old build script files were copied from https://github.com/pypa/manylinux, but they has been deleted and replaced in the upstream repo. The manylinux repo doesn't have a manylinux2014 branch anymore. So I'm removing the obsolete code, sync the files with the latest master. 2. Update GPU CUDA version from 11.0 to 11.1(after a discussion with PMs). 3. Delete tools/ci_build/github/linux/docker/Dockerfile.manylinux2014_cuda10_2. (Merged the content to tools/ci_build/github/linux/docker/Dockerfile.manylinux2014_cuda11) 4. Modernize the cmake code of how to locate python devel files. It was suggested in https://github.com/onnx/onnx/pull/1631 . 5. Remove `onnxruntime_MSVC_STATIC_RUNTIME` and `onnxruntime_GCC_STATIC_CPP_RUNTIME` build options. Now cmake has builtin support for it. Starting from cmake 3.15, we can use `CMAKE_MSVC_RUNTIME_LIBRARY` cmake variable to choose which MSVC runtime library we want to use. 6. Update Ubuntu docker images that used in our CI build from Ubuntu 18.04 to Ubuntu 20.04. 7. Update GCC version in CUDA 11.1 pipelines from 8.x to 9.3.1 8. Split Linux GPU CI pipeline to two jobs: build the code on a CPU machine then run the tests on another GPU machines. In the past we didn't test our python packages. We only tested the pre-packed files. So we didn't catch the rpath issue in CI build. 9. Add a CentOS machine pool and test our Linux GPU build on real CentOS machines. 10. Rework ARM64 Linux GPU python packaging pipeline. Previously it uses cross-compiling therefore we must static link to C Runtime. But now have pluggable EP API and it doesn't support static link. So I changed to use qemu emulation instead. Now the build is 10x slower than before. But it is more extensible.
2021-06-03 06:36:49 +00:00
onnxruntime_add_include_to_target(onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers)
if (onnxruntime_USE_MIMALLOC)
target_link_libraries(onnxruntime_framework mimalloc-static)
endif()
if (onnxruntime_BUILD_WEBASSEMBLY)
target_link_libraries(onnxruntime_framework ${ABSEIL_LIBS})
endif()
2018-11-20 00:48:22 +00:00
set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
# need onnx to build to create headers that this project includes
add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES})
# In order to find the shared provider libraries we need to add the origin to the rpath for all executables we build
# For the shared onnxruntime library, this is set in onnxruntime.cmake through CMAKE_SHARED_LINKER_FLAGS
# But our test files don't use the shared library so this must be set for them.
# For Win32 it generates an absolute path for shared providers based on the location of the executable/onnxruntime.dll
build ONNXRuntime into WebAssembly (#6478) * Simplified version of WebAssembly support to keep most of existing data structures and add cmake using Ninja and emcmake * Clean up CMakeLists.txt and add an example to create and compute a kernel * Load a model from bytes and remove graph building steps * Add all cpu and contrib ops with mlas library * WebAssembly build with Onnxruntime C/CXX API * Use protobuf cmakefile directory instead of adding every necessary source file * Fix invalid output at example * add missing files * Change an example to use Teams model and support ort mobile format * add API for javascript * fix input releasing in _ort_run() * update API * Let onnxruntime cmake build WebAssembly with option '--wasm' * allow one-step building for wasm * Make build script working on Linux and MacOS * Fix broken build from Windows command * Enable unit test on building WebAssembly * Resolve comments * update build flags * wasm conv improvement from: 1) GemmV; 2) Depthwise direct convolution 3x3; 3) Direct convolution 3x3 * Cleaned mlas unittest. * use glob * update comments * Update baseline due to loss scale fix (#6948) * fix stream sync issue (#6954) * Enable type reduction in EyeLike, Mod, random.cc CPU kernels. (#6960) * Update EyeLike CPU kernel. * Update Mod CPU kernel. * Update Multinomial CPU kernel. * Slight improvement to Pad CPU kernel binary size. * Update RandomNormal[Like], RandomUniform[Like] CPU kernels. * Fix warning from setting multiple MSVC warning level options. (#6917) Fix warning from setting multiple MSVC warning level options. Replace an existing /Wn flag instead of always appending a new one. * MLAS: quantized GEMM update (#6916) Various updates to the int8_t GEMMs: 1) Add ARM64 udot kernel to take advantage of dot product instructions available in newer cores. Some models run 4x faster than the stock implementation we used before. 2) Refactor the x64 kernels to share common code for AVX2(u8u8/u8s8/avxvnni) vs AVX512(u8u8/u8s8/avx512vnni) to reduce binary size. 3) Extend kernels to support per-column zero points for matrix B. This is not currently wired to an operator. * Implement QLinearAveragePool with unit tests. (#6896) Implement QLinearAveragePool with unit tests. * Attention fusion detect num_heads and hidden_size automatically (#6920) * fixed type to experimental session constructor (#6950) * fixed type to experimental session constructor Co-authored-by: David Medine <david.medine@brainproducts.com> * Update onnxruntime_perf_test.exe to accept free dimension overrides (#6962) Co-authored-by: Ori Levari <orlevari@microsoft.com> * Fix possible fd leak in NNAPI (#6966) * Release buffers for prepacked tensors (#6820) Unsolved problems: 1. One test failure was caused by a bug in Cudnn rnn kernels, when they can allocate a buffer and partially initialize it, the garbage data near tail of the buffer caused problem in some of the hardware. To attack this problem in a broader sense, should we add code in our allocators, and during a memory fuzzing test, fill an allocated buffer with garbage before returning to the caller? 2. Prepacking is used more widely than we know. For instance, Cudnn rnn kernels also cache their weights. They mix several weight tensors together into a single buffer, and never touch the original weight tensor anymore. This is the same idea with pre-pack, but they didn't override the virtual function, and they never tried to release those weight tensors, leading to memory waste. It also seems to me that there are some other kernels have similar behavior. Wonder how much memory we can save if we try to cleanup those too. 3. Turning off memory pattern planning does increase memory fragmentation, leading to out of memory error in some training test cases. Perhaps we can revisit the idea of pushing kernels-creation stage earlier, and then during initializer deserialization, we only avoid tracing those that will be prepacked. * Enable type reduction for Range, ReverseSequence, ScatterND, Split, and Unique CPU kernels. (#6963) * add CI * fix test in ci * fix flags for nsync in wasm build * add copyright banner * fix wasm source glob * add missing exports * resolve comments * Perf gain by make packb wide to 4 from 16 on GEMM for WASM. Remove no need direct conv in previous perf tuning. * fix buildbreak introduced from latest master merge * fix buildbreak in mlasi.h * resolve all comments except MLAS * rewrite packb related 3 functions for WASM_SCALAR seperately rather than using #ifdef in each. and other changes according to PR feedback in mlas. * More complete scalar path in sgemm from Tracy. * Fix edge case handling in depthwise conv2d kernel 3x3. where: *) support input W==1 and H==1 *) recalc in accurate pad_right and pad_bottom *) support hidden pad_right == 2 or pad_bottom == 2 when W == 1 or H==1 and no pad left/top * Add more test coverage for conv depthwise from Tracy. Fix one typo according to PR. * resolve comments * replace typedef by using * do not use throw in OrtRun() * output error message Co-authored-by: Sunghoon <35605090+hanbitmyths@users.noreply.github.com> Co-authored-by: Lei Zhang <zhang.huanning@hotmail.com> Co-authored-by: Wei-Sheng Chin <wschin@outlook.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> Co-authored-by: Tracy Sharpe <42477615+tracysh@users.noreply.github.com> Co-authored-by: David Medine <david.eric.medine@gmail.com> Co-authored-by: David Medine <david.medine@brainproducts.com> Co-authored-by: Ori Levari <ori.levari@microsoft.com> Co-authored-by: Ori Levari <orlevari@microsoft.com> Co-authored-by: Guoyu Wang <62914304+gwang-msft@users.noreply.github.com> Co-authored-by: Chen Fu <chenfucs@gmail.com>
2021-04-06 23:18:10 +00:00
if (UNIX AND NOT APPLE AND NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_BUILD_WEBASSEMBLY)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
endif()
if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
find_package (SQLite3)
if (SQLITE3_FOUND)
include_directories(${SQLite3_INCLUDE_DIR})
target_link_libraries (onnxruntime_framework ${SQLite3_LIBRARY})
else()
message( FATAL_ERROR "Could not locate SQLite3 package." )
endif (SQLITE3_FOUND)
target_compile_definitions(onnxruntime_framework PRIVATE DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
endif()
if (WIN32)
target_compile_definitions(onnxruntime_framework PRIVATE _SCL_SECURE_NO_WARNINGS)
endif()
if (NOT onnxruntime_BUILD_SHARED_LIB)
install(TARGETS onnxruntime_framework
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
2018-11-23 04:56:43 +00:00
install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)