OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExecutorResourceMgrCommon.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <math.h>
20 #include <string>
21 
22 #include "Logger/Logger.h"
24 #include "Shared/StringTransform.h"
25 
26 namespace ExecutorResourceMgr_Namespace {
27 
28 // Type declarations and using aliases
29 using ChunkKey = std::vector<int>;
30 using RequestId = size_t;
31 
33  public:
34  ExecutorResourceMgrError(RequestId const request_id, std::string error_msg)
35  : request_id_(request_id), error_msg_(std::move(error_msg)) {}
36  RequestId getRequestId() const { return request_id_; }
37  std::string getErrorMsg() const { return error_msg_; }
38 
39  private:
41  std::string error_msg_;
42 };
43 
44 class QueryTimedOutWaitingInQueue : public std::runtime_error {
45  public:
46  QueryTimedOutWaitingInQueue(const size_t timeout_ms)
47  : std::runtime_error("Query exceeded queue timeout threshold " +
48  std::to_string(timeout_ms) + "ms.") {}
49 };
50 
51 class QueryNeedsTooMuchBufferPoolMem : public std::runtime_error {
52  public:
53  QueryNeedsTooMuchBufferPoolMem(const size_t max_buffer_pool_mem,
54  const size_t requested_buffer_pool_mem,
55  const ExecutorDeviceType device_type)
56  : std::runtime_error(
57  "Query requested more " + get_device_type_string(device_type) +
58  " buffer pool mem (" + format_num_bytes(requested_buffer_pool_mem) +
59  ") than max available for query (" + format_num_bytes(max_buffer_pool_mem) +
60  ") in executor resource pool") {}
61 
62  private:
63  std::string get_device_type_string(const ExecutorDeviceType device_type) {
64  switch (device_type) {
66  return "CPU";
68  return "GPU";
69  default:
70  UNREACHABLE();
71  return "";
72  }
73  }
74 };
75 
76 class QueryNeedsTooManyCpuSlots : public std::runtime_error {
77  public:
78  QueryNeedsTooManyCpuSlots(const size_t max_cpu_slots, const size_t requested_cpu_slots)
79  : std::runtime_error(
80  "Query requested more CPU slots (" + std::to_string(requested_cpu_slots) +
81  ") than max available for query (" + std::to_string(max_cpu_slots) +
82  ") in executor resource pool") {}
83 };
84 
85 class QueryNeedsTooManyGpuSlots : public std::runtime_error {
86  public:
87  QueryNeedsTooManyGpuSlots(const size_t max_gpu_slots, const size_t requested_gpu_slots)
88  : std::runtime_error(
89  "Query requested more GPU slots (" + std::to_string(requested_gpu_slots) +
90  ") than available per query (" + std::to_string(max_gpu_slots) +
91  ") in executor resource pool") {}
92 };
93 
94 class QueryNeedsTooMuchCpuResultMem : public std::runtime_error {
95  public:
96  QueryNeedsTooMuchCpuResultMem(const size_t max_cpu_result_mem,
97  const size_t requested_cpu_result_mem)
98  : std::runtime_error(
99  "Query requested more CPU result memory (" +
100  format_num_bytes(requested_cpu_result_mem) + ") than available per query (" +
101  format_num_bytes(max_cpu_result_mem) + ") in executor resource pool") {}
102 };
103 
108 enum class ResourceType {
109  CPU_SLOTS = 0,
110  GPU_SLOTS = 1,
111  CPU_RESULT_MEM = 2,
112  GPU_RESULT_MEM = 3,
115  INVALID_TYPE = 6,
116  NUM_RESOURCE_TYPES = 6,
117 };
118 
119 static constexpr size_t ResourceTypeSize =
120  static_cast<size_t>(ResourceType::NUM_RESOURCE_TYPES);
121 
122 static const char* ResourceTypeStrings[] = {"cpu_slots",
123  "gpu_slots",
124  "cpu_result_mem",
125  "gpu_result_mem",
126  "cpu_buffer_pool_mem",
127  "gpu_buffer_pool_mem"};
128 
129 inline std::string resource_type_to_string(const ResourceType resource_type) {
130  return ResourceTypeStrings[static_cast<size_t>(resource_type)];
131 }
132 
144 enum class ResourceSubtype {
145  CPU_SLOTS = 0,
146  GPU_SLOTS = 1,
147  CPU_RESULT_MEM = 2,
148  GPU_RESULT_MEM = 3,
153  INVALID_SUBTYPE = 8,
155 };
156 
157 static constexpr size_t ResourceSubtypeSize =
158  static_cast<size_t>(ResourceSubtype::NUM_RESOURCE_SUBTYPES);
159 
160 static const char* ResourceSubtypeStrings[] = {"cpu_slots",
161  "gpu_slots",
162  "cpu_result_mem",
163  "gpu_result_mem",
164  "pinned_cpu_buffer_pool_mem",
165  "pinned_gpu_buffer_pool_mem",
166  "pageable_cpu_buffer_pool_mem",
167  "pageable_gpu_buffer_pool_mem",
168  "invalid_type"};
169 
170 inline std::string resource_subtype_to_string(const ResourceSubtype resource_subtype) {
171  return ResourceSubtypeStrings[static_cast<size_t>(resource_subtype)];
172 }
173 
174 } // namespace ExecutorResourceMgr_Namespace
QueryNeedsTooMuchCpuResultMem(const size_t max_cpu_result_mem, const size_t requested_cpu_result_mem)
QueryNeedsTooManyCpuSlots(const size_t max_cpu_slots, const size_t requested_cpu_slots)
static constexpr size_t ResourceTypeSize
#define UNREACHABLE()
Definition: Logger.h:338
ResourceType
Stores the resource type for a ExecutorResourcePool request.
std::string get_device_type_string(const ExecutorDeviceType device_type)
ExecutorDeviceType
ResourceSubtype
Stores the resource sub-type for a ExecutorResourcePool request.
std::string to_string(char const *&&v)
std::string resource_subtype_to_string(const ResourceSubtype resource_subtype)
QueryNeedsTooMuchBufferPoolMem(const size_t max_buffer_pool_mem, const size_t requested_buffer_pool_mem, const ExecutorDeviceType device_type)
std::string format_num_bytes(const size_t bytes)
std::string resource_type_to_string(const ResourceType resource_type)
static constexpr size_t ResourceSubtypeSize
QueryNeedsTooManyGpuSlots(const size_t max_gpu_slots, const size_t requested_gpu_slots)
RequestId request_id()
Definition: Logger.cpp:876
static const char * ResourceSubtypeStrings[]
ExecutorResourceMgrError(RequestId const request_id, std::string error_msg)