[Openmp-commits] [openmp] d26000e - [openmp][devicertl] Freestanding nvptx via stub printf

Jon Chesterfield via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 23 15:08:00 PDT 2021


Author: Jon Chesterfield
Date: 2021-08-23T23:07:47+01:00
New Revision: d26000e4cc2bc65e207a84fa26cb6e374d60aa12

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

LOG: [openmp][devicertl] Freestanding nvptx via stub printf

Compiled nvptx devicertl as freestanding, breaking the
dependency on host glibc and gcc-multilibs. Thus build it by default.

Comes at the cost of #defining out printf. Tried mapping it onto
__builtin_printf but that gets transformed back to printf instead
of hitting the cuda/openmp lowering transform.

Printf could be preserved by one of:
- dropping all the standard headers and ffreestanding
- providing a header only printf implementation
- changing the compiler handling of printf

Reviewed By: grokos

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

Added: 
    

Modified: 
    openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
    openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
    openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt b/openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
index 68d93cedc06ce..4ccadec86eeda 100644
--- a/openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
+++ b/openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
@@ -10,8 +10,8 @@
 #
 ##===----------------------------------------------------------------------===##
 
-# By default we will not build NVPTX deviceRTL on a CUDA free system
-set(LIBOMPTARGET_BUILD_NVPTX_BCLIB FALSE CACHE BOOL
+# By default we will build NVPTX deviceRTL on a CUDA free system
+set(LIBOMPTARGET_BUILD_NVPTX_BCLIB TRUE CACHE BOOL
   "Whether build NVPTX deviceRTL on CUDA free system.")
 
 if (NOT (LIBOMPTARGET_DEP_CUDA_FOUND OR LIBOMPTARGET_BUILD_NVPTX_BCLIB))
@@ -163,6 +163,7 @@ list(TRANSFORM LIBOMPTARGET_LLVM_INCLUDE_DIRS_NVPTX PREPEND "-I")
 # Set flags for LLVM Bitcode compilation.
 set(bc_flags -S -x c++ -O1 -std=c++14
              -mllvm -openmp-opt-disable
+             -ffreestanding
              -target nvptx64
              -Xclang -emit-llvm-bc
              -Xclang -aux-triple -Xclang ${aux_triple}

diff  --git a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
index 896da1e26075f..11f017c453445 100644
--- a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -181,6 +181,11 @@ EXTERN int __kmpc_impl_test_lock(omp_lock_t *lock) {
   return __kmpc_atomic_add(lock, 0u);
 }
 
+extern "C" {
+void *malloc(size_t);
+void free(void *);
+}
+
 EXTERN void *__kmpc_impl_malloc(size_t x) { return malloc(x); }
 EXTERN void __kmpc_impl_free(void *x) { free(x); }
 

diff  --git a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
index 4664e58a3a33c..1f64bb99afb5e 100644
--- a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
+++ b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
@@ -12,12 +12,15 @@
 #ifndef _TARGET_IMPL_H_
 #define _TARGET_IMPL_H_
 
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-
 #include "nvptx_interface.h"
 
+#include <stddef.h>
+#include <stdint.h>
+
+// subset of inttypes.h
+#define PRId64 "ld"
+#define PRIu64 "lu"
+
 typedef uint32_t __kmpc_impl_lanemask_t;
 
 #define INLINE inline __attribute__((always_inline))
@@ -80,4 +83,6 @@ enum : __kmpc_impl_lanemask_t {
   __kmpc_impl_all_lanes = ~(__kmpc_impl_lanemask_t)0
 };
 
+#define printf(...)
+
 #endif


        


More information about the Openmp-commits mailing list