File: backend_exception.h

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (54 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <c10/util/Exception.h>

namespace c10 {
class TORCH_API BackendRuntimeException : public c10::Error {
 public:
  // Use debug_handle to throw exception
  BackendRuntimeException(
      SourceLocation loc,
      std::string msg,
      int64_t debug_handle)
      : c10::Error(loc, msg) {
    debug_handles.push_back(debug_handle);
  }
  // If rethrowing, can push another debug_handle
  // This is useful in couple of scenarios.
  // 1. A submodule is lowered and lite interperter has CallMethod
  //    to lowered module's method. In this case lowered module will throw with
  //    a handle, plus there will be another debug handle corresponding
  //    to the CallMethod node in lite interpreter. Both together give complete
  //    trace. This function allows lite interpreter to rethrow with debug
  //    handle it has for CallMethod.
  // 2. Another scenarios is when lite interperter can make function calls or
  //    the lowered backend also has function call ability. Thus we have
  //    multiple function frames. Now we need a stack of handles to symbolicate
  //    entire stack trace.
  void pushDebugHandle(int64_t debug_handle) {
    debug_handles.push_back(debug_handle);
  }
  const std::vector<int64_t>& getDebugHandles() {
    return debug_handles;
  }

 private:
  // Stores stack of debug handles.
  std::vector<int64_t> debug_handles;
};

} // namespace c10
#define TORCH_DELEGATED_BACKEND_THROW(cond, msg, debug_handle) \
  if (C10_UNLIKELY_OR_CONST(!(cond))) {                        \
    throw ::c10::BackendRuntimeException(                      \
        {__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, \
        msg,                                                   \
        debug_handle);                                         \
  }

#define TORCH_DELEGATED_BACKEND_RETHROW(e, debug_handle) \
  do {                                                   \
    e.pushDebugHandle(debug_handle);                     \
    throw;                                               \
  } while (false)

#define DEBUG_HANDLE_UNKNOWN -1