Skip to content

Commit

Permalink
[OpenACC] throw if acc_malloc returned nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
dalg24 committed Jan 19, 2024
1 parent a3aa567 commit f9f3c6e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/OpenACC/Kokkos_OpenACCSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <OpenACC/Kokkos_OpenACC_DeepCopy.hpp>
#include <impl/Kokkos_MemorySpace.hpp>
#include <impl/Kokkos_Profiling_Interface.hpp>
#include <impl/Kokkos_Error.hpp>

#include <openacc.h>

Expand Down Expand Up @@ -66,6 +67,17 @@ void *Kokkos::Experimental::OpenACCSpace::impl_allocate(

ptr = acc_malloc(arg_alloc_size);

if (!ptr) {
size_t alignment = 1; // OpenACC does not handle alignment
using Kokkos::Experimental::RawMemoryAllocationFailure::FailureMode;
auto failure_mode = arg_alloc_size > 0 ? FailureMode::OutOfMemoryError
: FailureMode::InvalidAllocationSize;
using Kokkos::Experimental::RawMemoryAllocationFailure::AllocationMechanism;
auto alloc_mechanism = AllocationMechanism::OpenACCMalloc;
throw Kokkos::Experimental::RawMemoryAllocationFailure(
arg_alloc_size, alignment, failure_mode, alloc_mechanism);
}

if (Kokkos::Profiling::profileLibraryLoaded()) {
const size_t reported_size =
(arg_logical_size > 0) ? arg_logical_size : arg_alloc_size;
Expand Down

0 comments on commit f9f3c6e

Please sign in to comment.