-
Notifications
You must be signed in to change notification settings - Fork 30
Static method of _Memory to create from external allocation #430
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
oleksandr-pavlyk
merged 2 commits into
master
from
feature/create_MemoryObject_from_external_allocation
May 6, 2021
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,24 +44,48 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(void, DPCTLSyclUSMRef) | |
__dpctl_give DPCTLSyclUSMRef | ||
DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
auto Q = unwrap(QRef); | ||
auto Ptr = malloc_shared(size, *Q); | ||
return wrap(Ptr); | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
try { | ||
auto Q = unwrap(QRef); | ||
auto Ptr = malloc_shared(size, *Q); | ||
return wrap(Ptr); | ||
} catch (feature_not_supported const &fns) { | ||
std::cerr << fns.what() << '\n'; | ||
return nullptr; | ||
} | ||
} | ||
|
||
__dpctl_give DPCTLSyclUSMRef | ||
DPCTLaligned_alloc_shared(size_t alignment, | ||
size_t size, | ||
__dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
auto Q = unwrap(QRef); | ||
auto Ptr = aligned_alloc_shared(alignment, size, *Q); | ||
return wrap(Ptr); | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
try { | ||
auto Q = unwrap(QRef); | ||
auto Ptr = aligned_alloc_shared(alignment, size, *Q); | ||
return wrap(Ptr); | ||
} catch (feature_not_supported const &fns) { | ||
std::cerr << fns.what() << '\n'; | ||
return nullptr; | ||
} | ||
} | ||
|
||
__dpctl_give DPCTLSyclUSMRef | ||
DPCTLmalloc_host(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
// SYCL 2020 spec: for devices without aspect::usm_host_allocations: | ||
// undefined behavior | ||
auto Q = unwrap(QRef); | ||
auto Ptr = malloc_host(size, *Q); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we not check for an exception here? At least a |
||
return wrap(Ptr); | ||
|
@@ -72,6 +96,12 @@ DPCTLaligned_alloc_host(size_t alignment, | |
size_t size, | ||
__dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
// SYCL 2020 spec: for devices without aspect::usm_host_allocations: | ||
// undefined behavior | ||
auto Q = unwrap(QRef); | ||
auto Ptr = aligned_alloc_host(alignment, size, *Q); | ||
return wrap(Ptr); | ||
|
@@ -80,24 +110,50 @@ DPCTLaligned_alloc_host(size_t alignment, | |
__dpctl_give DPCTLSyclUSMRef | ||
DPCTLmalloc_device(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
auto Q = unwrap(QRef); | ||
auto Ptr = malloc_device(size, *Q); | ||
return wrap(Ptr); | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
try { | ||
auto Q = unwrap(QRef); | ||
auto Ptr = malloc_device(size, *Q); | ||
return wrap(Ptr); | ||
} catch (feature_not_supported const &fns) { | ||
std::cerr << fns.what() << '\n'; | ||
return nullptr; | ||
} | ||
} | ||
|
||
__dpctl_give DPCTLSyclUSMRef | ||
DPCTLaligned_alloc_device(size_t alignment, | ||
size_t size, | ||
__dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
auto Q = unwrap(QRef); | ||
auto Ptr = aligned_alloc_device(alignment, size, *Q); | ||
return wrap(Ptr); | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
try { | ||
auto Q = unwrap(QRef); | ||
auto Ptr = aligned_alloc_device(alignment, size, *Q); | ||
return wrap(Ptr); | ||
} catch (feature_not_supported const &fns) { | ||
std::cerr << fns.what() << '\n'; | ||
return nullptr; | ||
} | ||
} | ||
|
||
void DPCTLfree_with_queue(__dpctl_take DPCTLSyclUSMRef MRef, | ||
__dpctl_keep const DPCTLSyclQueueRef QRef) | ||
{ | ||
if (!QRef) { | ||
std::cerr << "Input QRef is nullptr\n"; | ||
return; | ||
} | ||
if (!MRef) { | ||
std::cerr << "Input MRef is nullptr, nothing to free\n"; | ||
return; | ||
} | ||
auto Ptr = unwrap(MRef); | ||
auto Q = unwrap(QRef); | ||
free(Ptr, *Q); | ||
|
@@ -106,6 +162,14 @@ void DPCTLfree_with_queue(__dpctl_take DPCTLSyclUSMRef MRef, | |
void DPCTLfree_with_context(__dpctl_take DPCTLSyclUSMRef MRef, | ||
__dpctl_keep const DPCTLSyclContextRef CRef) | ||
{ | ||
if (!CRef) { | ||
std::cerr << "Input CRef is nullptr\n"; | ||
return; | ||
} | ||
if (!MRef) { | ||
std::cerr << "Input MRef is nullptr, nothing to free\n"; | ||
return; | ||
} | ||
auto Ptr = unwrap(MRef); | ||
auto C = unwrap(CRef); | ||
free(Ptr, *C); | ||
|
@@ -114,6 +178,14 @@ void DPCTLfree_with_context(__dpctl_take DPCTLSyclUSMRef MRef, | |
const char *DPCTLUSM_GetPointerType(__dpctl_keep const DPCTLSyclUSMRef MRef, | ||
__dpctl_keep const DPCTLSyclContextRef CRef) | ||
{ | ||
if (!CRef) { | ||
std::cerr << "Input CRef is nullptr\n"; | ||
return "unknown"; | ||
} | ||
if (!MRef) { | ||
std::cerr << "Input MRef is nullptr\n"; | ||
return "unknown"; | ||
} | ||
auto Ptr = unwrap(MRef); | ||
auto C = unwrap(CRef); | ||
|
||
|
@@ -134,6 +206,15 @@ DPCTLSyclDeviceRef | |
DPCTLUSM_GetPointerDevice(__dpctl_keep const DPCTLSyclUSMRef MRef, | ||
__dpctl_keep const DPCTLSyclContextRef CRef) | ||
{ | ||
if (!CRef) { | ||
std::cerr << "Input CRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
if (!MRef) { | ||
std::cerr << "Input MRef is nullptr\n"; | ||
return nullptr; | ||
} | ||
|
||
auto Ptr = unwrap(MRef); | ||
auto C = unwrap(CRef); | ||
|
||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.