-
Notifications
You must be signed in to change notification settings - Fork 935
accelerator: introduce compare_ipc_handles fnct #12352
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
accelerator: introduce compare_ipc_handles fnct #12352
Conversation
| int *pid_2 = (int *)&handle_2[pos]; | ||
|
|
||
| /* Note: using pid_1 != pid_2 since we need to return 0 if identical */ | ||
| return (memcmp(handle_1, handle_2, 32) && (*pid_1 != *pid_2)); |
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 not sure about this - should it be memcmp(handle_1, handle_2, 32) || (*pid_1 != *pid_2) instead?
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 you might be right, I hate these brain twister. I will write down the decision matrix to check
| * and the process ID for comparison. | ||
| * We definitily need to exclude the offset component in the comparison. | ||
| */ | ||
| int pos = 32 + 2*sizeof(size_t); |
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 static const int POS = (int) 32 + 2 * sizeof(size_t); - maybe also need a const for 32.
5dc1328 to
9251cd5
Compare
|
@wenduwan thank you for your review, can you please have another look? I think I incorporated both of your comments. |
| int *pid_1 = (int *)&handle_1[pos]; | ||
| int *pid_2 = (int *)&handle_2[pos]; | ||
|
|
||
| return (memcmp(handle_1, handle_2, 32) + (*pid_1 == *pid_2 ? 0 : 1)); |
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.
Ah this might not work because -1 + 1 = 0
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.
:-( you are unfortunately right again. Thanks for catching it!
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.
A more readable way can be
...
if (*pid_1 != *pid_2) return *pid_1 > *pid_2 ? 1 : -1;
return memcmp(handle_1, handle_2, 32);
...
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.
that is actually a good idea, I made just one minor change, thanks!
comparing ipc handles might not be always just a memcmp of the two handles. Introduce an abstraction for this functionality. Use the memcmp function that was used so far in the cuda and ze component, but use only certain parts of the ipc handle in rocm. Signed-off-by: Edgar Gabriel <[email protected]>
9251cd5 to
4002fbc
Compare
comparing ipc handles might not be always just a memcmp of the two handles. Introduce an abstraction for this functionality. Use the memcmp function that was used so far in the cuda and ze component, but use only certain parts of the ipc handle in rocm.