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 ensure that match any / match all work. |
16 | static void test_match() { |
17 | // FIXME: Disable on older SMs as they hang for some reason. |
18 | #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700 |
19 | uint64_t mask = gpu::get_lane_mask(); |
20 | EXPECT_EQ(1ull << gpu::get_lane_id(), |
21 | gpu::match_any(mask, gpu::get_lane_id())); |
22 | EXPECT_EQ(mask, gpu::match_any(mask, 1)); |
23 | |
24 | uint64_t expected = gpu::get_lane_id() < 16 ? 0xffff : 0xffff0000; |
25 | EXPECT_EQ(expected, gpu::match_any(mask, gpu::get_lane_id() < 16)); |
26 | EXPECT_EQ(mask, gpu::match_all(mask, 1)); |
27 | EXPECT_EQ(0ull, gpu::match_all(mask, gpu::get_lane_id())); |
28 | #endif |
29 | } |
30 | |
31 | TEST_MAIN(int argc, char **argv, char **envp) { |
32 | if (gpu::get_thread_id() >= gpu::get_lane_size()) |
33 | return 0; |
34 | |
35 | test_match(); |
36 | |
37 | return 0; |
38 | } |
39 | |