brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · c346a2e Raw
34 lines · cpp
1//===-- Test for the shuffle operations on the GPU ------------------------===//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/CPP/bit.h"10#include "src/__support/GPU/utils.h"11#include "test/IntegrationTest/test.h"12 13using namespace LIBC_NAMESPACE;14 15// Test to make sure the shuffle instruction works by doing a simple broadcast.16// Each iteration reduces the width, so it will broadcast to a subset we check.17static void test_shuffle() {18  uint64_t mask = gpu::get_lane_mask();19  EXPECT_EQ(cpp::popcount(mask), gpu::get_lane_size());20 21  uint32_t x = gpu::get_lane_id();22  for (uint32_t width = gpu::get_lane_size(); width > 0; width /= 2)23    EXPECT_EQ(gpu::shuffle(mask, 0, x, width), (x / width) * width);24}25 26TEST_MAIN(int argc, char **argv, char **envp) {27  if (gpu::get_thread_id() >= gpu::get_lane_size())28    return 0;29 30  test_shuffle();31 32  return 0;33}34