forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[OpenMP][libc] Remove special handling for OpenMP printf (llv…
- Loading branch information
Showing
11 changed files
with
183 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===-- GPU implementation of fprintf -------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "rpc_fprintf.h" | ||
|
||
#include "src/__support/CPP/string_view.h" | ||
#include "src/__support/GPU/utils.h" | ||
#include "src/__support/RPC/rpc_client.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/stdio/gpu/file.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
template <uint16_t opcode> | ||
int fprintf_impl(::FILE *__restrict file, const char *__restrict format, | ||
size_t format_size, void *args, size_t args_size) { | ||
uint64_t mask = gpu::get_lane_mask(); | ||
rpc::Client::Port port = rpc::client.open<opcode>(); | ||
|
||
if constexpr (opcode == RPC_PRINTF_TO_STREAM) { | ||
port.send([&](rpc::Buffer *buffer) { | ||
buffer->data[0] = reinterpret_cast<uintptr_t>(file); | ||
}); | ||
} | ||
|
||
port.send_n(format, format_size); | ||
port.recv([&](rpc::Buffer *buffer) { | ||
args_size = static_cast<size_t>(buffer->data[0]); | ||
}); | ||
port.send_n(args, args_size); | ||
|
||
uint32_t ret = 0; | ||
for (;;) { | ||
const char *str = nullptr; | ||
port.recv([&](rpc::Buffer *buffer) { | ||
ret = static_cast<uint32_t>(buffer->data[0]); | ||
str = reinterpret_cast<const char *>(buffer->data[1]); | ||
}); | ||
// If any lanes have a string argument it needs to be copied back. | ||
if (!gpu::ballot(mask, str)) | ||
break; | ||
|
||
uint64_t size = str ? internal::string_length(str) + 1 : 0; | ||
port.send_n(str, size); | ||
} | ||
|
||
port.close(); | ||
return ret; | ||
} | ||
|
||
// TODO: Delete this and port OpenMP to use `printf`. | ||
// place of varargs. Once varargs support is added we will use that to | ||
// implement the real version. | ||
LLVM_LIBC_FUNCTION(int, rpc_fprintf, | ||
(::FILE *__restrict stream, const char *__restrict format, | ||
void *args, size_t size)) { | ||
cpp::string_view str(format); | ||
if (stream == stdout) | ||
return fprintf_impl<RPC_PRINTF_TO_STDOUT>(stream, format, str.size() + 1, | ||
args, size); | ||
else if (stream == stderr) | ||
return fprintf_impl<RPC_PRINTF_TO_STDERR>(stream, format, str.size() + 1, | ||
args, size); | ||
else | ||
return fprintf_impl<RPC_PRINTF_TO_STREAM>(stream, format, str.size() + 1, | ||
args, size); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- Implementation header for RPC functions -----------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H | ||
#define LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H | ||
|
||
#include "hdr/types/FILE.h" | ||
#include "src/__support/macros/config.h" | ||
#include <stddef.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
int rpc_fprintf(::FILE *__restrict stream, const char *__restrict format, | ||
void *argc, size_t size); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_GPU_RPC_HOST_CALL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters