Skip to content

Commit f81879c

Browse files
committed
[Libomptarget] Add RPC-based printf implementation for OpenMP #85638
Summary: Relanding after reverting, only applies to AMDGPU for now. This patch adds an implementation of printf that's provided by the GPU C library runtime. This pritnf currently implemented using the same wrapper handling that OpenMP sets up. This will be removed once we have proper varargs support. This printf differs from the one CUDA offers in that it is synchronous and uses a finite size. Additionally we support pretty much every format specifier except the %n option. Depends on #85331
1 parent 0a13175 commit f81879c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

openmp/libomptarget/DeviceRTL/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ set(clang_opt_flags -O3 -mllvm -openmp-opt-disable -DSHARED_SCRATCHPAD_SIZE=512
122122
set(link_opt_flags -O3 -openmp-opt-disable -attributor-enable=module -vectorize-slp=false )
123123
set(link_export_flag -passes=internalize -internalize-public-api-file=${source_directory}/exports)
124124

125+
# If the user built with the GPU C library enabled we will use that instead.
126+
if(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
127+
list(APPEND clang_opt_flags -DOMPTARGET_HAS_LIBC)
128+
endif()
129+
125130
# Prepend -I to each list element
126131
set (LIBOMPTARGET_LLVM_INCLUDE_DIRS_DEVICERTL "${LIBOMPTARGET_LLVM_INCLUDE_DIRS}")
127132
list(TRANSFORM LIBOMPTARGET_LLVM_INCLUDE_DIRS_DEVICERTL PREPEND "-I")

openmp/libomptarget/DeviceRTL/src/LibC.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {
2525
} // namespace impl
2626
#pragma omp end declare variant
2727

28-
// We do not have a vprintf implementation for AMD GPU yet so we use a stub.
2928
#pragma omp begin declare variant match(device = {arch(amdgcn)})
29+
30+
#ifdef OMPTARGET_HAS_LIBC
31+
// TODO: Remove this handling once we have varargs support.
32+
extern "C" struct FILE *stdout;
33+
extern "C" int32_t rpc_fprintf(FILE *, const char *, void *, uint64_t);
34+
35+
namespace impl {
36+
int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t Size) {
37+
return rpc_fprintf(stdout, Format, Arguments, Size);
38+
}
39+
} // namespace impl
40+
#else
41+
// We do not have a vprintf implementation for AMD GPU so we use a stub.
3042
namespace impl {
3143
int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {
3244
return -1;
3345
}
3446
} // namespace impl
47+
#endif
3548
#pragma omp end declare variant
3649

3750
extern "C" {

0 commit comments

Comments
 (0)