Skip to content

Commit

Permalink
Merge pull request #195 from krasznaa/SYCLResourceExcept-main-20220914
Browse files Browse the repository at this point in the history
SYCL Memory Resource Exceptions, main branch (2022.09.14.)
  • Loading branch information
krasznaa authored Sep 15, 2022
2 parents 8d57490 + 5edeaa1 commit b51764b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sycl/src/memory/sycl/device_memory_resource.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void* device_memory_resource::do_allocate(std::size_t nbytes,
void* result = cl::sycl::aligned_alloc_device(alignment, nbytes,
details::get_queue(m_queue));

// Check that the allocation succeeded.
if (result == nullptr) {
throw std::bad_alloc();
}

// Let the user know what's happening.
VECMEM_DEBUG_MSG(
5, "Allocated %ld bytes of (%ld aligned) device memory on \"%s\" at %p",
Expand Down
5 changes: 5 additions & 0 deletions sycl/src/memory/sycl/host_memory_resource.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void* host_memory_resource::do_allocate(std::size_t nbytes,
void* result = cl::sycl::aligned_alloc_host(alignment, nbytes,
details::get_queue(m_queue));

// Check that the allocation succeeded.
if (result == nullptr) {
throw std::bad_alloc();
}

// Let the user know what's happening.
VECMEM_DEBUG_MSG(5,
"Allocated %ld bytes of (%ld aligned) host memory at %p",
Expand Down
5 changes: 5 additions & 0 deletions sycl/src/memory/sycl/shared_memory_resource.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void* shared_memory_resource::do_allocate(std::size_t nbytes,
void* result = cl::sycl::aligned_alloc_shared(alignment, nbytes,
details::get_queue(m_queue));

// Check that the allocation succeeded.
if (result == nullptr) {
throw std::bad_alloc();
}

// Let the user know what's happening.
VECMEM_DEBUG_MSG(
5, "Allocated %ld bytes of (%ld aligned) shared memory on \"%s\" at %p",
Expand Down

0 comments on commit b51764b

Please sign in to comment.