Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libc / src / __support / GPU / allocator.cpp
blobf98e610104797fda51d9b85cfa984dafeb9050ae
1 //===-- GPU memory allocator implementation ---------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "allocator.h"
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 {
16 namespace {
18 void *rpc_allocate(uint64_t size) {
19 void *ptr = nullptr;
20 rpc::Client::Port port = rpc::client.open<RPC_MALLOC>();
21 port.send_and_recv(
22 [=](rpc::Buffer *buffer, uint32_t) { buffer->data[0] = size; },
23 [&](rpc::Buffer *buffer, uint32_t) {
24 ptr = reinterpret_cast<void *>(buffer->data[0]);
25 });
26 port.close();
27 return ptr;
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);
34 });
35 port.close();
38 } // namespace
40 namespace gpu {
42 void *allocate(uint64_t size) { return rpc_allocate(size); }
44 void deallocate(void *ptr) { rpc_free(ptr); }
46 } // namespace gpu
47 } // namespace LIBC_NAMESPACE_DECL