Skip to content

[SYCL] Fixing device check in program link constructor #74

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

Merged
merged 1 commit into from
Apr 18, 2019

Conversation

schittir
Copy link
Contributor

This patch gets sycl devices via context in program
interoperability constructor and
sorts devices in program link constructor to check that
all the programs in the list use the same devices

Signed-off-by: Sindhu Chittireddy [email protected]

std::map<cl_device_id, device> IdToDeviceMap;
for (auto &Dev : SyclContextDevices) {
IdToDeviceMap[Dev.get()] = Dev;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is not clear to me whether when you are calling sort_devices_by_cl_device_id() you have gone always through here. If so, since you are using std::map<cl_device_id, device>, if you are iterated on it it is already sorted by cl_device_id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The map is used only in the interoperability constructor, whereas the sorting_by_cl_device_id() for device check is called in the program link constructor. The programs being linked may or may not constructed through the interoperability constructor.

I don't know if std::sort is optimized for already sorted containers but I can add an if(!is_sorted(sortedDevices.begin(),sortedDevices.end()) check before calling the sort method. I wonder if it is it really important to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

No I do not think this micro-optimization is important.
But thank you for the clarification.
And since you have it at hand, feel free to add it as a comment somewhere.
Comments are super useful for reviewers and generally for any non write-only code. ;-)
Thanks.

@intel intel deleted a comment from schittir Apr 11, 2019
@intel intel deleted a comment from schittir Apr 11, 2019
romanovvlad
romanovvlad previously approved these changes Apr 17, 2019
// Returns underlying native device object (if any) w/o reference count
// modification. Caller must ensure the returned object lives on stack only.
// It can also be safely passed to the underlying native runtime API.
// Warning. Returned reference will be invalid if device_impl was destroyed.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little bit scared by reading these 2 lines at the same time...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of the first three lines is to explain the usage of the method and the responsibility of the user. The warning is intended to be scary and is consistent with other classes containing getHandleRef method.
The juxtaposition seems useful to me and is used in other classes too.

This patch gets sycl devices via context in program
interoperability constructor and
sorts devices in program link constructor to check that
all the programs in the list use the same devices

It also addresses the case where program is constructed
using only a subset of devices associated with sycl context
Signed-off-by: Sindhu Chittireddy <[email protected]>
@romanovvlad romanovvlad merged commit 1bedf88 into intel:sycl Apr 18, 2019
vladimirlaz pushed a commit to vladimirlaz/llvm that referenced this pull request Jun 21, 2020
  CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
vmaksimo added a commit to vmaksimo/llvm that referenced this pull request Oct 12, 2020
  CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp
vladimirlaz pushed a commit that referenced this pull request Mar 30, 2021
  CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Linux.cpp
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.

7 participants