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(
12
12
DEPENDS
13
13
${target_gpu_utils}
14
14
)
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(
6
6
../malloc.h
7
7
DEPENDS
8
8
libc.include.stdlib
9
- libc.src.__support.RPC.rpc_client
9
+ libc.src.__support.GPU.allocator
10
10
)
11
11
12
12
add_entrypoint_object (
@@ -28,5 +28,5 @@ add_entrypoint_object(
28
28
../abort.h
29
29
DEPENDS
30
30
libc.include.stdlib
31
- libc.src.__support.RPC.rpc_client
31
+ libc.src.__support.GPU.allocator
32
32
)
Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " src/stdlib/free.h"
10
- #include " src/__support/RPC/rpc_client.h"
10
+
11
+ #include " src/__support/GPU/allocator.h"
11
12
#include " src/__support/common.h"
12
13
13
14
namespace LIBC_NAMESPACE {
14
15
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); }
22
17
23
18
} // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change 7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " src/stdlib/malloc.h"
10
- #include " src/__support/RPC/rpc_client.h"
10
+
11
+ #include " src/__support/GPU/allocator.h"
11
12
#include " src/__support/common.h"
12
13
13
14
namespace LIBC_NAMESPACE {
14
15
15
16
LLVM_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);
24
18
}
25
19
26
20
} // namespace LIBC_NAMESPACE
You can’t perform that action at this time.
0 commit comments