-
Notifications
You must be signed in to change notification settings - Fork 789
[SYCL] Improve mock PI plugin #7129
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] Improve mock PI plugin #7129
Conversation
The patch adds more logic to default redefinitions of PI APIs: 1. Allocate, refcount and deallocated various handles 2. Handle sub-buffer creation Also the patch adds support for adding PI functions to be called in addition (before or after) to the original function. This allows intersecting PI API calls for introspection while still allowing original function take care of handles. Or add some post processing of the returned values.
I love the idea of what we are doing here, but I'm not sure about how. However, please consider the below just as an alternative idea and not a request to make any changes. What if do more functional programming style here? Pseudocode:
or
This is likely slower in run time but I think that for testing infrastructure the tradeoff between easier maintainability/speed could be more biased towards the former. |
We could do something like that https://godbolt.org/z/T3oPbvKv8 . |
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 is super good! It will make it a lot easier to for example add specific info queries without having to redefine the entire info query function. Few comments.
@@ -130,6 +221,10 @@ class PiMock { | |||
PiMock(const PiMock &) = delete; | |||
PiMock &operator=(const PiMock &) = delete; | |||
~PiMock() { | |||
// Since the plugin relies on the global vars to store function pointers we | |||
// need to reset them for the new PiMock plugin instance | |||
// TODO: Make function pointers array for each PiMock instance? |
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 we would need that in case gtest ever decides to run tests in parallel. It may be enough to make the arrays thread_local
. That might have problems when a specific test is multi-threaded though.
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.
As an alternative we could:
- Create a global map
pi_platfrom
to array of function pointers map - create a global map from every handle(
void*)
topi_platform
- update the map(from
2)
) any time we create or remove a handle in the mock functions - in the proxy function, for a given handle find a corresponding
pi_platform
using the map from2)
- Using
pi_platform
find an array of function pointers from1)
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 that might be a good solution to the problem. We could even simplify the map (2) a little, defining a space for which a given platform can use, e.g. the first platform can create handles 0-10000, the next can use 10000-20000, etc. Biggest problem is if someone overwrites the behavior of a function returning handles and return something not in the allocated range/in the map.
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!
@romanovvlad, please see post commit issue: https://github.com/intel/llvm/actions/runs/3322958425/jobs/5492696367 |
There are actually few separate issues in different configurations. Probably it would be the best to revert at this point and reapply as soon as addressed. |
This reverts commit 1f35a39.
The patch adds more logic to default redefinitions of PI APIs:
Also the patch adds support for adding PI functions to be called in addition (before or after) to the original function. This allows intercepting PI API calls for introspection while still allowing original function take care of handles. Or add some post processing of the returned values.