Skip to content
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

Add capsules #350

Merged
merged 2 commits into from
Apr 2, 2021
Merged

Add capsules #350

merged 2 commits into from
Apr 2, 2021

Conversation

oleksandr-pavlyk
Copy link
Collaborator

@oleksandr-pavlyk oleksandr-pavlyk commented Apr 1, 2021

SyclQueue and SyclContext can now be constructed from named capsule objects, with expected names being "SyclContextRef" and "SyclQueueRef".

Classes also acquire a method _get_capsule(sef) to construct a capsule from the instance.

Examples:

In [1]: import dpctl

In [2]: q = dpctl.SyclQueue("level_zero:gpu")

In [3]: cap = q._get_capsule()

In [4]: q1 = dpctl.SyclQueue(cap)

In [5]: q1.equals(q)
Out[5]: True

In [6]: cap
Out[6]: <capsule object "used_SyclQueueRef" at 0x7f0e651689f0>

In [7]: quit
In [1]: import dpctl

In [2]: c = dpctl.SyclContext("gpu")

In [3]: c
Out[3]: <dpctl.SyclContext at 0x7fc1123818d0>

In [4]: caps = c._get_capsule()

In [5]: caps
Out[5]: <capsule object "SyclContextRef" at 0x7fc0eb1acb70>

In [6]: c_copy = dpctl.SyclContext(caps)

In [7]: c.equals(c_copy)
Out[7]: True

@oleksandr-pavlyk
Copy link
Collaborator Author

It builds! Let's merge it :)

SyclQueue instance implements _get_capsule() method that produces
"SyclQueueRef" named capsule

This capsule can be used to construct a new instance of SyclQueue,
doing so renames the capsule to avoid reuse.

```
In [1]: import dpctl

In [2]: q = dpctl.SyclQueue("level_zero:gpu")

In [3]: cap = q._get_capsule()

In [4]: q1 = dpctl.SyclQueue(cap)

In [5]: q1.equals(q)
Out[5]: True

In [6]: cap
Out[6]: <capsule object "used_SyclQueueRef" at 0x7f0e651689f0>

In [7]: quit
```
The recognized capsule must be named "SyclContextRef", and is renamed to
"used_SyclContextRef" once consumed.

```
In [1]: import dpctl

In [2]: c = dpctl.SyclContext("gpu")

In [3]: c
Out[3]: <dpctl.SyclContext at 0x7fc1123818d0>

In [4]: caps = c._get_capsule()

In [5]: caps
Out[5]: <capsule object "SyclContextRef" at 0x7fc0eb1acb70>

In [6]: c_copy = dpctl.SyclContext(caps)

In [7]: c.equals(c_copy)
Out[7]: True
```
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the add-capsules branch 2 times, most recently from 06ab5d9 to 4f326c8 Compare April 2, 2021 16:56
@oleksandr-pavlyk oleksandr-pavlyk merged commit 3e5b855 into master Apr 2, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the add-capsules branch April 2, 2021 17:16
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.

2 participants