-
Notifications
You must be signed in to change notification settings - Fork 2.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
[refactor] Make taichi/common self contained #2200
Conversation
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.
Sorry for the large change. This is mostly shuffling code around.
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.
Looks great to me!
Btw, do you expect the compilation/linking time to also improve after this series of refactoring, given we re-compile fewer headers? If that is the case, does it makes sense to set up a quantitative build time benchmark? (so that we can tell a more precise and quantitative story to future developers? Something like "after Ye's refactoring not only the code is more readable but also the compilation time is improved by 20%" :-)
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.
One more trap: the current build.py
file only copies the libtaichi_core.pyd
to the package. Before we release it may need fixing:
Lines 60 to 67 in dee35f4
if get_os_name() == 'linux': | |
shutil.copy('../build/libtaichi_core.so', 'taichi/lib/taichi_core.so') | |
elif get_os_name() == 'osx': | |
shutil.copy('../build/libtaichi_core.dylib', | |
'taichi/lib/taichi_core.so') | |
else: | |
shutil.copy('../runtimes/RelWithDebInfo/taichi_core.dll', | |
'taichi/lib/taichi_core.pyd') |
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.
Looks great to me!
@@ -0,0 +1,6 @@ | |||
#include "taichi/common/core.h" | |||
|
|||
namespace taichi { |
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.
Shall we write namespace taichi
as-is or use this one?
Line 154 in dee35f4
#define TI_NAMESPACE_BEGIN namespace taichi { |
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, I think both are fine. At some point we should do a batch change from TI_NAMESPACE_BEGIN
to namespace taichi {
anyway.. Do you have a preference?
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 I also prefer namespace taichi {
... It took me one more click in the IDE to know what TI_NAMESPACE_BEGIN
was.
Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
LOL, TBH I haven't really looked to much into the compilation duration problem in Taichi. To me it was slow but not unbearable. I think it's great to have a build perf benchmark, but maybe not that urgent? Also we should confirm whether the slowness comes from compilation (parallelizable) or linking (single-threaded), or both.. If the reprocessing of the headers is a major source of slowness, maybe we can try things like https://clang.llvm.org/docs/PCHInternals.html#using-precompiled-headers-with-clang. Anyhow, compilation optimization itself is a huge topic... :) |
Good point! But note that the newly added lib is what CMake calls an |
Sounds good. Improving compilation speed always makes development more enjoyable and make CI cost less but I agree with you that it is not urgent.
I see! I misunderstood. I thought an extra shared obj was created. |
Related issue = #2196
The goal of this PR is to make
taichi/common
self-contained and not depend on any other part of the codebase. There are a few problems before:Logger
's impl used to be intaichi/util
, this creates a circular include betweentaichi/common
andtaichi/util
.logging.cpp
gets moved totaichi/common
.Logger
itself is coupled with both signal handlers andpybind11
.Create a
HackedSignalHandler
, which takes care of these procedures in its constructor. We then instantiate a globalHackedSignalHandler
instead. The name "hacked" is mostly because I'm not sure if this is the best practice to invoke some initialization code in a shared library. There is a__attribute((constructor))
attribute, but it's a GCC specific extension..logger
, and switches to the singletonLogger::get_instance()
. This is because global variables in different translation units are unspecified.[Click here for the format server]