diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt b/openmp/libomptarget/DeviceRTL/CMakeLists.txt --- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt +++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt @@ -108,6 +108,7 @@ ${include_directory}/Debug.h ${include_directory}/Interface.h ${include_directory}/Mapping.h + ${include_directory}/Memory.h ${include_directory}/State.h ${include_directory}/Synchronization.h ${include_directory}/Types.h @@ -119,6 +120,7 @@ ${source_directory}/Debug.cpp ${source_directory}/Kernel.cpp ${source_directory}/Mapping.cpp + ${source_directory}/Memory.cpp ${source_directory}/Misc.cpp ${source_directory}/Parallelism.cpp ${source_directory}/Reduction.cpp diff --git a/openmp/libomptarget/DeviceRTL/include/Memory.h b/openmp/libomptarget/DeviceRTL/include/Memory.h new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/DeviceRTL/include/Memory.h @@ -0,0 +1,23 @@ +//===--- Memory.h - OpenMP device runtime memory allocator -------- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// +// +//===----------------------------------------------------------------------===// + +#ifndef OMPTARGET_MEMORY_H +#define OMPTARGET_MEMORY_H + +#include "Types.h" + +extern "C" { +__attribute__((leaf)) void *malloc(uint64_t Size); +__attribute__((leaf)) void free(void *Ptr); +} + +#endif diff --git a/openmp/libomptarget/DeviceRTL/include/Types.h b/openmp/libomptarget/DeviceRTL/include/Types.h --- a/openmp/libomptarget/DeviceRTL/include/Types.h +++ b/openmp/libomptarget/DeviceRTL/include/Types.h @@ -32,6 +32,7 @@ using uint32_t = unsigned int; using int64_t = long; using uint64_t = unsigned long; +using size_t = decltype(sizeof(char)); static_assert(sizeof(int8_t) == 1, "type size mismatch"); static_assert(sizeof(uint8_t) == 1, "type size mismatch"); diff --git a/openmp/libomptarget/DeviceRTL/src/CMakeLists.txt b/openmp/libomptarget/DeviceRTL/src/CMakeLists.txt --- a/openmp/libomptarget/DeviceRTL/src/CMakeLists.txt +++ b/openmp/libomptarget/DeviceRTL/src/CMakeLists.txt @@ -3,6 +3,7 @@ Debug.cpp Kernel.cpp Mapping.cpp + Memory.cpp Misc.cpp Parallelism.cpp Reduction.cpp diff --git a/openmp/libomptarget/DeviceRTL/src/Memory.cpp b/openmp/libomptarget/DeviceRTL/src/Memory.cpp new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/DeviceRTL/src/Memory.cpp @@ -0,0 +1,35 @@ +//===------- Memory.cpp - OpenMP device runtime memory allocator -- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// +//===----------------------------------------------------------------------===// + +#pragma omp begin declare target device_type(nohost) + +#include "Memory.h" + +/// AMDGCN Implementation +/// +///{ +#pragma omp begin declare variant match(device = {arch(amdgcn)}) + +extern "C" { +__attribute__((leaf)) unsigned long long +__ockl_dm_alloc(unsigned long long Size); +__attribute__((leaf)) void __ockl_dm_dealloc(unsigned long long Addr); + +void *malloc(size_t Size) { return (void *)__ockl_dm_alloc(Size); } + +void free(void *P) { __ockl_dm_dealloc((unsigned long long)P); } +} + +#pragma omp end declare variant + +///} + +#pragma omp end declare target diff --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp --- a/openmp/libomptarget/DeviceRTL/src/State.cpp +++ b/openmp/libomptarget/DeviceRTL/src/State.cpp @@ -13,6 +13,7 @@ #include "Debug.h" #include "Interface.h" #include "Mapping.h" +#include "Memory.h" #include "Synchronization.h" #include "Types.h" #include "Utils.h" @@ -36,36 +37,6 @@ namespace { -/// Fallback implementations are missing to trigger a link time error. -/// Implementations for new devices, including the host, should go into a -/// dedicated begin/end declare variant. -/// -///{ - -extern "C" { -__attribute__((leaf)) void *malloc(uint64_t Size); -__attribute__((leaf)) void free(void *Ptr); -} - -///} - -/// AMDGCN implementations of the shuffle sync idiom. -/// -///{ -#pragma omp begin declare variant match(device = {arch(amdgcn)}) - -extern "C" { -void *malloc(uint64_t Size) { - // TODO: Use some preallocated space for dynamic malloc. - return nullptr; -} - -void free(void *Ptr) {} -} - -#pragma omp end declare variant -///} - /// A "smart" stack in shared memory. /// /// The stack exposes a malloc/free interface but works like a stack internally.