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 rpc::Client::Port port = rpc::client.open<RPC_TEST_INCREMENT>(); 22 port.send_and_recv( 23 [=](rpc::Buffer *buffer) { 24 reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt; 25 }, 26 [&](rpc::Buffer *buffer) { 27 cnt = reinterpret_cast<uint64_t *>(buffer->data)[0]; 28 }); 29 port.close(); 30 } 31 ASSERT_TRUE(cnt == num_additions && "Incorrect sum"); 32 } 33 34 // Test to ensure that the RPC mechanism doesn't hang on divergence. test_noop(uint8_t data)35static void test_noop(uint8_t data) { 36 rpc::Client::Port port = rpc::client.open<RPC_NOOP>(); 37 port.send([=](rpc::Buffer *buffer) { buffer->data[0] = data; }); 38 port.close(); 39 } 40 TEST_MAIN(int argc,char ** argv,char ** envp)41TEST_MAIN(int argc, char **argv, char **envp) { 42 test_add_simple(); 43 44 if (gpu::get_thread_id() % 2) 45 test_noop(1); 46 else 47 test_noop(2); 48 49 return 0; 50 } 51