1 //===-- GPU memory allocator implementation ---------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
11 #include "src/__support/GPU/utils.h"
12 #include "src/__support/RPC/rpc_client.h"
13 #include "src/__support/macros/config.h"
15 namespace LIBC_NAMESPACE_DECL
{
18 void *rpc_allocate(uint64_t size
) {
20 rpc::Client::Port port
= rpc::client
.open
<RPC_MALLOC
>();
22 [=](rpc::Buffer
*buffer
, uint32_t) { buffer
->data
[0] = size
; },
23 [&](rpc::Buffer
*buffer
, uint32_t) {
24 ptr
= reinterpret_cast<void *>(buffer
->data
[0]);
30 void rpc_free(void *ptr
) {
31 rpc::Client::Port port
= rpc::client
.open
<RPC_FREE
>();
32 port
.send([=](rpc::Buffer
*buffer
, uint32_t) {
33 buffer
->data
[0] = reinterpret_cast<uintptr_t>(ptr
);
42 void *allocate(uint64_t size
) { return rpc_allocate(size
); }
44 void deallocate(void *ptr
) { rpc_free(ptr
); }
47 } // namespace LIBC_NAMESPACE_DECL