-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Clear extensions functions cache upon context release #5282
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] Clear extensions functions cache upon context release #5282
Conversation
s-kanaev
commented
Jan 11, 2022
This is to eliminate reuse of invalid cached values after context being released. Signed-off-by: Sergey Kanaev <[email protected]>
c7d36c3
to
68811ba
Compare
Signed-off-by: Sergey Kanaev <[email protected]>
68811ba
to
6878a50
Compare
/summary:run |
The test is going to be disabled until intel/llvm#5282 is merged Signed-off-by: Sergey Kanaev <[email protected]>
Signed-off-by: Sergey Kanaev <[email protected]>
/summary:run |
The test is going to be disabled until intel/llvm#5282 is merged Signed-off-by: Sergey Kanaev <[email protected]>
Signed-off-by: Sergey Kanaev <[email protected]>
Signed-off-by: Sergey Kanaev <[email protected]>
…on-context-release
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.
New approach LGTM. Just have some minor suggestions.
Co-authored-by: Steffen Larsen <[email protected]>
Signed-off-by: Sergey Kanaev <[email protected]>
/summary:run |
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 stuff! Have a 👍 .
The failure on HIP AMD isn't relevant to this patch and is resolved by XFAIL-ing the tests int intel/llvm-test-suite#740 |
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've made a few style comments as I'm not an expert in this code and can't review design solution.
I'll let @romanovvlad to follow-up with that PR.
#undef _EXT_FUNCTION_COMMON | ||
} // namespace detail | ||
|
||
struct ExtFuncsCachesT { |
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.
Why plural form?
struct ExtFuncsCachesT { | |
struct ExtFuncsCacheT { |
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's plural because each context has it's own cache.
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 think it would be reasonable to call the whole map a cache instead of ExtFuncsPerContextT instances.
@@ -1397,6 +1480,8 @@ pi_result piPluginInit(pi_plugin *PluginInit) { | |||
// PI interface supports higher version or the same version. | |||
strncpy(PluginInit->PluginVersion, SupportedVersion, 4); | |||
|
|||
ExtFuncsCaches = new ExtFuncsCachesT; |
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.
Should we use a smart pointer? https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r3-a-raw-pointer-a-t-is-non-owning
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 might be an option if the following drawback is resolved. Smart pointer (both shared_ptr
and unique_ptr
) are not trivially destructible. Having a smart pointer here may lead to potential mem leak or anything else related to order of destructors calls.
Probably, @alexbatashev has smth to comment here if I'm wrong.
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.
Having a smart pointer here may lead to potential mem leak or anything else related to order of destructors calls.
Could you clarify the scenario when "mem leak or anything else related to order of destructors calls" happen and how using a raw pointer solves the problems in such scenarios?
From POV, you can always call release
method when you call delete
for a raw pointer and have additional mem leak protection for the cases when delete
is not called.
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.
The mem-leak and destructor ordering I refer here are not related to the owned object, i.e. cache, but to the smart pointer itself. shared_ptr
has two atomic counters. My blind guess is they're in heap. Both unique_ptr
and shared_ptr
have a 'complex' d-tor which has to check if the pointer owns the object.
Sure thing. When smart pointer is used I'll put call to release
method in piTearDown
. Bearing this in mind, is there any real need for smart pointer as I won't use its features?
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.
If we change the type of ExtFuncsCaches
to a unique_ptr
, we may have a problem since unique_ptr
can be destructed(as a regular global var) earlier than the latest call to an API which uses this var.
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.
How is that possible? Isn't calling functions from unloaded sharing library is UB?
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.
How is that possible? Isn't calling functions from unloaded sharing library is UB?
A global object can be destroyed earlier then a library is unloaded.
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.
Right, so I expected that plug-in has a single global object managing the lifetime of plug-in data ("plug-in context") and after this global object is destroyed, there can't be any "calls to an API which uses this var".
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 can't be any "calls to an API which uses this var".
How this can be guaranteed?
/verify with intel/llvm-test-suite#745 |
// if cached that extension is not available return nullptr and | ||
// PI_INVALID_VALUE | ||
*fptr = F; | ||
return F ? PI_SUCCESS : PI_INVALID_VALUE; | ||
*fptr = FuncInitialized.first; |
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.
Not sure we get a lot from having lazy initialization for these function pointers. Suggest moving all the initialization to piContextCreate
. This should simplify the logic.
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.
Per what was discussed with @steffenlarsen , the main drawback of constant (as opposed to lazy) init in piContextCreate
is that use-cases that create lots of contexts without using extensions will be impacted on performance. I reckon it's only synthetic cases, but still...
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'm OK with leaving as is. But still think that if an application creates lots of context this initialization will be that last thing we should worry about. Also this would make "common" case faster and code more simpler because less mutexes and checks should be needed.
@@ -1397,6 +1480,8 @@ pi_result piPluginInit(pi_plugin *PluginInit) { | |||
// PI interface supports higher version or the same version. | |||
strncpy(PluginInit->PluginVersion, SupportedVersion, 4); | |||
|
|||
ExtFuncsCaches = new ExtFuncsCachesT; |
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.
If we change the type of ExtFuncsCaches
to a unique_ptr
, we may have a problem since unique_ptr
can be destructed(as a regular global var) earlier than the latest call to an API which uses this var.
…on-context-release
Signed-off-by: Sergey Kanaev <[email protected]>
/verify with intel/llvm-test-suite#745 |
The test is going to be disabled until intel#5282 is merged Signed-off-by: Sergey Kanaev <[email protected]>