-
Notifications
You must be signed in to change notification settings - Fork 393
[TransferEngine] Use dynamic loader to support tcp over cuda #925
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @alogfans, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a GpuRuntime
class to dynamically load CUDA/MUSA libraries and handle GPU memory transfers without requiring compile-time linking. This is a good approach to make the binary more portable. The changes correctly adapt writeBody
and readBody
to use this new dynamic loading mechanism. I have a few suggestions to improve code clarity and maintainability, such as replacing std::cout
with structured logging, defining constants for magic numbers, and simplifying some logic.
reinterpret_cast<MemcpyFn>(dlsym(handle_, "musaMemcpy")); | ||
|
||
if (pGetAttr_ && pMemcpy_) { | ||
std::cout << "[GpuRuntime] Loaded GPU runtime: " << lib << "\n"; |
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.
gpu.copy(dram_buffer, addr + total_transferred_bytes_, buffer_size, | ||
4); |
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.
The magic number 4
corresponds to cudaMemcpyDefault
. To improve readability and maintainability, it's better to define this as a named constant in the GpuRuntime
class and use it here. A similar change should be applied in readBody
as well.
For example, you can add this to GpuRuntime
:
static constexpr int kMemcpyDefault = 4; // cudaMemcpyDefault
gpu.copy(dram_buffer, addr + total_transferred_bytes_, buffer_size, | |
4); | |
gpu.copy(dram_buffer, addr + total_transferred_bytes_, buffer_size, | |
GpuRuntime::kMemcpyDefault); |
if (isCudaMemory(addr)) { | ||
auto &gpu = GpuRuntime::instance(); | ||
gpu.copy(addr + total_transferred_bytes_, dram_buffer, | ||
transferred_bytes, 4); | ||
if (is_cuda_memory) delete[] dram_buffer; | ||
} |
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.
The logic in this #else
block can be simplified. The is_cuda_memory
variable is already captured by the lambda and holds the result of isCudaMemory(addr)
, so you can use it in the if
condition to avoid a redundant function call. Additionally, the inner if (is_cuda_memory)
check before delete[] dram_buffer
is redundant.
I'd also recommend using a named constant for the magic number 4
as mentioned in another comment.
if (isCudaMemory(addr)) { | |
auto &gpu = GpuRuntime::instance(); | |
gpu.copy(addr + total_transferred_bytes_, dram_buffer, | |
transferred_bytes, 4); | |
if (is_cuda_memory) delete[] dram_buffer; | |
} | |
if (is_cuda_memory) { | |
auto &gpu = GpuRuntime::instance(); | |
gpu.copy(addr + total_transferred_bytes_, dram_buffer, | |
transferred_bytes, 4 /* kMemcpyDefault */); | |
delete[] dram_buffer; | |
} |
No description provided.