Skip to content

Added new example of Python object exposing __sycl_usm_array_interface__ #596

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
Sep 27, 2021

Conversation

oleksandr-pavlyk
Copy link
Contributor

@oleksandr-pavlyk oleksandr-pavlyk commented Sep 26, 2021

Native Pybind11-generated extension implemented Python type bound to
DMatrix C++ class which allocates USM memory using sycl::usm_allocator.

The Python object implements __sycl_usm_array_interface__, which allows
dpctl.memory.as_usm_memory to create a view into that native USM allocation.
The example.py modifies that memory from Python, and uses object's own
.tolist() method to retrieve the memory using C++, demonstrating that
values changed.

Also added license missing headers to .cpp and .hpp files from other
examples

Native Pybind11-generated extension implemented Python type bound to
DMatrix C++ class which allocates USM memory using sycl::usm_allocator.

The Python object implements __sycl_usm_array_interface__, which allows
dpctl.memory.as_usm_memory to create a view into that native USM allocation.
The example.py modifies that memory from Python, and uses object's own
.tolist() method to retrieve the memory using C++, demonstrating that
values changed.

Also added license missing headers to .cpp and .hpp files from other
examples
{
PyObject *queue_ptr = queue.ptr();
if (PyObject_TypeCheck(queue_ptr, &PySyclQueueType)) {
DPCTLSyclQueueRef QRef =
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not we need to free the QRef?

Copy link
Contributor Author

@oleksandr-pavlyk oleksandr-pavlyk Sep 27, 2021

Choose a reason for hiding this comment

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

It appears we do not need to free QRef. The DPCTLSyclQueueRef get_queue_ref(SyclQueue q) function returns the reference stored in the Python object (https://github.com/IntelPython/dpctl/blob/master/dpctl/_sycl_queue.pyx#L691), so resources referenced by QRef are managed by the Python object itself.

DMatrix makes a copy of sycl::queue in its constructor, so it should all be good.

@oleksandr-pavlyk oleksandr-pavlyk merged commit b180d59 into master Sep 27, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the extend-examples branch September 27, 2021 22:30
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