mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[XPU] Add an implict conversion from XPUStream to sycl::queue* (#148646)
# Motivation Currently, in Pytorch XPU, `cudaStream_t` is mapped to `sycl::queue&`, so an implicit cast from `XPUStream` to `sycl::queue&` is provided just like `CUDAStream` has an implicit cast to `cudaStream_t`. But on the SYCLomatic side, we migrate `cudaStream_t` to `sycl::queue*` but not `sycl::queue&` (One reason is that `cudaStream_t` is actually a pointer so users can do anything with that integer. Another reason is that the early `sycl::queue` was not impl-ed by a pointer, so copy by value is not desirable.) Without this PR: ``` cudaStream_t a = getCurrentCUDAStream(); cudaStream_t b = getCurrentCUDAStream().stream(); ``` need be migrated to: ``` queue_ptr a = &(sycl::queue&)getCurrentXPUStream(); queue_ptr b = &(getCurrentXPUStream().queue()); ``` With this PR: ``` queue_ptr a = getCurrentXPUStream(); queue_ptr b = &(getCurrentXPUStream().queue()); ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/148646 Approved by: https://github.com/guangyey, https://github.com/EikanWang
This commit is contained in:
parent
c067127d47
commit
9e106019f6
|
|
@ -59,6 +59,11 @@ class C10_XPU_API XPUStream {
|
|||
return queue();
|
||||
}
|
||||
|
||||
/// Implicit conversion to sycl::queue*.
|
||||
operator sycl::queue*() const {
|
||||
return &queue();
|
||||
}
|
||||
|
||||
/// Implicit conversion to Stream (a.k.a., forget that the stream is a
|
||||
/// XPU stream).
|
||||
operator Stream() const {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,9 @@ TEST(XPUStreamTest, ExternalTest) {
|
|||
ASSERT_TRUE(curStream == myStream);
|
||||
ASSERT_TRUE(&(curStream.queue()) == stream);
|
||||
|
||||
sycl::queue* q_ptr = curStream;
|
||||
ASSERT_TRUE(q_ptr == stream);
|
||||
|
||||
delete stream;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user