1 //===-- Loader test to check the RPC interface with the loader ------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "include/llvm-libc-types/test_rpc_opcodes_t.h" 10 #include "src/__support/GPU/utils.h" 11 #include "src/__support/RPC/rpc_client.h" 12 #include "test/IntegrationTest/test.h" 13 14 using namespace LIBC_NAMESPACE; 15 test_add_simple()16static void test_add_simple() { 17 uint32_t num_additions = 18 10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id(); 19 uint64_t cnt = 0; 20 for (uint32_t i = 0; i < num_additions; ++i) { 21 LIBC_NAMESPACE::rpc::Client::Port port = 22 LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INCREMENT>(); 23 port.send_and_recv( 24 [=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 25 reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt; 26 }, 27 [&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 28 cnt = reinterpret_cast<uint64_t *>(buffer->data)[0]; 29 }); 30 port.close(); 31 } 32 ASSERT_TRUE(cnt == num_additions && "Incorrect sum"); 33 } 34 35 // Test to ensure that the RPC mechanism doesn't hang on divergence. test_noop(uint8_t data)36static void test_noop(uint8_t data) { 37 LIBC_NAMESPACE::rpc::Client::Port port = 38 LIBC_NAMESPACE::rpc::client.open<RPC_NOOP>(); 39 port.send([=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { 40 buffer->data[0] = data; 41 }); 42 port.close(); 43 } 44 TEST_MAIN(int argc,char ** argv,char ** envp)45TEST_MAIN(int argc, char **argv, char **envp) { 46 test_add_simple(); 47 48 if (gpu::get_thread_id() % 2) 49 test_noop(1); 50 else 51 test_noop(2); 52 53 return 0; 54 } 55