Skip to content

[SYCL] Plugin Interface: Single Call to Plugin to populate a Plugin Datastructure. #808

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

Closed

Conversation

garimagu
Copy link
Contributor

@garimagu garimagu commented Nov 8, 2019

[SYCL] Using a single call to Plugin, and populating a Plugin
datastructure with all function pointers. Extension to this will allow
us to bind multiple plugins.
[SYCL] Changing all the PI_CALL(RT:: or PI_CALL_RESULT(RT:: to
PI_CALL( or PI_CALL_RESULT( and other required changes.

Two last commits represent this change.
They are built over the previous PR#776, PR#798 .

@garimagu garimagu force-pushed the private/garimagu/pi_functiontable branch 2 times, most recently from 9f11c42 to 234ef82 Compare November 12, 2019 20:07
@garimagu
Copy link
Contributor Author

rebased and removed conflicts over PR#798.
Valid commits to be checked for this review are the last two commits.

@smaslov-intel smaslov-intel self-requested a review November 13, 2019 00:02
@smaslov-intel smaslov-intel self-assigned this Nov 13, 2019
@garimagu garimagu force-pushed the private/garimagu/pi_functiontable branch from 234ef82 to 708fc25 Compare November 15, 2019 02:31
@garimagu
Copy link
Contributor Author

garimagu commented Nov 15, 2019

Rebased over PR#798. and removed conflicts after merge of PR#776.
Valid commits are the last two commits.

@garimagu garimagu force-pushed the private/garimagu/pi_functiontable branch from 708fc25 to 5fb5ca1 Compare November 15, 2019 19:18
@garimagu garimagu requested a review from romanovvlad November 15, 2019 19:18
@garimagu
Copy link
Contributor Author

rebase.

@garimagu garimagu force-pushed the private/garimagu/pi_functiontable branch from 5fb5ca1 to ade27b1 Compare November 15, 2019 19:45
@garimagu
Copy link
Contributor Author

@smaslov-intel Please review.

datastructure with all function pointers. Extension to this will allow
us to bind multiple plugins.

Signed-off-by: Garima Gupta <[email protected]>
PI_CALL( or PI_CALL_RESULT( and other required changes.

Signed-off-by: Garima Gupta <[email protected]>
@garimagu garimagu force-pushed the private/garimagu/pi_functiontable branch from ade27b1 to bc2305d Compare November 19, 2019 00:02
@garimagu
Copy link
Contributor Author

rebase,clang-format and conflict resolution.

detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
sizeof(size_t), &BufSize, nullptr);
PI_CALL(piMemGetInfo, detail::pi::cast<detail::RT::PiMem>(MemObject),
CL_MEM_SIZE, sizeof(size_t), &BufSize, nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Only noticing this now - this somehow reminds me of Lisp 😄

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 have never used Lisp. Are you talking about use of comma after the api name?
I have the call interface changed in #843 . Do you think that works?
Maybe I can close this PR and merge the two PRs together.
Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry for the confusion and the extra work that I now caused - I meant "Lisp" as a positive thing 😿

Both approaches seem ok to me, the one in this PR seems to require less state in the trace class though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. The other way makes it more like calling a constructor and a functor on it.

// checks and writes the appropriate Function Pointers in
// PIFunctionTable.
const char PiVersion[4] = "1.1";
char PluginVersion[4] = "1.1"; // Plugin edits this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the fixed-sized array be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm.. I will a todo for this problem. I think this is a different problem to be resolved at a later point.

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 have added a TODO like below:
// TODO: Work on version fields and their handshaking mechanism.
// Some choices are:
// - Use of integers to keep major and minor version.
// - Keeping char* Versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in commit # 5 in PR 843

// TODO: Remove the 'OclPtr' extension used with the PI_APIs.
// Forward calls to OpenCL RT.
pi_result piPluginInit(pi_plugin *PluginInit) {
strcpy(PluginInit->PluginVersion, SupportedVersion);
Copy link
Contributor

Choose a reason for hiding this comment

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

As the version array is of fixed size the use of strncpy would be safer here.

Wondering though if it would be ok to make PluginInit->PluginVersion a const char* to point to the version string literal in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm..
I thought keeping all memory allocation and destruction in Plugin Interface will be a better idea. The library is loaded and it populates the fields.
I will take the focus off the version discussion and add a TODO for future.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean it, if the plugin cpp file defines the version as a string literal, then piPluginInit could just point PluginInit->PluginVersion to the string literal. No copying required and therefore no memory management.

There might be intricacies with the plugin unloading though which could leave a dangling pointer but my guess is that an unloaded plugin means that most SYCL calls become unsafe anyway.

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 will add a TODO. I can create a separate patch for the version discussion and changes. It will help segregate this discussion and keep the progress going.

pi_result piPluginInit(pi_plugin *PluginInit) {
strcpy(PluginInit->PluginVersion, SupportedVersion);
int CompareVersions = strcmp(PluginInit->PiVersion, SupportedVersion);
if (CompareVersions < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this comparison fails we already changed the PluginInit->PluginVersion. Should we move the comparison before the version is set in the plugin?

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. That was the intention I initially had. For the Plugin Interface to know that the plugin supported some other Version and maybe take an action for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that commit not pushed yet as I cannot see a change in the 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 is their in 4ce1cc4.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! 👍


decltype(::piPluginInit) *PluginInitializeFunction = (decltype(
&::piPluginInit))(getOsLibraryFuncAddress(Library, "piPluginInit"));
int err = PluginInitializeFunction(&PluginInformation);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would implement the init function to not affect the argument if an error occurs. If we need/want that at least the plugin version is set - even on an error - then please document this required behavior.

Though I would prefer to not access the argument if an error is returned in the code below.

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.

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 have removed piPluginInit function to edit the PluginInformation structure when an error occurs.

@@ -74,18 +78,21 @@ void *loadPlugin(const std::string &PluginPath) {
// needs to setup infrastructure to route PI_CALLs to the appropriate plugins.
// Currently, we bind to a singe plugin.
bool bindPlugin(void *Library) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure about the calling-sites of this though passing an explicit plugin argument in would be clearer instead of changing a global variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. I think we will have to do that once the plugin data structure becomes a part of a sycl object.

Copy link
Contributor Author

@garimagu garimagu left a comment

Choose a reason for hiding this comment

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

Added the changes in commit 5 of PR#843.

detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
sizeof(size_t), &BufSize, nullptr);
PI_CALL(piMemGetInfo, detail::pi::cast<detail::RT::PiMem>(MemObject),
CL_MEM_SIZE, sizeof(size_t), &BufSize, nullptr);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. The other way makes it more like calling a constructor and a functor on it.

// checks and writes the appropriate Function Pointers in
// PIFunctionTable.
const char PiVersion[4] = "1.1";
char PluginVersion[4] = "1.1"; // Plugin edits 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.

Hmmm.. I will a todo for this problem. I think this is a different problem to be resolved at a later point.

// TODO: Remove the 'OclPtr' extension used with the PI_APIs.
// Forward calls to OpenCL RT.
pi_result piPluginInit(pi_plugin *PluginInit) {
strcpy(PluginInit->PluginVersion, SupportedVersion);
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 will add a TODO. I can create a separate patch for the version discussion and changes. It will help segregate this discussion and keep the progress going.

pi_result piPluginInit(pi_plugin *PluginInit) {
strcpy(PluginInit->PluginVersion, SupportedVersion);
int CompareVersions = strcmp(PluginInit->PiVersion, SupportedVersion);
if (CompareVersions < 0) {
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. That was the intention I initially had. For the Plugin Interface to know that the plugin supported some other Version and maybe take an action for it.

pi_result piPluginInit(pi_plugin *PluginInit) {
strcpy(PluginInit->PluginVersion, SupportedVersion);
int CompareVersions = strcmp(PluginInit->PiVersion, SupportedVersion);
if (CompareVersions < 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it now.

@@ -74,18 +78,21 @@ void *loadPlugin(const std::string &PluginPath) {
// needs to setup infrastructure to route PI_CALLs to the appropriate plugins.
// Currently, we bind to a singe plugin.
bool bindPlugin(void *Library) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. I think we will have to do that once the plugin data structure becomes a part of a sycl object.


decltype(::piPluginInit) *PluginInitializeFunction = (decltype(
&::piPluginInit))(getOsLibraryFuncAddress(Library, "piPluginInit"));
int err = PluginInitializeFunction(&PluginInformation);
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.

@garimagu
Copy link
Contributor Author

@bjoernknafla
Let me know if you are ok if I close this PR.
The review #843 includes this change, and you can review it there further. I have taken care of your comments in the 5th commit in the review.
Also, regarding the version comparison and on how to keep it, we can have a separate commit to have it better designed. Let me know if you think it is fine.

Copy link
Contributor

@bjoernknafla bjoernknafla left a comment

Choose a reason for hiding this comment

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

Not seeing some of the TODOs in the code - probably missing pushing the commits, otherwise ok.

@garimagu
Copy link
Contributor Author

Not seeing some of the TODOs in the code - probably missing pushing the commits, otherwise ok.

I have incorporated them in the 5th commit of #843 . I should have given the link earlier.
4ce1cc4

@garimagu
Copy link
Contributor Author

This PR is a part of PR #843 .
Closing this to avoid duplicated review effort.

@garimagu garimagu closed this Nov 21, 2019
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.

3 participants