-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL][USM] Add support for pointer query APIs #1016
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
29b34f7
Initial commit of USM pointer queries
jbrodman 2b4cda2
Change how host device is selected.
jbrodman bd7142a
Add pointer query test
jbrodman 8ed0a4c
Style changes and return a device in context for host allocs
jbrodman a164b01
Remove spurious bump of ref count on devices.
jbrodman fa315d8
Fix comment and compile error.
jbrodman d93f16b
Only test on host until future driver update
jbrodman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// RUN: %clangxx -fsycl %s -o %t1.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out | ||
|
||
//==-------------- pointer_query.cpp - Pointer Query test ------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
int main() { | ||
int *array = nullptr; | ||
const int N = 4; | ||
queue q; | ||
auto dev = q.get_device(); | ||
auto ctxt = q.get_context(); | ||
|
||
if (!(dev.get_info<info::device::usm_device_allocations>() && | ||
dev.get_info<info::device::usm_shared_allocations>() && | ||
dev.get_info<info::device::usm_host_allocations>())) | ||
return 0; | ||
|
||
usm::alloc Kind; | ||
device D; | ||
|
||
// Test device allocs | ||
array = (int *)malloc_device(N * sizeof(int), q); | ||
if (array == nullptr) { | ||
return 1; | ||
} | ||
Kind = get_pointer_type(array, ctxt); | ||
if (ctxt.is_host()) { | ||
// for now, host device treats all allocations | ||
// as host allocations | ||
if (Kind != usm::alloc::host) { | ||
return 2; | ||
} | ||
} else { | ||
if (Kind != usm::alloc::device) { | ||
return 3; | ||
} | ||
} | ||
D = get_pointer_device(array, ctxt); | ||
if (D != dev) { | ||
return 4; | ||
} | ||
free(array, ctxt); | ||
|
||
// Test shared allocs | ||
array = (int *)malloc_shared(N * sizeof(int), q); | ||
if (array == nullptr) { | ||
return 5; | ||
} | ||
Kind = get_pointer_type(array, ctxt); | ||
if (ctxt.is_host()) { | ||
// for now, host device treats all allocations | ||
// as host allocations | ||
if (Kind != usm::alloc::host) { | ||
return 6; | ||
} | ||
} else { | ||
if (Kind != usm::alloc::shared) { | ||
return 7; | ||
} | ||
} | ||
D = get_pointer_device(array, ctxt); | ||
if (D != dev) { | ||
return 8; | ||
} | ||
free(array, ctxt); | ||
|
||
// Test host allocs | ||
array = (int *)malloc_host(N * sizeof(int), q); | ||
if (array == nullptr) { | ||
return 9; | ||
} | ||
Kind = get_pointer_type(array, ctxt); | ||
if (Kind != usm::alloc::host) { | ||
return 10; | ||
} | ||
D = get_pointer_device(array, ctxt); | ||
auto Devs = ctxt.get_devices(); | ||
auto result = std::find(Devs.begin(), Devs.end(), D); | ||
if (result == Devs.end()) { | ||
// Returned device was not in queried context | ||
return 11; | ||
} | ||
free(array, ctxt); | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if user mixes up context used for USM allocation and context passed to get_pointer_type function?
Can we add some diagnostic to catch such issues?
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 PI_CALL should fail if something like that goes 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.
In the example above get_pointer_type doesn't call PI.
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 I follow.
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 mean, the code snippet doesn't return any error, while being illegal because Ptr is allocated in the Ctx1 but get_pointer_type is called with Ctx2.
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 this can really be handled. In this case, I would expect it to just work as shared allocations work on the host and the host doesn't really care what context anything is in. CPU memory is CPU memory.
The trickier case is:
Trying to use Ptr on the host ought to crash the program or give garbage values. We would have to keep track of insane amounts of state to try to get a host device context to bail on this.
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 should invent some diagnostic, probably enabled if some option is set only.
People facing this issue in real code already.
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 if done as a separate patch.