30 lines · cpp
1//===-- GPU Implementation of aligned_alloc -------------------------------===//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/stdlib/aligned_alloc.h"10 11#include "src/__support/GPU/allocator.h"12#include "src/__support/common.h"13#include "src/__support/macros/config.h"14 15namespace LIBC_NAMESPACE_DECL {16 17LLVM_LIBC_FUNCTION(void *, aligned_alloc, (size_t alignment, size_t size)) {18 // FIXME: NVIDIA targets currently use the built-in 'malloc' which we cannot19 // reason with. But we still need to provide this function for compatibility.20#ifndef LIBC_TARGET_ARCH_IS_NVPTX21 return gpu::aligned_allocate(static_cast<uint32_t>(alignment), size);22#else23 (void)alignment;24 (void)size;25 return nullptr;26#endif27}28 29} // namespace LIBC_NAMESPACE_DECL30