Skip to content

Commit 3b8ccb2

Browse files
committed
add test
1 parent 1bb9630 commit 3b8ccb2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

libc/test/integration/src/__support/GPU/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ add_integration_test(
99
LOADER_ARGS
1010
--threads 64
1111
)
12+
13+
add_integration_test(
14+
shuffle_test
15+
SUITE libc-support-gpu-tests
16+
SRCS
17+
shuffle.cpp
18+
LOADER_ARGS
19+
--threads 64
20+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/__support/CPP/bit.h"
10+
#include "src/__support/GPU/utils.h"
11+
#include "test/IntegrationTest/test.h"
12+
13+
using 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.
17+
static 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+
26+
TEST_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+
}

0 commit comments

Comments
 (0)