-
Notifications
You must be signed in to change notification settings - Fork 749
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
[SYCL] Unload libraries in jit_compiler and kernel_compiler_opencl destructors #16517
base: sycl
Are you sure you want to change the base?
[SYCL] Unload libraries in jit_compiler and kernel_compiler_opencl destructors #16517
Conversation
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
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.
LGTM. Would it be possible to also add a test covering these changes?
both objects are static so not sure if it is possible to track with UT |
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.
Makes sense, but please add a PR description and consider updating the title, which is a bit misleading because jit_compiler
doesn't load ocloc
but rather the sycl-jit
library.
sycl/source/detail/jit_compiler.hpp
Outdated
@@ -98,6 +98,7 @@ class jit_compiler { | |||
CompileSYCLFuncT CompileSYCLHandle = nullptr; | |||
ResetConfigFuncT ResetConfigHandle = nullptr; | |||
AddToConfigFuncT AddToConfigHandle = nullptr; | |||
void *MLibraryHandle = nullptr; |
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.
Could this be a unique pointer as well, reusing the custom deleter from the newly-added unique pointer in jit_compiler
's constructor? Then we wouldn't need to duplicate the unload logic in the destructor.
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.
Nit: The other members here don't carry the M
prefix.
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.
done in c86ef55
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.
title is slightly updated too.
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
sycl/source/detail/jit_compiler.cpp
Outdated
jit_compiler::~jit_compiler() {} | ||
|
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.
No longer needed.
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.
done in b326642
sycl/source/detail/jit_compiler.hpp
Outdated
~jit_compiler() = default; | ||
~jit_compiler(); |
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.
No longer needed.
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.
done in b326642
bool Available; | ||
bool Available = false; |
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.
Is this necessary?
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 just noticed that there is no pre initialization for this var, I think that code analyzer could report it
sycl/source/detail/jit_compiler.cpp
Outdated
@@ -23,29 +23,38 @@ namespace sycl { | |||
inline namespace _V1 { | |||
namespace detail { | |||
|
|||
static std::function<void(void *)> CustomDeleterForLibHandle = |
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.
This can be a normal function, maybe just declare it as a static member of jit_compiler
so you can use it for decltype
.
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.
done in b326642
static inline void printPerformanceWarning(const std::string &Message) { | ||
if (detail::SYCLConfig<detail::SYCL_RT_WARNING_LEVEL>::get() > 0) { | ||
std::cerr << "WARNING: " << Message << "\n"; | ||
} | ||
} | ||
|
||
jit_compiler::jit_compiler() { | ||
jit_compiler::jit_compiler() | ||
: LibraryHandle(nullptr, CustomDeleterForLibHandle) { |
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.
Is this initialisation necessary?
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.
yes, it is. I should pass custom deleter function to unique_ptr constructor.
sycl/source/detail/jit_compiler.hpp
Outdated
@@ -98,6 +99,7 @@ class jit_compiler { | |||
CompileSYCLFuncT CompileSYCLHandle = nullptr; | |||
ResetConfigFuncT ResetConfigHandle = nullptr; | |||
AddToConfigFuncT AddToConfigHandle = nullptr; | |||
std::unique_ptr<void, std::function<void(void *)>> LibraryHandle; |
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.
Suggestion: Introduce a type alias above for this.
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 could but I don't think that it is necessary, all types are simple and the structure is clear.
Please let me know if you have any concerns.
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.
Can we simply have this as a void *
and handle resource freeing in the destructor? I think this overcomplicates code.
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.
It was done in the first version of this PR and changed to unique_ptr according to @jopperm code-review comment. Not sure what should I do then.
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.
LGTM then!
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
Fixes memory leaks in jit_compiler and kernel_compiler_opencl classes.
Libraries loaded to provide compilation utils have to be released.