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

Static method of _Memory to create from external allocation #430

Merged

Conversation

oleksandr-pavlyk
Copy link
Collaborator

Method takes USMRef, number of bytes and queue reference.

If USMRef is bound to context in the queue and USM type comes
back not 'unknown', appropriate MemoryUSM* object is created
which assumes ownership of this memory.

Optional memory_owner keyword argument may be specified to set
the recorded reference object to something other than None (signaling
that _Memory is responsible for memory deallocation).

This can be used to create MemoryUSM* Python object from natively
allocated memory, populate it, but leave deallocation to the caller.
It could also be set to a PyCapsule object that carries a custom deleter.

@oleksandr-pavlyk oleksandr-pavlyk requested a review from diptorupd May 5, 2021 23:27
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/create_MemoryObject_from_external_allocation branch from 5b537af to 1676f34 Compare May 6, 2021 00:03
.flake8 Outdated Show resolved Hide resolved
dpctl/memory/_memory.pxd Outdated Show resolved Hide resolved
dpctl/memory/_memory.pyx Outdated Show resolved Hide resolved
dpctl/memory/_memory.pyx Outdated Show resolved Hide resolved
dpctl/memory/_memory.pyx Outdated Show resolved Hide resolved
dpctl/memory/_memory.pyx Outdated Show resolved Hide resolved
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/create_MemoryObject_from_external_allocation branch from 1676f34 to 3aced4c Compare May 6, 2021 01:39
Method takes USMRef, number of bytes and queue reference.

If USMRef is bound to context in the queue and USM type comes
back not 'unknown', appropriate MemoryUSM* object is created
which assumes ownership of this memory.

Optional `memory_owner` keyword argument may be specified to set
the recorded reference object to something other than None (signaling
that _Memory is responsible for memory deallocation).

This can be used to create MemoryUSM* Python object from natively
allocated memory, populate it, but leave deallocation to the caller.
It could also be set to a PyCapsule object that carries a custom deleter.
@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/create_MemoryObject_from_external_allocation branch from 3aced4c to 8fed78b Compare May 6, 2021 01:59
if (!QRef) {
std::cerr << "Input QRef is nullptr\n";
return nullptr;
}
auto Q = unwrap(QRef);
auto Ptr = malloc_host(size, *Q);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not check for an exception here? At least a bad_alloc exception?

@oleksandr-pavlyk oleksandr-pavlyk force-pushed the feature/create_MemoryObject_from_external_allocation branch from 69c5783 to 7247207 Compare May 6, 2021 16:02
@oleksandr-pavlyk
Copy link
Collaborator Author

CI failure is network related, timing out when trying to retrieve NumPy for pip installation

pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='binstar-cio-packages-prod.s3.amazonaws.com', port=443): Read timed out.

@oleksandr-pavlyk oleksandr-pavlyk merged commit 83b7359 into master May 6, 2021
@oleksandr-pavlyk oleksandr-pavlyk deleted the feature/create_MemoryObject_from_external_allocation branch May 6, 2021 18:39
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