Skip to content

Conversation

@runzhech
Copy link
Contributor

@runzhech runzhech commented Jul 9, 2025

PR Category

Custom Device

PR Types

New features

Description

支持python测调用xpu的stream、event等接口

@paddle-bot
Copy link

paddle-bot bot commented Jul 9, 2025

你的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.

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2025

Codecov Report

❌ Patch coverage is 27.27273% with 16 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@1987f7c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/device/__init__.py 27.27% 8 Missing ⚠️
python/paddle/device/xpu/__init__.py 20.00% 8 Missing ⚠️

❌ Your patch status has failed because the patch coverage (27.27%) 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   #73924   +/-   ##
==========================================
  Coverage           ?   27.27%           
==========================================
  Files              ?        3           
  Lines              ?       22           
  Branches           ?        0           
==========================================
  Hits               ?        6           
  Misses             ?       16           
  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.

@runzhech runzhech force-pushed the streams branch 5 times, most recently from 133617d to 67f6f1b Compare July 23, 2025 11:34

int64_t XPUContext::GetStreamNum() const { return impls_.size(); }

int XPUContext::SetCurrentStream(int idx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

如果 idx == prev_stream_idx,直接返回。

int prev_stream_idx = current_stream_idx;
impls_[0]->SetStream(stream_pool[idx]);
current_stream_idx = idx;
idle_stream_flags[prev_stream_idx] = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

idle_stream_flags[current_stream_idx] 设置为 false

break;
}
}
if (found_idle_stream) {
Copy link
Contributor

Choose a reason for hiding this comment

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

如果 found,还需要把 idle_stream_flags 对应位置设置为 false

@runzhech runzhech force-pushed the streams branch 6 times, most recently from 3f1f8c7 to 92bf114 Compare July 31, 2025 10:33
@runzhech runzhech force-pushed the streams branch 2 times, most recently from 469181a to 814126e Compare August 4, 2025 16:40
@runzhech
Copy link
Contributor Author

runzhech commented Aug 5, 2025

/re-run all-failed

Copy link
Contributor

@HarperCy HarperCy left a comment

Choose a reason for hiding this comment

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

LGTM

Return the current CUDA stream by the device.
Args:
device(paddle.CUDAPlace()|int|None, optional): The device or the ID of the device which want to get stream from.
Copy link
Contributor

Choose a reason for hiding this comment

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

paddle.XPU**

Copy link
Contributor

@cqulilujia cqulilujia left a comment

Choose a reason for hiding this comment

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

LGTM

@runzhech
Copy link
Contributor Author

runzhech commented Aug 5, 2025

/re-run all-failed

1 similar comment
@runzhech
Copy link
Contributor Author

runzhech commented Aug 6, 2025

/re-run all-failed

@runzhech runzhech force-pushed the streams branch 2 times, most recently from e68294a to 7a0e2cb Compare August 6, 2025 16:18
Copy link
Collaborator

@tianshuo78520a tianshuo78520a left a comment

Choose a reason for hiding this comment

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

Approve print

Copy link
Contributor

@yongqiangma yongqiangma left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM。 记得补充中文文档

@runzhech
Copy link
Contributor Author

runzhech commented Aug 7, 2025

/re-run all-failed

Copy link
Member

@tizhou86 tizhou86 left a comment

Choose a reason for hiding this comment

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

LGTM

} else {
impls_.push_back(std::make_unique<Impl>());
impls_[0]->Init(get_gm_size(0), get_l3_size(0));
stream_pool.push_back(impls_[0]->context_->get_stream());
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO:如果开启XPU_CDNN_CLUSTER_PARALLEL,则stream的相关接口就会有问题。

Copy link
Contributor

@dynamicheart dynamicheart left a comment

Choose a reason for hiding this comment

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

LGTM

paddle::platform::GetXPUCurrentDeviceId();
auto stream = paddle::platform::get_current_stream(device_id);
xpu_wait(stream);
xpu_wait(stream->raw_stream());
Copy link
Contributor

Choose a reason for hiding this comment

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

未检查返回值,下个PR修复

if (context_->xpu_stream != nullptr && stream_owned_) {
void SetStream(void* stream, bool clear = true) {
if (clear && context_->xpu_stream != nullptr && stream_owned_) {
xpu_stream_destroy(context_->xpu_stream);
Copy link
Contributor

Choose a reason for hiding this comment

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

未检查返回值,下个PR修复

phi::backends::xpu::XPUDeviceGuard guard(dev_idx);
xpu_event_destroy(event);
if (xpu_event_query(event) == XPU_SUCCESS) {
xpu_event_destroy(event);
Copy link
Contributor

Choose a reason for hiding this comment

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

未检查返回值,下个PR修复

@dynamicheart dynamicheart merged commit 97fd314 into PaddlePaddle:develop Aug 7, 2025
76 of 79 checks passed
@runzhech runzhech deleted the streams branch August 8, 2025 06:06
Enigmatisms pushed a commit to Enigmatisms/Paddle that referenced this pull request Aug 9, 2025
* [XPU] support python streams api for xpu

* [XPU] support python streams api for xpu

* [XPU] add stream & event unittests
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.