-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Enable proper override using MIMalloc #9944
Conversation
….0.3 Refactor for a universal ifdef
Do we've a plan for Linux? I suppose it's going to be a separate PR? In reply to: 987425400 |
Linux is supported via LD_PRELAOD mechanism although can be done statically as well. In reply to: 987425400 |
@@ -388,8 +388,7 @@ def parse_arguments(): | |||
"--use_vstest", action='store_true', | |||
help="Use use_vstest for running unitests.") | |||
parser.add_argument( | |||
"--use_mimalloc", default=['none'], | |||
choices=['none', 'stl', 'arena', 'all'], help="Use mimalloc.") | |||
"--use_mimalloc", action='store_true', help="Use mimalloc allocator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any internal teams that rely on any of these specific choices? May be the ones who introduced them in the first place? Might want to give them a headsup? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually checked. Nobody is using it currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone is building from source ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mimalloc is only available for building from source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so what if someone (3P) is building from source after each release ? They might find to their surprise that this option that existed previously doesn't exist anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no way to know about 3P usage. We can document this in the release notes since this might indeed break existing (if any) 3P workflows.
@@ -75,6 +75,14 @@ file(GLOB onnxruntime_common_src CONFIGURE_DEPENDS | |||
${onnxruntime_common_src_patterns} | |||
) | |||
|
|||
# Remove new/delete intercept. To deal with memory leaks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will memory leak detection be off by default? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed off line
#else | ||
int ret = mi_posix_memalign(&p, alignment, size); | ||
if (ret != 0) | ||
ORT_THROW_EX(std::bad_alloc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the other #if cases also throw std::bad_alloc? #Resolved
@@ -10,6 +10,7 @@ include_directories(${mimalloc_root_dir}/include) | |||
|
|||
option(MI_OVERRIDE "" OFF) | |||
option(MI_BUILD_TESTS "" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are lines 3-8 needed now ? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
Actually, the original override did not target Linux. So there are #ifdefs in the cmake. I have also not tested that. In reply to: 987450755 |
Yes, all new/deletes are overriden. In reply to: 987552314 |
Just curious: In the target model that this change is primarily intended for, are there any STL containers that are used a lot in Run() ? If there are, if we sub in the In reply to: 988208851 |
LGTM 👍 |
@@ -63,6 +63,11 @@ if (onnxruntime_ENABLE_TRAINING) | |||
target_include_directories(onnxruntime_framework PRIVATE ${DLPACK_INCLUDE_DIR}) | |||
endif() | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, after "onnxruntime_framework", you should add "PRIVATE" or "PUBLIC" keyword.
target_link_libraries(onnxruntime_framework PRIVATE mimalloc-static)
However, I suggest you add it to https://github.com/microsoft/onnxruntime/blob/master/cmake/CMakeLists.txt#L938 instead. To make sure they are in order. https://github.com/microsoft/onnxruntime/blob/master/docs/cmake_guideline.md#dont-call-target_link_libraries-on-static-libraries
[Enable proper mimalloc override](#9944) PR has fixed a number of issues with regards to building onnxruntime with mimalloc. This PR documents usage of mimalloc.
[Enable proper mimalloc override](#9944) PR has fixed a number of issues with regards to building onnxruntime with mimalloc. This PR documents usage of mimalloc.
Description:
This change enables users to build ORT with mimalloc memory allocator on Windows so the CPUAllocator and all new/deletes are served by mimalloc.
Motivation and Context
mimalloc has shown that gives considerable boost to performance over standard windows allocator.
Note: python API has a problem on shutdown garbage collection in pybind11.