8000 Revert "Enable XPUEvent elapsed_time function (#134666)" (#140872) · pytorch/pytorch@62d2c5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 62d2c5b

Browse files
guangyeypytorchmergebot
authored andcommitted
Revert "Enable XPUEvent elapsed_time function (#134666)" (#140872)
# Motivation This PR raises an internal UT failure on XPU. This reverts commit 4bbd6da. # Additional Context refer to #140814 Pull Request resolved: #140872 Approved by: https://github.com/EikanWang
1 parent 3d26c08 commit 62d2c5b

File tree

3 files changed

+21
-85
lines changed

3 files changed

+21
-85
lines changed

aten/src/ATen/xpu/XPUEvent.h

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ struct TORCH_XPU_API XPUEvent {
8585
void record(const XPUStream& stream) {
8686
if (!isCreated()) {
8787
device_index_ = stream.device_index();
88-
assignEvent(stream.queue());
88+
event_ = std::make_unique<sycl::event>(
89+
stream.queue().ext_oneapi_submit_barrier());
8990
const c10::impl::PyInterpreter* interp = c10::impl::GPUTrace::get_trace();
9091
if (C10_UNLIKELY(interp)) {
9192
(*interp)->trace_gpu_event_creation(
@@ -99,7 +100,9 @@ struct TORCH_XPU_API XPUEvent {
99100
" does not match recording stream's device ",
100101
stream.device_index(),
101102
".");
102-
reassignEvent(stream.queue());
103+
event_.reset();
104+
event_ = std::make_unique<sycl::event>(
105+
stream.queue().ext_oneapi_submit_barrier());
103106
}
104107
const c10::impl::PyInterpreter* interp = c10::impl::GPUTrace::get_trace();
105108
if (C10_UNLIKELY(interp)) {
@@ -125,7 +128,7 @@ struct TORCH_XPU_API XPUEvent {
125128
}
126129
}
127130

128-
double elapsed_time(const XPUEvent& other) const {
131+
float elapsed_time(const XPUEvent& other) const {
129132
TORCH_CHECK(
130133
isCreated() && other.isCreated(),
131134
"Both events must be recorded before calculating elapsed time.");
@@ -135,20 +138,10 @@ struct TORCH_XPU_API XPUEvent {
135138
TORCH_CHECK(
136139
enable_timing_ && other.enable_timing_,
137140
"Both events must be created with argument 'enable_timing=True'.");
138-
139-
#if SYCL_COMPILER_VERSION < 20250000
141+
// TODO: provides the ability to time the execution of commands in a SYCL
142+
// queue without enabling profiling on the entire queue
140143
TORCH_CHECK_NOT_IMPLEMENTED(
141-
false,
142-
"elapsed_time of XPUEvent requires PyTorch to be built with SYCL compiler version 2025.0.0 or newer.");
143-
#endif
144-
145-
using namespace sycl::info::event_profiling;
146-
// Block until both of the recorded events are completed.
147-
uint64_t end_time_ns = other.event().get_profiling_info<command_end>();
148-
uint64_t start_time_ns = event().get_profiling_info<command_end>();
149-
// Return the elapsed time in milliseconds.
150-
return 1e-6 *
151-
(static_cast<double>(end_time_ns) - static_cast<double>(start_time_ns));
144+
false, "elapsed_time is not supported by XPUEvent.");
152145
}
153146

154147
void synchronize() const {
@@ -163,24 +156,6 @@ struct TORCH_XPU_API XPUEvent {
163156
}
164157

165158
private:
166-
void assignEvent(sycl::queue& queue) {
167-
#if SYCL_COMPILER_VERSION >= 20250000
168-
if (enable_timing_) {
169-
event_ = std::make_unique<sycl::event>(
170-
sycl::ext::oneapi::experimental::submit_profiling_tag(queue));
171-
} else {
172-
event_ = std::make_unique<sycl::event>(queue.ext_oneapi_submit_barrier());
173-
}
174-
#else
175-
event_ = std::make_unique<sycl::event>(queue.ext_oneapi_submit_barrier());
176-
#endif
177-
}
178-
179-
void reassignEvent(sycl::queue& queue) {
180-
event_.reset();
181-
assignEvent(queue);
182-
}
183-
184159
bool enable_timing_ = false;
185160
DeviceIndex device_index_ = -1;
186161
// Only need to track the last event, as events in an in-order queue are

c10/xpu/impl/XPUGuardImpl.h

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,6 @@ struct XPUGuardImpl final : public c10::impl::DeviceGuardImplInterface {
140140
event_command_status::complete;
141141
}
142142

143-
double elapsedTime(
144-
void* start_event,
145-
void* end_event,
146-
const DeviceIndex device_index) const override {
147-
#if SYCL_COMPILER_VERSION < 20250000
148-
TORCH_CHECK_NOT_IMPLEMENTED(
149-
false,
150-
"elapsedTime requires PyTorch to be built with SYCL compiler version 2025.0.0 or newer.");
151-
#endif
152-
TORCH_CHECK(
153-
start_event && end_event,
154-
"Both events must be recorded before calculating elapsed time.");
155-
auto* xpu_start_event = reinterpret_cast<sycl::event*>(start_event);
156-
auto* xpu_end_event = reinterpret_cast<sycl::event*>(end_event);
157-
158-
using namespace sycl::info::event_profiling;
159-
// Block until both of the recorded events are completed.
160-
uint64_t end_time_ns = xpu_end_event->get_profiling_info<command_end>();
161-
uint64_t start_time_ns = xpu_start_event->get_profiling_info<command_end>();
162-
// Return the elapsed time in milliseconds.
163-
return 1e-6 *
164-
(static_cast<double>(end_time_ns) - static_cast<double>(start_time_ns));
165-
}
166-
167143
// Stream-related functions
168144
bool queryStream(const Stream& stream) const override {
169145
const XPUStream xpu_stream{stream};
@@ -200,6 +176,12 @@ struct XPUGuardImpl final : public c10::impl::DeviceGuardImplInterface {
200176
const XPUStream xpu_stream{stream};
201177
XPUCachingAllocator::recordStream(data_ptr, xpu_stream);
202178
}
179+
180+
double elapsedTime(void* event1, void* event2, const DeviceIndex device_index)
181+
const override {
182+
TORCH_CHECK_NOT_IMPLEMENTED(
183+
false, "elapsedTime is not supported by XPU backend.");
184+
}
203185
};
204186

205187
} // namespace c10::xpu::impl

test/test_xpu.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44
import sys
55
import tempfile
6-
import time
76
import unittest
87

98
import torch
@@ -236,21 +235,6 @@ def test_events(self):
236235
stream.record_event(event)
237236
event.synchronize()
238237
self.assertTrue(event.query())
239-
start_event = torch.xpu.Event(enable_timing=True)
240-
end_event = torch.xpu.Event(enable_timing=True)
241-
stream.record_event(start_event)
242-
time.sleep(0.1)
243-
stream.record_event(end_event)
244-
torch.xpu.synchronize()
245-
if int(torch.version.xpu) >= 20250000:
246-
self.assertGreater(start_event.elapsed_time(end_event), 0)
247-
self.assertLess(end_event.elapsed_time(start_event), 0)
248-
else:
249-
with self.assertRaisesRegex(
250-
NotImplementedError,
251-
"elapsed_time of XPUEvent requires PyTorch to be built with SYCL compiler version 2025.0.0 or newer.",
252-
):
253-
start_event.elapsed_time(end_event)
254238

255239
def test_generic_stream_event(self):
256240
stream = torch.Stream("xpu")
@@ -266,8 +250,8 @@ def test_generic_stream_event(self):
266250
self.assertEqual(stream.stream_id, xpu_stream.stream_id)
267251
self.assertNotEqual(stream.stream_id, torch.xpu.current_stream().stream_id)
268252

269-
event1 = torch.Event("xpu", enable_timing=True)
270-
event2 = torch.Event("xpu", enable_timing=True)
253+
event1 = torch.Event("xpu")
254+
event2 = torch.Event("xpu")
271255
self.assertEqual(event1.event_id, 0)
272256
a = torch.randn(1000)
273257
b = torch.randn(1000)
@@ -284,15 +268,10 @@ def test_generic_stream_event(self):
284268
self.assertTrue(event2.query())
285269
self.assertNotEqual(event1.event_id, event2.event_id)
286270
self.assertEqual(c_xpu.cpu(), a + b)
287-
if int(torch.version.xpu) >= 20250000:
288-
self.assertGreater(event1.elapsed_time(event2), 0)
289-
self.assertLess(event2.elapsed_time(event1), 0)
290-
else:
291-
with self.assertRaisesRegex(
292-
NotImplementedError,
293-
"elapsedTime requires PyTorch to be built with SYCL compiler version 2025.0.0 or newer.",
294-
):
295-
event1.elapsed_time(event2)
271+
with self.assertRaisesRegex(
272+
NotImplementedError, "elapsedTime is not supported by XPU backend."
273+
):
274+
event1.elapsed_time(event2)
296275
xpu_event = torch.xpu.Event()
297276
self.assertIsInstance(xpu_event, torch.Event)
298277
self.assertTrue(issubclass(type(xpu_event), torch.Event))

0 commit comments

Comments
 (0)
0