Skip to content

Commit

Permalink
[openmp][devicertl] Freestanding nvptx via stub printf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JonChesterfield committed Aug 23, 2021
1 parent 1055c5e commit d26000e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
Expand Up @@ -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))
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
Expand Up @@ -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); }

Expand Down
13 changes: 9 additions & 4 deletions openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
Expand Up @@ -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))
Expand Down Expand Up @@ -80,4 +83,6 @@ enum : __kmpc_impl_lanemask_t {
__kmpc_impl_all_lanes = ~(__kmpc_impl_lanemask_t)0
};

#define printf(...)

#endif

0 comments on commit d26000e

Please sign in to comment.