Skip to content

Commit d28a367

Browse files
committed
[Libomptarget] Add RPC-based printf implementation for OpenMP
Summary: 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 470040b commit d28a367

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,23 @@ void memset(void *dst, int C, size_t count) {
5353
dstc[I] = C;
5454
}
5555

56+
// If the user built with the GPU C library enabled we will assume that we can
57+
// call it.
58+
#ifdef OMPTARGET_HAS_LIBC
59+
60+
// TODO: Remove this handling once we have varargs support.
61+
extern struct FILE *stdout;
62+
int32_t rpc_fprintf(FILE *, const char *, void *, uint64_t);
63+
64+
int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t Size) {
65+
return rpc_fprintf(stdout, Format, Arguments, Size);
66+
}
67+
#else
5668
/// printf() calls are rewritten by CGGPUBuiltin to __llvm_omp_vprintf
5769
int32_t __llvm_omp_vprintf(const char *Format, void *Arguments, uint32_t Size) {
5870
return impl::omp_vprintf(Format, Arguments, Size);
5971
}
72+
#endif
6073
}
6174

6275
#pragma omp end declare target

0 commit comments

Comments
 (0)