• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <ATen/native/vulkan/api/Exception.h>
2 
3 #include <sstream>
4 
5 namespace at {
6 namespace native {
7 namespace vulkan {
8 namespace api {
9 
10 #define VK_RESULT_CASE(code) \
11   case code:                 \
12     out << #code;            \
13     break;
14 
operator <<(std::ostream & out,const VkResult result)15 std::ostream& operator<<(std::ostream& out, const VkResult result) {
16   switch (result) {
17     VK_RESULT_CASE(VK_SUCCESS)
18     VK_RESULT_CASE(VK_NOT_READY)
19     VK_RESULT_CASE(VK_TIMEOUT)
20     VK_RESULT_CASE(VK_EVENT_SET)
21     VK_RESULT_CASE(VK_EVENT_RESET)
22     VK_RESULT_CASE(VK_INCOMPLETE)
23     VK_RESULT_CASE(VK_ERROR_OUT_OF_HOST_MEMORY)
24     VK_RESULT_CASE(VK_ERROR_OUT_OF_DEVICE_MEMORY)
25     VK_RESULT_CASE(VK_ERROR_INITIALIZATION_FAILED)
26     VK_RESULT_CASE(VK_ERROR_DEVICE_LOST)
27     VK_RESULT_CASE(VK_ERROR_MEMORY_MAP_FAILED)
28     VK_RESULT_CASE(VK_ERROR_LAYER_NOT_PRESENT)
29     VK_RESULT_CASE(VK_ERROR_EXTENSION_NOT_PRESENT)
30     VK_RESULT_CASE(VK_ERROR_FEATURE_NOT_PRESENT)
31     VK_RESULT_CASE(VK_ERROR_INCOMPATIBLE_DRIVER)
32     VK_RESULT_CASE(VK_ERROR_TOO_MANY_OBJECTS)
33     VK_RESULT_CASE(VK_ERROR_FORMAT_NOT_SUPPORTED)
34     VK_RESULT_CASE(VK_ERROR_FRAGMENTED_POOL)
35     default:
36       out << "VK_ERROR_UNKNOWN (VkResult " << result << ")";
37       break;
38   }
39   return out;
40 }
41 
42 #undef VK_RESULT_CASE
43 
44 //
45 // SourceLocation
46 //
47 
operator <<(std::ostream & out,const SourceLocation & loc)48 std::ostream& operator<<(std::ostream& out, const SourceLocation& loc) {
49   out << loc.function << " at " << loc.file << ":" << loc.line;
50   return out;
51 }
52 
53 //
54 // Exception
55 //
56 
Error(SourceLocation source_location,std::string msg)57 Error::Error(SourceLocation source_location, std::string msg)
58     : msg_(std::move(msg)), source_location_{source_location} {
59   std::ostringstream oss;
60   oss << "Exception raised from " << source_location_ << ": ";
61   oss << msg_;
62   what_ = oss.str();
63 }
64 
Error(SourceLocation source_location,const char * cond,std::string msg)65 Error::Error(SourceLocation source_location, const char* cond, std::string msg)
66     : msg_(std::move(msg)), source_location_{source_location} {
67   std::ostringstream oss;
68   oss << "Exception raised from " << source_location_ << ": ";
69   oss << "(" << cond << ") is false! ";
70   oss << msg_;
71   what_ = oss.str();
72 }
73 
74 } // namespace api
75 } // namespace vulkan
76 } // namespace native
77 } // namespace at
78