brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · d46a1ad Raw
54 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/GPU/utils.h"10#include "src/__support/RPC/rpc_client.h"11#include "test/IntegrationTest/test.h"12 13using namespace LIBC_NAMESPACE;14 15static void test_add_simple() {16  uint64_t num_additions =17      10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id();18  uint64_t cnt = 0;19  for (uint32_t i = 0; i < num_additions; ++i) {20    LIBC_NAMESPACE::rpc::Client::Port port =21        LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_INCREMENT>();22    port.send_and_recv(23        [=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {24          reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt;25        },26        [&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {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.35static void test_noop(uint8_t data) {36  LIBC_NAMESPACE::rpc::Client::Port port =37      LIBC_NAMESPACE::rpc::client.open<LIBC_NOOP>();38  port.send([=](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {39    buffer->data[0] = data;40  });41  port.close();42}43 44TEST_MAIN(int argc, char **argv, char **envp) {45  test_add_simple();46 47  if (gpu::get_thread_id() % 2)48    test_noop(1);49  else50    test_noop(2);51 52  return 0;53}54