File tree Expand file tree Collapse file tree 6 files changed +88
-19
lines changed
Expand file tree Collapse file tree 6 files changed +88
-19
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,15 @@ add_header_library(
1212 DEPENDS
1313 ${target_gpu_utils}
1414)
15+
16+ add_object_library(
17+ allocator
18+ SRCS
19+ allocator.cpp
20+ HDRS
21+ allocator.h
22+ DEPENDS
23+ libc.src.__support.common
24+ libc.src.__support.GPU.utils
25+ libc.src.__support.RPC.rpc_client
26+ )
Original file line number Diff line number Diff line change 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+ // ===----------------------------------------------------------------------===//
8+
9+ #include " allocator.h"
10+
11+ #include " src/__support/GPU/utils.h"
12+ #include " src/__support/RPC/rpc_client.h"
13+
14+ namespace LIBC_NAMESPACE {
15+ namespace {
16+
17+ void *rpc_allocate (uint64_t size) {
18+ void *ptr = nullptr ;
19+ rpc::Client::Port port = rpc::client.open <RPC_MALLOC>();
20+ port.send_and_recv ([=](rpc::Buffer *buffer) { buffer->data [0 ] = size; },
21+ [&](rpc::Buffer *buffer) {
22+ ptr = reinterpret_cast <void *>(buffer->data [0 ]);
23+ });
24+ port.close ();
25+ return ptr;
26+ }
27+
28+ void rpc_free (void *ptr) {
29+ rpc::Client::Port port = rpc::client.open <RPC_FREE>();
30+ port.send ([=](rpc::Buffer *buffer) {
31+ buffer->data [0 ] = reinterpret_cast <uintptr_t >(ptr);
32+ });
33+ port.close ();
34+ }
35+
36+ } // namespace
37+
38+ namespace gpu {
39+
40+ void *allocate (uint64_t size) { return rpc_allocate (size); }
41+
42+ void deallocate (void *ptr) { rpc_free (ptr); }
43+
44+ } // namespace gpu
45+ } // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change 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+ // ===----------------------------------------------------------------------===//
8+
9+ #ifndef LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H
10+ #define LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H
11+
12+ #include < stdint.h>
13+
14+ namespace LIBC_NAMESPACE {
15+ namespace gpu {
16+
17+ void *allocate (uint64_t size);
18+ void deallocate (void *ptr);
19+
20+ } // namespace gpu
21+ } // namespace LIBC_NAMESPACE
22+
23+ #endif // LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ add_entrypoint_object(
66 ../malloc.h
77 DEPENDS
88 libc.include .stdlib
9- libc.src.__support.RPC.rpc_client
9+ libc.src.__support.GPU.allocator
1010)
1111
1212add_entrypoint_object(
@@ -28,5 +28,5 @@ add_entrypoint_object(
2828 ../abort.h
2929 DEPENDS
3030 libc.include .stdlib
31- libc.src.__support.RPC.rpc_client
31+ libc.src.__support.GPU.allocator
3232)
Original file line number Diff line number Diff line change 77// ===----------------------------------------------------------------------===//
88
99#include " src/stdlib/free.h"
10- #include " src/__support/RPC/rpc_client.h"
10+
11+ #include " src/__support/GPU/allocator.h"
1112#include " src/__support/common.h"
1213
1314namespace LIBC_NAMESPACE {
1415
15- LLVM_LIBC_FUNCTION (void , free, (void *ptr)) {
16- rpc::Client::Port port = rpc::client.open <RPC_FREE>();
17- port.send ([=](rpc::Buffer *buffer) {
18- buffer->data [0 ] = reinterpret_cast <uintptr_t >(ptr);
19- });
20- port.close ();
21- }
16+ LLVM_LIBC_FUNCTION (void , free, (void *ptr)) { gpu::deallocate (ptr); }
2217
2318} // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change 77// ===----------------------------------------------------------------------===//
88
99#include " src/stdlib/malloc.h"
10- #include " src/__support/RPC/rpc_client.h"
10+
11+ #include " src/__support/GPU/allocator.h"
1112#include " src/__support/common.h"
1213
1314namespace LIBC_NAMESPACE {
1415
1516LLVM_LIBC_FUNCTION (void *, malloc, (size_t size)) {
16- void *ptr = nullptr ;
17- rpc::Client::Port port = rpc::client.open <RPC_MALLOC>();
18- port.send_and_recv ([=](rpc::Buffer *buffer) { buffer->data [0 ] = size; },
19- [&](rpc::Buffer *buffer) {
20- ptr = reinterpret_cast <void *>(buffer->data [0 ]);
21- });
22- port.close ();
23- return ptr;
17+ return gpu::allocate (size);
2418}
2519
2620} // namespace LIBC_NAMESPACE
You can’t perform that action at this time.
0 commit comments