-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc][NFC] Move GPU allocator implementation to common header (#84690)
Summary: This is a NFC move preceding more radical functional changes to the allocator implementation. We just move it to a common utility so it will be easier to write these in tandem.
- Loading branch information
Showing
6 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===-- GPU memory allocator implementation ---------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "allocator.h" | ||
|
||
#include "src/__support/GPU/utils.h" | ||
#include "src/__support/RPC/rpc_client.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
namespace { | ||
|
||
void *rpc_allocate(uint64_t size) { | ||
void *ptr = nullptr; | ||
rpc::Client::Port port = rpc::client.open<RPC_MALLOC>(); | ||
port.send_and_recv([=](rpc::Buffer *buffer) { buffer->data[0] = size; }, | ||
[&](rpc::Buffer *buffer) { | ||
ptr = reinterpret_cast<void *>(buffer->data[0]); | ||
}); | ||
port.close(); | ||
return ptr; | ||
} | ||
|
||
void rpc_free(void *ptr) { | ||
rpc::Client::Port port = rpc::client.open<RPC_FREE>(); | ||
port.send([=](rpc::Buffer *buffer) { | ||
buffer->data[0] = reinterpret_cast<uintptr_t>(ptr); | ||
}); | ||
port.close(); | ||
} | ||
|
||
} // namespace | ||
|
||
namespace gpu { | ||
|
||
void *allocate(uint64_t size) { return rpc_allocate(size); } | ||
|
||
void deallocate(void *ptr) { rpc_free(ptr); } | ||
|
||
} // namespace gpu | ||
} // namespace LIBC_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- GPU memory allocator implementation ---------------------*- 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 LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H | ||
#define LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H | ||
|
||
#include <stdint.h> | ||
|
||
namespace LIBC_NAMESPACE { | ||
namespace gpu { | ||
|
||
void *allocate(uint64_t size); | ||
void deallocate(void *ptr); | ||
|
||
} // namespace gpu | ||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC___SUPPORT_GPU_ALLOCATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters