Skip to content

[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 7 commits into from
Feb 6, 2020

Conversation

jbrodman
Copy link
Contributor

This PR adds support for APIs that query properties of USM pointers.
In particular, this PR enables asking the allocation type of a USM pointer (host/device/shared) and the device against which it was allocated (if applicable).

Host allocations return host devices.
Host devices treat all pointers as host allocs.

This PR replaces #902

@jbrodman
Copy link
Contributor Author

I'm thinking this is a driver version issue again. Can we update the drivers to the latest for GPU?

///
/// @param ptr is the USM pointer to query
/// @param ctxt is the sycl context the ptr was allocated in
alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
Copy link
Contributor

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?

sycl::context Ctx1(sycl::cpu_selector), Ctx2(sycl::host_selector);
auto *Ptr = sycl::alloc_shared(Ctx1, ...);
auto Type = sycl::get_pointer_type(Ptr, Ctx2); // <- This returns alloc::host.

Can we add some diagnostic to catch such issues?

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 PI_CALL should fail if something like that goes wrong.

Copy link
Contributor

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.

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'm not sure I follow.

Copy link
Contributor

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.

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'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:

sycl::context Ctx1(sycl::gpu_selector), Ctx2(sycl::host_selector);
auto *Ptr = sycl::alloc_device(Ctx1, ...);
auto Type = sycl::get_pointer_type(Ptr, Ctx2); // <- This returns alloc::host.

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@romanovvlad romanovvlad self-assigned this Jan 19, 2020
Signed-off-by: James Brodman <[email protected]>
@jbrodman
Copy link
Contributor Author

jbrodman commented Feb 6, 2020

The test failures remain an "old" driver problem.

@romanovvlad
Copy link
Contributor

The test failures remain an "old" driver problem.

Probably we should disable them for some time as well.

@bader
Copy link
Contributor

bader commented Feb 6, 2020

+@tfzhu to fix "old driver" issue.

@jbrodman
Copy link
Contributor Author

jbrodman commented Feb 6, 2020

+@tfzhu to fix "old driver" issue.

Fails on 19.48.14977

Works on 20.01.15265+

Didn't have any in-between versions handy to try.

Windows, of course, will probably lag behind by even more.

@tfzhu
Copy link
Contributor

tfzhu commented Feb 6, 2020

+@tfzhu to fix "old driver" issue.

Working on uplift the RT version. Blocked by Windows lit test failure

@bader bader requested a review from romanovvlad February 6, 2020 13:20
@romanovvlad romanovvlad merged commit 926e38e into intel:sycl Feb 6, 2020
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.

4 participants