brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · a02a674 Raw
42 lines · cpp
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-exception6//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  EXPECT_TRUE(__builtin_is_aligned(divergent, 16));28  *divergent = 1;29  EXPECT_EQ(*divergent, 1);30  LIBC_NAMESPACE::free(divergent);31 32  if (gpu::get_lane_id() & 1) {33    int *masked = reinterpret_cast<int *>(34        LIBC_NAMESPACE::malloc((gpu::get_thread_id() + 1) * 16));35    EXPECT_NE(masked, nullptr);36    *masked = 1;37    EXPECT_EQ(*masked, 1);38    LIBC_NAMESPACE::free(masked);39  }40  return 0;41}42