10bd564a2SJoseph Huber //===-- Loader test to check the RPC interface with the loader ------------===// 20bd564a2SJoseph Huber // 30bd564a2SJoseph Huber // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40bd564a2SJoseph Huber // See https://llvm.org/LICENSE.txt for license information. 50bd564a2SJoseph Huber // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60bd564a2SJoseph Huber // 70bd564a2SJoseph Huber //===----------------------------------------------------------------------===// 80bd564a2SJoseph Huber 973aab2f6Slntue #include "include/llvm-libc-types/test_rpc_opcodes_t.h" 10a080798fSJoseph Huber #include "src/__support/GPU/utils.h" 110bd564a2SJoseph Huber #include "src/__support/RPC/rpc_client.h" 120bd564a2SJoseph Huber #include "test/IntegrationTest/test.h" 130bd564a2SJoseph Huber 14b6bc9d72SGuillaume Chatelet using namespace LIBC_NAMESPACE; 150bd564a2SJoseph Huber 160bd564a2SJoseph Huber static void test_add_simple() { 17507edb52SJoseph Huber uint32_t num_additions = 18507edb52SJoseph Huber 10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id(); 190bd564a2SJoseph Huber uint64_t cnt = 0; 20a080798fSJoseph Huber for (uint32_t i = 0; i < num_additions; ++i) { 2189614cebSJoseph Huber LIBC_NAMESPACE::rpc::Client::Port port = 2289614cebSJoseph Huber LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INCREMENT>(); 230bd564a2SJoseph Huber port.send_and_recv( 2489614cebSJoseph Huber [=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 250bd564a2SJoseph Huber reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt; 260bd564a2SJoseph Huber }, 2789614cebSJoseph Huber [&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 280bd564a2SJoseph Huber cnt = reinterpret_cast<uint64_t *>(buffer->data)[0]; 290bd564a2SJoseph Huber }); 300bd564a2SJoseph Huber port.close(); 310bd564a2SJoseph Huber } 320bd564a2SJoseph Huber ASSERT_TRUE(cnt == num_additions && "Incorrect sum"); 330bd564a2SJoseph Huber } 340bd564a2SJoseph Huber 35507edb52SJoseph Huber // Test to ensure that the RPC mechanism doesn't hang on divergence. 36507edb52SJoseph Huber static void test_noop(uint8_t data) { 3789614cebSJoseph Huber LIBC_NAMESPACE::rpc::Client::Port port = 38*a6ef0debSJoseph Huber LIBC_NAMESPACE::rpc::client.open<LIBC_NOOP>(); 3989614cebSJoseph Huber port.send([=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 4089614cebSJoseph Huber buffer->data[0] = data; 4189614cebSJoseph Huber }); 42507edb52SJoseph Huber port.close(); 43507edb52SJoseph Huber } 44507edb52SJoseph Huber 450bd564a2SJoseph Huber TEST_MAIN(int argc, char **argv, char **envp) { 460bd564a2SJoseph Huber test_add_simple(); 47a080798fSJoseph Huber 48507edb52SJoseph Huber if (gpu::get_thread_id() % 2) 49507edb52SJoseph Huber test_noop(1); 50507edb52SJoseph Huber else 51507edb52SJoseph Huber test_noop(2); 52507edb52SJoseph Huber 530bd564a2SJoseph Huber return 0; 540bd564a2SJoseph Huber } 55