-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Implement a generic streaming interface in the RPC
Currently we provide the `send_n` and `recv_n` functions. These were somewhat divergent and not tested on the GPU. This patch changes the support to be more common. We do this my making the CPU provide an array equal the to at least the lane size while the GPU can rely on the private memory address of its stack variables. This allows us to send data back and forth generically. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D150379
- Loading branch information
Showing
5 changed files
with
137 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===-- Loader test to check the RPC streaming interface with the loader --===// | ||
// | ||
// 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 "src/__support/GPU/utils.h" | ||
#include "src/__support/RPC/rpc_client.h" | ||
#include "src/__support/integer_to_string.h" | ||
#include "src/string/memory_utils/memcmp_implementations.h" | ||
#include "src/string/memory_utils/memcpy_implementations.h" | ||
#include "src/string/string_utils.h" | ||
#include "test/IntegrationTest/test.h" | ||
|
||
extern "C" void *malloc(uint64_t); | ||
|
||
using namespace __llvm_libc; | ||
|
||
static void test_stream() { | ||
const char str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"; | ||
uint64_t send_size = sizeof(str); | ||
void *send_ptr = malloc(send_size); | ||
void *recv_ptr; | ||
uint64_t recv_size; | ||
|
||
inline_memcpy(send_ptr, str, send_size); | ||
ASSERT_TRUE(inline_memcmp(send_ptr, str, send_size) == 0 && "Data mismatch"); | ||
rpc::Client::Port port = rpc::client.open<rpc::TEST_STREAM>(); | ||
port.send_n(send_ptr, send_size); | ||
port.recv_n(&recv_ptr, &recv_size, | ||
[](uint64_t size) { return malloc(size); }); | ||
port.close(); | ||
ASSERT_TRUE(inline_memcmp(recv_ptr, str, recv_size) == 0 && "Data mismatch"); | ||
ASSERT_TRUE(recv_size == send_size && "Data size mismatch"); | ||
|
||
free(send_ptr); | ||
free(recv_ptr); | ||
} | ||
|
||
TEST_MAIN(int argc, char **argv, char **envp) { | ||
test_stream(); | ||
|
||
return 0; | ||
} |
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