xref: /aosp_15_r20/external/pytorch/c10/xpu/XPUException.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1*da0073e9SAndroid Build Coastguard Worker #pragma once
2*da0073e9SAndroid Build Coastguard Worker 
3*da0073e9SAndroid Build Coastguard Worker #include <c10/util/Exception.h>
4*da0073e9SAndroid Build Coastguard Worker #include <sycl/sycl.hpp>
5*da0073e9SAndroid Build Coastguard Worker 
6*da0073e9SAndroid Build Coastguard Worker namespace c10::xpu {
7*da0073e9SAndroid Build Coastguard Worker 
8*da0073e9SAndroid Build Coastguard Worker static inline sycl::async_handler asyncHandler = [](sycl::exception_list el) {
9*da0073e9SAndroid Build Coastguard Worker   if (el.size() == 0) {
10*da0073e9SAndroid Build Coastguard Worker     return;
11*da0073e9SAndroid Build Coastguard Worker   }
12*da0073e9SAndroid Build Coastguard Worker   for (const auto& e : el) {
13*da0073e9SAndroid Build Coastguard Worker     try {
14*da0073e9SAndroid Build Coastguard Worker       std::rethrow_exception(e);
catch(sycl::exception & e)15*da0073e9SAndroid Build Coastguard Worker     } catch (sycl::exception& e) {
16*da0073e9SAndroid Build Coastguard Worker       TORCH_WARN("SYCL Exception: ", e.what());
17*da0073e9SAndroid Build Coastguard Worker     }
18*da0073e9SAndroid Build Coastguard Worker   }
19*da0073e9SAndroid Build Coastguard Worker   throw;
20*da0073e9SAndroid Build Coastguard Worker };
21*da0073e9SAndroid Build Coastguard Worker 
22*da0073e9SAndroid Build Coastguard Worker } // namespace c10::xpu
23