XPUGraphsC10Utils.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. #pragma once
  3. #include <c10/xpu/XPUStream.h>
  4. #include <iostream>
  5. // XPU Graphs utils used by c10 and aten.
  6. using namespace sycl::ext::oneapi::experimental;
  7. namespace c10::xpu {
  8. static_assert(
  9. int8_t(queue_state::executing) == 0,
  10. "unexpected int(queue_state::executing) value");
  11. static_assert(
  12. int8_t(queue_state::recording) == 1,
  13. "unexpected int(queue_state::recording) value");
  14. enum class CaptureStatus : int8_t {
  15. Executing = int8_t(queue_state::executing),
  16. Recording = int8_t(queue_state::recording)
  17. };
  18. inline std::ostream& operator<<(std::ostream& os, CaptureStatus status) {
  19. switch (status) {
  20. case CaptureStatus::Executing:
  21. os << "Executing";
  22. break;
  23. case CaptureStatus::Recording:
  24. os << "Recording";
  25. break;
  26. default:
  27. TORCH_INTERNAL_ASSERT(
  28. false, "Unknown XPU graph CaptureStatus", int(status));
  29. }
  30. return os;
  31. }
  32. inline CaptureStatus currentStreamCaptureStatusMayInitCtx() {
  33. auto state = c10::xpu::getCurrentXPUStream().queue().ext_oneapi_get_state();
  34. return CaptureStatus(state);
  35. }
  36. } // namespace c10::xpu
  37. #else
  38. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  39. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)