Skip to content

[Custom Device] Fix a bug in CUDA Graph invocation related to the cus… - #77226

Merged
ZhangX-21 merged 1 commit into
PaddlePaddle:developfrom
ZhangX-21:fix_cuda_graph_bug
Jan 14, 2026
Merged

ZhangX-21 merged 1 commit into
PaddlePaddle:developfrom
ZhangX-21:fix_cuda_graph_bug

Conversation

@ZhangX-21

Copy link
Copy Markdown
Contributor

PR Category

Custom Device

PR Types

Bug fixes

Description

Fix a bug in CUDA Graph invocation related to the custom device lifecycle
Pcard-90546

@paddle-bot

paddle-bot Bot commented Jan 6, 2026

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@ZhangX-21
ZhangX-21 force-pushed the fix_cuda_graph_bug branch 5 times, most recently from ae6f2e2 to 7ac49d5 Compare January 7, 2026 06:59
@codecov-commenter

codecov-commenter commented Jan 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@4ff6cb2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...dle/phi/core/memory/allocation/allocator_facade.cc 66.66% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #77226   +/-   ##
==========================================
  Coverage           ?   66.66%           
==========================================
  Files              ?        1           
  Lines              ?        9           
  Branches           ?        0           
==========================================
  Hits               ?        6           
  Misses             ?        3           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZhangX-21
ZhangX-21 force-pushed the fix_cuda_graph_bug branch 4 times, most recently from 4edd9d6 to bacb9e1 Compare January 7, 2026 15:49
@ZhangX-21

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ZhangX-21
ZhangX-21 force-pushed the fix_cuda_graph_bug branch 3 times, most recently from 5224b04 to 03a7b47 Compare January 8, 2026 06:43
@ZhangX-21

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ZhangX-21

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@yongqiangma yongqiangma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

paddle::optional<std::thread::id> CUDAGraph::capturing_thread_id_{paddle::none};
std::vector<std::function<void()>> CUDAGraph::cudagraph_pre_capture_callbacks_;

std::vector<CUDAGraph *> g_cuda_graph;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

为什么需要单独增加全局参数,公用之前GPU上的参数不可以吗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GPU在处理CudaGraph的析构函数的时候处理对应CUDAGraph::Reset()函数,不用考虑DeviceManager的生命周期。在多设备的时候抽象接口都是由DeviceManager来管理,所以依赖其生命周期。如果没有主动的调用reset()函数,在Python文件执行结束会调用一次析构函数,造成Reset函数中DeviceManager中的抽象接口超过生命周期,造成segement fault。所以通过 g_cuda_graph在维护cudagraph的Reset的资源管理。在DeviceManager释放资源之前提前把cudagraph的资源释放掉。

@ZhangX-21

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@sneaxiy sneaxiy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ZhangX-21

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@ZhangX-21
ZhangX-21 merged commit 09a7322 into PaddlePaddle:develop Jan 14, 2026
157 of 169 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants