Skip to content
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

Open
wants to merge 5 commits into
base: sycl
Choose a base branch
from

Conversation

KseniyaTikhomirova
Copy link
Contributor

@KseniyaTikhomirova KseniyaTikhomirova commented Jan 3, 2025

Fixes memory leaks in jit_compiler and kernel_compiler_opencl classes.
Libraries loaded to provide compilation utils have to be released.

Signed-off-by: Tikhomirova, Kseniya <[email protected]>
@KseniyaTikhomirova KseniyaTikhomirova changed the title Fix leak in online compiler [SYCL] Unload ocloc in jit_compiler and kernel_compiler_opencl Jan 3, 2025
@KseniyaTikhomirova KseniyaTikhomirova marked this pull request as ready for review January 3, 2025 16:17
@KseniyaTikhomirova KseniyaTikhomirova requested review from a team as code owners January 3, 2025 16:17
Copy link
Contributor

@uditagarwal97 uditagarwal97 left a 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?

@KseniyaTikhomirova
Copy link
Contributor Author

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

Copy link
Contributor

@jopperm jopperm left a 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.

@@ -98,6 +98,7 @@ class jit_compiler {
CompileSYCLFuncT CompileSYCLHandle = nullptr;
ResetConfigFuncT ResetConfigHandle = nullptr;
AddToConfigFuncT AddToConfigHandle = nullptr;
void *MLibraryHandle = nullptr;
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in c86ef55

Copy link
Contributor Author

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]>
@KseniyaTikhomirova KseniyaTikhomirova changed the title [SYCL] Unload ocloc in jit_compiler and kernel_compiler_opencl [SYCL] Unload libraries in jit_compiler and kernel_compiler_opencl destructors Jan 7, 2025
Comment on lines 107 to 108
jit_compiler::~jit_compiler() {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in b326642

Comment on lines 63 to 64
~jit_compiler() = default;
~jit_compiler();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in b326642

Comment on lines -83 to +84
bool Available;
bool Available = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Contributor Author

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

@@ -23,29 +23,38 @@ namespace sycl {
inline namespace _V1 {
namespace detail {

static std::function<void(void *)> CustomDeleterForLibHandle =
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this initialisation necessary?

Copy link
Contributor Author

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.

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants