[Openmp-commits] [PATCH] D112005: [OpenMP] Check output of malloc in the device for debug

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 29 10:06:11 PDT 2021


jhuber6 updated this revision to Diff 383411.
jhuber6 added a comment.

Updating with ASSERT for the runtime usage.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112005/new/

https://reviews.llvm.org/D112005

Files:
  openmp/libomptarget/DeviceRTL/include/Configuration.h
  openmp/libomptarget/DeviceRTL/src/State.cpp


Index: openmp/libomptarget/DeviceRTL/src/State.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/State.cpp
+++ openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -134,9 +134,12 @@
     return Ptr;
   }
 
-  return memory::allocGlobal(AlignedBytes,
-                             "Slow path shared memory allocation, insufficient "
-                             "shared memory stack memory!");
+  void *GlobalMemory = memory::allocGlobal(
+      AlignedBytes, "Slow path shared memory allocation, insufficient "
+                    "shared memory stack memory!");
+  ASSERT(GlobalMemory != nullptr && "nullptr returned by malloc!");
+
+  return GlobalMemory;
 }
 
 void SharedMemorySmartStackTy::pop(void *Ptr, uint32_t Bytes) {
@@ -162,7 +165,10 @@
 }
 
 void *memory::allocGlobal(uint64_t Bytes, const char *Reason) {
-  return malloc(Bytes);
+  void *Ptr = malloc(Bytes);
+  if (config::isDebugMode(config::DebugKind::CommonIssues) && Ptr == nullptr)
+    PRINT("nullptr returned by malloc!\n");
+  return Ptr;
 }
 
 void memory::freeGlobal(void *Ptr, const char *Reason) { free(Ptr); }
@@ -280,6 +286,7 @@
   if (!ThreadStates[TId]) {
     ThreadStates[TId] = reinterpret_cast<ThreadStateTy *>(memory::allocGlobal(
         sizeof(ThreadStateTy), "ICV modification outside data environment"));
+    ASSERT(ThreadStates[TId] != nullptr && "Nullptr returned by malloc!");
     ThreadStates[TId]->init();
   }
   return ThreadStates[TId]->ICVState.*Var;
@@ -529,6 +536,8 @@
   } else {
     SharedMemVariableSharingSpacePtr = (void **)memory::allocGlobal(
         nArgs * sizeof(void *), "new extended args");
+    ASSERT(SharedMemVariableSharingSpacePtr != nullptr &&
+           "Nullptr returned by malloc!");
   }
   *GlobalArgs = SharedMemVariableSharingSpacePtr;
 }
Index: openmp/libomptarget/DeviceRTL/include/Configuration.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/Configuration.h
+++ openmp/libomptarget/DeviceRTL/include/Configuration.h
@@ -21,6 +21,7 @@
 enum DebugKind : uint32_t {
   Assertion = 1U << 0,
   FunctionTracing = 1U << 1,
+  CommonIssues = 1U << 2,
 };
 
 /// Return the number of devices in the system, same number as returned on the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112005.383411.patch
Type: text/x-patch
Size: 2288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20211029/144f4caa/attachment.bin>


More information about the Openmp-commits mailing list