Skip to content

Fix async error reporting and memory type handling in CCLAdaptor and DeviceAdaptor - #266

Merged
MC952-arch merged 2 commits into
flagos-ai:mainfrom
MC952-arch:bug-fix
Oct 15, 2025
Merged

Fix async error reporting and memory type handling in CCLAdaptor and DeviceAdaptor#266
MC952-arch merged 2 commits into
flagos-ai:mainfrom
MC952-arch:bug-fix

Conversation

@MC952-arch

@MC952-arch MC952-arch commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

This PR addresses two key issues:

  • Asynchronous Error Reporting: corrected the asyncError parameter in all CommGetAsyncError functions across CCLAdaptors and the main flagcx API. The parameter is now passed by pointer (flagcxResult_t *asyncError) instead of by value, ensuring that asynchronous error results are properly returned to the caller.
  • Memory Type Handling: ensured that DeviceMalloc/Free APIs consistently use flagcxMemDevice as the default memory type, preventing ambiguity in memory allocation and deallocation across DeviceAdaptors.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @MC952-arch, 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 addresses several critical bug fixes within the flagcx framework. The primary focus is on enhancing the reliability of asynchronous error reporting by correcting parameter passing mechanisms and resolving a logical flaw in how different memory types are handled during device memory operations. These changes improve the robustness and correctness of the underlying communication and device management layers.

Highlights

  • Asynchronous Error Reporting Fix: Corrected the asyncError parameter in all CommGetAsyncError functions across various Collective Communication Library (CCL) adaptors and the main flagcx API. The parameter is now passed by pointer (flagcxResult_t *asyncError) instead of by value, ensuring that asynchronous error results are properly returned to the caller.
  • Memory Type Handling Logic Correction: Refactored the memory allocation (DeviceMalloc) and deallocation (DeviceFree) functions within several device adaptors. The conditional logic for handling flagcxMemManaged memory types was reordered to ensure it is checked before the generic flagcxMemDevice type, preventing incorrect memory management calls.
Ignored Files
  • Ignored by pattern: .github/workflows/** (3)
    • .github/workflows/test.yml
    • .github/workflows/torch-api-test.yml
    • .github/workflows/unit-test.yml
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 several bug fixes. The main fix corrects the signature of flagcxCommGetAsyncError across multiple files, changing an output parameter from pass-by-value to pass-by-pointer. This ensures that the asynchronous error status is correctly propagated to the caller. Additionally, the memory allocation and deallocation logic in several device adaptors has been refactored. While the refactoring is good, I've suggested making the conditional logic more explicit to improve code clarity and robustness against future changes.

Comment thread flagcx/adaptor/device/cuda_adaptor.cc
Comment on lines +66 to 72
} else {
if (stream == NULL) {
DEVCHECK(cudaFree(ptr));
} else {
DEVCHECK(cudaFreeAsync(ptr, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(cudaFree(ptr));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity and robustness, it's better to explicitly check for flagcxMemDevice rather than relying on an else block. This makes the code easier to understand and safer if new flagcxMemType_t values are added in the future.

  } else if (type == flagcxMemDevice) {
    if (stream == NULL) {
      DEVCHECK(cudaFree(ptr));
    } else {
      DEVCHECK(cudaFreeAsync(ptr, stream->base));
    }
  }

Comment thread flagcx/adaptor/device/ducuda_adaptor.cc
Comment on lines +66 to 72
} else {
if (stream == NULL) {
DEVCHECK(cudaFree(ptr));
} else {
DEVCHECK(cudaFreeAsync(ptr, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(cudaFree(ptr));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity and robustness, it's better to explicitly check for flagcxMemDevice rather than relying on an else block. This makes the code easier to understand and safer if new flagcxMemType_t values are added in the future.

Suggested change
} else {
if (stream == NULL) {
DEVCHECK(cudaFree(ptr));
} else {
DEVCHECK(cudaFreeAsync(ptr, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(cudaFree(ptr));
}
} else if (type == flagcxMemDevice) {
if (stream == NULL) {
DEVCHECK(cudaFree(ptr));
} else {
DEVCHECK(cudaFreeAsync(ptr, stream->base));
}
}

Comment thread flagcx/adaptor/device/hip_adaptor.cc
Comment thread flagcx/adaptor/device/kunlunxin_adaptor.cc
Comment on lines +55 to 61
} else {
if (stream == NULL) {
DEVCHECK(mcMalloc(ptr, size));
} else {
DEVCHECK(mcMallocAsync(ptr, size, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(mcMallocManaged(ptr, size, mcMemAttachGlobal));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity and robustness, it's better to explicitly check for flagcxMemDevice rather than relying on an else block. This makes the code easier to understand and safer if new flagcxMemType_t values are added in the future.

Suggested change
} else {
if (stream == NULL) {
DEVCHECK(mcMalloc(ptr, size));
} else {
DEVCHECK(mcMallocAsync(ptr, size, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(mcMallocManaged(ptr, size, mcMemAttachGlobal));
}
} else if (type == flagcxMemDevice) {
if (stream == NULL) {
DEVCHECK(mcMalloc(ptr, size));
} else {
DEVCHECK(mcMallocAsync(ptr, size, stream->base));
}
}

Comment thread flagcx/adaptor/device/maca_adaptor.cc
Comment on lines +50 to 58
} else {
if (stream == NULL) {
DEVCHECK(musaMalloc(ptr, size));
} else {
DEVCHECK(musaMalloc(ptr, size));
// MUSA currently does not support async malloc
// DEVCHECK(musaMallocAsync(ptr, size, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(musaMallocManaged(ptr, size, musaMemAttachGlobal));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved clarity and robustness, it's better to explicitly check for flagcxMemDevice rather than relying on an else block. This makes the code easier to understand and safer if new flagcxMemType_t values are added in the future.

Suggested change
} else {
if (stream == NULL) {
DEVCHECK(musaMalloc(ptr, size));
} else {
DEVCHECK(musaMalloc(ptr, size));
// MUSA currently does not support async malloc
// DEVCHECK(musaMallocAsync(ptr, size, stream->base));
}
} else if (type == flagcxMemManaged) {
DEVCHECK(musaMallocManaged(ptr, size, musaMemAttachGlobal));
}
} else if (type == flagcxMemDevice) {
if (stream == NULL) {
DEVCHECK(musaMalloc(ptr, size));
} else {
DEVCHECK(musaMalloc(ptr, size));
// MUSA currently does not support async malloc
// DEVCHECK(musaMallocAsync(ptr, size, stream->base));
}
}

Comment thread flagcx/adaptor/device/musa_adaptor.cc
@MC952-arch MC952-arch changed the title Several bug fixes Fix async error reporting and memory type handling in CCLAdaptor and DeviceAdaptor Oct 2, 2025

@mikethegoblin mikethegoblin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yuejiewang yuejiewang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MC952-arch
MC952-arch merged commit 1fd15c0 into flagos-ai:main Oct 15, 2025
3 checks passed
@MC952-arch
MC952-arch deleted the bug-fix branch October 24, 2025 03:05
liuhe-spec pushed a commit to liuhe-spec/FlagCX that referenced this pull request Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants