[Openmp-commits] [openmp] 567b3f8 - [OpenMP][deviceRTLs] Drop `assert` in common parts of `deviceRTLs`

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Thu Feb 4 09:39:49 PST 2021


Author: Shilei Tian
Date: 2021-02-04T12:39:43-05:00
New Revision: 567b3f8841d0725e07dd816ca4288a309064bd39

URL: https://github.com/llvm/llvm-project/commit/567b3f8841d0725e07dd816ca4288a309064bd39
DIFF: https://github.com/llvm/llvm-project/commit/567b3f8841d0725e07dd816ca4288a309064bd39.diff

LOG: [OpenMP][deviceRTLs] Drop `assert` in common parts of `deviceRTLs`

The header `assert.h` needs to be included in order to use `assert` in the code.
When building NVPTX `deviceRTLs` on a CUDA free system, it requires headers from
`gcc-multilib`, which some systems don't have. This patch drops the use of
`assert` in common parts of `deviceRTLs`. In light of
`openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h`, a code block
```
if (!cond)
  __builtin_trap();
```
is being used. The builtin will be translated to `call void @llvm.trap()`, and
the corresponding PTX is `trap;`.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D95986

Added: 
    

Modified: 
    openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
    openmp/libomptarget/deviceRTLs/common/debug.h
    openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
index 428edfab39a8..fb41332631bc 100644
--- a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
+++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
@@ -18,7 +18,6 @@
 
 #include "amdgcn_interface.h"
 
-#include <assert.h>
 #include <inttypes.h>
 #include <stddef.h>
 #include <stdint.h>
@@ -68,11 +67,6 @@ enum : __kmpc_impl_lanemask_t {
   __kmpc_impl_all_lanes = ~(__kmpc_impl_lanemask_t)0
 };
 
-// DEVICE versions of part of libc
-INLINE void __assert_fail(const char *, const char *, unsigned int,
-                          const char *) {
-  __builtin_trap();
-}
 EXTERN int printf(const char *, ...);
 
 #endif

diff  --git a/openmp/libomptarget/deviceRTLs/common/debug.h b/openmp/libomptarget/deviceRTLs/common/debug.h
index aeffa2f7e4b1..3b2895e22a29 100644
--- a/openmp/libomptarget/deviceRTLs/common/debug.h
+++ b/openmp/libomptarget/deviceRTLs/common/debug.h
@@ -142,13 +142,17 @@ NOINLINE static void log(const char *fmt, Arguments... parameters) {
 template <typename... Arguments>
 NOINLINE static void check(bool cond, const char *fmt,
                            Arguments... parameters) {
-  if (!cond)
+  if (!cond) {
     printf(fmt, (int)GetBlockIdInKernel(), (int)GetThreadIdInBlock(),
            (int)GetWarpId(), (int)GetLaneId(), parameters...);
-  assert(cond);
+    __builtin_trap();
+  }
 }
 
-NOINLINE static void check(bool cond) { assert(cond); }
+NOINLINE static void check(bool cond) {
+  if (!cond)
+    __builtin_trap();
+}
 #endif
 
 // set flags that are tested (inclusion properties)

diff  --git a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
index 33fa9bb78c9c..52a7d32faa98 100644
--- a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
+++ b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
@@ -12,7 +12,6 @@
 #ifndef _TARGET_IMPL_H_
 #define _TARGET_IMPL_H_
 
-#include <assert.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>


        


More information about the Openmp-commits mailing list