1//===-- Test for parallel GPU malloc interface ----------------------------===//
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 "test/IntegrationTest/test.h"
10
11#include "src/__support/GPU/utils.h"
12#include "src/stdlib/free.h"
13#include "src/stdlib/malloc.h"
14
15using namespace LIBC_NAMESPACE;
16
17TEST_MAIN(int, char **, char **) {
18 int *convergent = reinterpret_cast<int *>(LIBC_NAMESPACE::malloc(16));
19 EXPECT_NE(convergent, nullptr);
20 *convergent = 1;
21 EXPECT_EQ(*convergent, 1);
22 LIBC_NAMESPACE::free(convergent);
23
24 int *divergent = reinterpret_cast<int *>(
25 LIBC_NAMESPACE::malloc((gpu::get_thread_id() + 1) * 16));
26 EXPECT_NE(divergent, nullptr);
27 *divergent = 1;
28 EXPECT_EQ(*divergent, 1);
29 LIBC_NAMESPACE::free(divergent);
30
31 if (gpu::get_lane_id() & 1) {
32 int *masked = reinterpret_cast<int *>(
33 LIBC_NAMESPACE::malloc((gpu::get_thread_id() + 1) * 16));
34 EXPECT_NE(masked, nullptr);
35 *masked = 1;
36 EXPECT_EQ(*masked, 1);
37 LIBC_NAMESPACE::free(masked);
38 }
39 return 0;
40}
41

source code of libc/test/integration/src/stdlib/gpu/malloc.cpp