-
Notifications
You must be signed in to change notification settings - Fork 438
[TransferEngine][WIP]heterogeneous-tcp #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AscendTransport
wants to merge
1
commit into
kvcache-ai:main
Choose a base branch
from
AscendTransport:ascend-tcp-agg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
114 changes: 114 additions & 0 deletions
114
mooncake-transfer-engine/include/transport/ascend_transport/heterogeneous_tcp_transport.h
This file contains hidden or 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,114 @@ | ||
| // Copyright 2025 Huawei Technologies Co., Ltd | ||
| // Copyright 2024 KVCache.AI | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef HETEROGENEOUS_TCP_TRANSPORT_H_ | ||
| #define HETEROGENEOUS_TCP_TRANSPORT_H_ | ||
|
|
||
| #include "transport/tcp_transport/tcp_transport.h" | ||
| #include "acl/acl.h" | ||
| #include <atomic> | ||
| #include <new> | ||
| #include <condition_variable> | ||
|
|
||
| #define HUGE_HOST_SIZE (3ULL * 1024 * 1024 * 1024) | ||
| #define HUGE_DEVICE_SIZE (8 * 1024 * 1024) | ||
| #define HUGE_DEVICE_NUM 4 | ||
|
|
||
| namespace mooncake { | ||
|
|
||
| class HeterogeneousTcpTransport : public Transport { | ||
| public: | ||
| HeterogeneousTcpTransport(); | ||
|
|
||
| ~HeterogeneousTcpTransport(); | ||
|
|
||
| int install(std::string &local_server_name, | ||
| std::shared_ptr<TransferMetadata> meta, | ||
| std::shared_ptr<Topology> topo) override; | ||
|
|
||
| const char *getName() const override { return "ascend"; } | ||
|
|
||
| int registerLocalMemory(void *addr, size_t length, | ||
| const std::string &location, bool remote_accessible, | ||
| bool update_metadata) override; | ||
|
|
||
| int unregisterLocalMemory(void *addr, bool update_metadata = true) override; | ||
|
|
||
| int registerLocalMemoryBatch(const std::vector<BufferEntry> &buffer_list, | ||
| const std::string &location) override; | ||
|
|
||
| int unregisterLocalMemoryBatch( | ||
| const std::vector<void *> &addr_list) override; | ||
|
|
||
| int createStream(); | ||
|
|
||
| Status submitTransfer(BatchID batch_id, | ||
| const std::vector<TransferRequest> &entries) override; | ||
|
|
||
| Status submitTransferTask( | ||
| const std::vector<TransferTask *> &task_list) override; | ||
|
|
||
| Status getTransferStatus(BatchID batch_id, size_t task_id, | ||
| TransferStatus &status) override; | ||
| std::unique_ptr<TcpTransport> transport_{}; | ||
|
|
||
| private: | ||
| void transferLoop(); | ||
|
|
||
| private: | ||
| struct TransferTaskTCP { | ||
| std::vector<TransferTask *> tasks; | ||
| uint64_t total_length; | ||
| uint64_t devId; | ||
|
|
||
| TransferTaskTCP(TransferTaskTCP &&) = default; | ||
| TransferTaskTCP &operator=(TransferTaskTCP &&) = default; | ||
|
|
||
| TransferTaskTCP(const TransferTaskTCP &) = delete; | ||
| TransferTaskTCP &operator=(const TransferTaskTCP &) = delete; | ||
|
|
||
| TransferTaskTCP(std::vector<TransferTask *> taskList, uint64_t len, | ||
| uint64_t id) | ||
| : tasks(std::move(taskList)), total_length(len), devId(id) {} | ||
| }; | ||
| bool running_ = false; | ||
| aclrtStream stream_; | ||
| void *hostAddr_ = nullptr; | ||
| void *devAddr_ = nullptr; | ||
| std::vector<void *> hugeDevAddrs; | ||
| int deviceLogicId_; | ||
| bool firstSubmit_ = true; | ||
| std::mutex memcpy_mutex_; | ||
| uint64_t offset_ = 0; | ||
| std::thread transferThread_; | ||
| std::queue<TransferTaskTCP> transferQueues_; | ||
| std::mutex transfer_mutex_; | ||
| std::condition_variable transfer_cond_; | ||
| std::atomic<int> transfer_counter_{0}; | ||
| int devId_ = 0; | ||
| std::array<bool, HUGE_DEVICE_NUM> mem_blocks = {false, false, false, false}; | ||
| std::mutex dev_mtx_; | ||
| std::condition_variable dev_cv_; | ||
| }; | ||
|
|
||
| using TransferRequest = Transport::TransferRequest; | ||
| using TransferStatus = Transport::TransferStatus; | ||
| using TransferStatusEnum = Transport::TransferStatusEnum; | ||
| using SegmentID = Transport::SegmentID; | ||
| using BatchID = Transport::BatchID; | ||
|
|
||
| } // namespace mooncake | ||
|
|
||
| #endif // HETEROGENEOUS_TCP_TRANSPORT_H_ |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
else ifblock is conditional onUSE_ASCEND_HETEROGENEOUS_TCP, but it's syntactically attached to the precedingif-else ifchain. IfUSE_ASCEND_HETEROGENEOUSis disabled, thiselse ifwill be dangling and cause a compilation error. The entire block for selecting anascendtransport should be restructured to handle the mutually exclusive options correctly, for example by using a singleif-else ifchain with#if/#elif/#endifpreprocessor directives to ensure correctness regardless of which flags are enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed