21 #include <shared_mutex>
27 namespace ExecutorResourceMgr_Namespace {
38 switch (resource_subtype) {
71 switch (resource_type) {
148 : total_cpu_slots(total_cpu_slots)
149 , total_gpu_slots(total_gpu_slots)
150 , total_cpu_result_mem(total_cpu_result_mem)
151 , total_cpu_buffer_pool_mem(total_cpu_buffer_pool_mem)
152 , total_gpu_buffer_pool_mem(total_gpu_buffer_pool_mem)
153 , allocated_cpu_slots(allocated_cpu_slots)
154 , allocated_gpu_slots(allocated_gpu_slots)
155 , allocated_cpu_result_mem(allocated_cpu_result_mem)
156 , allocated_cpu_buffer_pool_mem(allocated_cpu_buffer_pool_mem)
157 , allocated_gpu_buffer_pool_mem(allocated_gpu_buffer_pool_mem)
158 , allocated_cpu_buffers(allocated_cpu_buffers)
159 , allocated_gpu_buffers(allocated_gpu_buffers)
160 , allocated_temp_cpu_buffer_pool_mem(allocated_temp_cpu_buffer_pool_mem)
161 , allocated_temp_gpu_buffer_pool_mem(allocated_temp_gpu_buffer_pool_mem)
162 , total_requests(total_requests)
163 , outstanding_requests(outstanding_requests)
164 , outstanding_cpu_slots_requests(outstanding_cpu_slots_requests)
165 , outstanding_gpu_slots_requests(outstanding_gpu_slots_requests)
166 , outstanding_cpu_result_mem_requests(outstanding_cpu_result_mem_requests)
167 , outstanding_cpu_buffer_pool_mem_requests(outstanding_cpu_buffer_pool_mem_requests)
168 , outstanding_gpu_buffer_pool_mem_requests(
169 outstanding_gpu_buffer_pool_mem_requests) {}
196 std::map<ChunkKey, std::pair<size_t, size_t>>;
240 const std::vector<std::pair<ResourceType, size_t>>& total_resources,
241 const std::vector<ConcurrentResourceGrantPolicy>&
242 concurrent_resource_grant_policies,
243 const std::vector<ResourceGrantPolicy>& max_per_request_resource_grant_policies);
248 const std::vector<ResourceRequest>& resource_requests)
const;
297 const double max_request_backoff_ratio)
const;
400 const std::vector<std::pair<ResourceType, size_t>>& total_resources,
401 const std::vector<ConcurrentResourceGrantPolicy>&
402 concurrent_resource_grant_policies,
403 const std::vector<ResourceGrantPolicy>& max_per_request_resource_grant_policies);
409 const size_t min_resource_requested)
const;
412 const size_t requested_resource_quantity,
413 const size_t min_requested_resource_quantity,
414 const size_t max_grantable_resource_quantity)
const;
417 const size_t min_requested_dependent_resource_quantity,
418 const size_t min_requested_independent_resource_quantity,
419 const size_t dependent_to_independent_resource_ratio)
const;
422 const size_t requested_dependent_resource_quantity,
423 const size_t min_requested_dependent_resource_quantity,
424 const size_t max_grantable_dependent_resource_quantity,
425 const size_t min_requested_independent_resource_quantity,
426 const size_t max_grantable_independent_resource_quantity,
427 const size_t dependent_to_independent_resource_ratio)
const;
430 const size_t resource_total,
431 const size_t resource_allocated,
435 const size_t resource_request,
436 const size_t resource_total,
437 const size_t resource_allocated,
438 const size_t global_outstanding_requests,
459 const size_t min_resource_requested,
460 const size_t max_resource_requested,
461 const size_t resource_allocated,
462 const size_t total_resource,
463 const double max_request_backoff_ratio)
const;
524 std::array<size_t, ResourceTypeSize>
528 std::array<size_t, ResourceSubtypeSize>
530 std::array<ResourceGrantPolicy, ResourceSubtypeSize>
533 std::array<ConcurrentResourceGrantPolicy, ResourceTypeSize>
539 std::array<size_t, ResourceTypeSize>
542 std::array<size_t, ResourceTypeSize>
size_t get_total_resource(const ResourceType resource_type) const
A container for various stats about the current state of the ExecutorResourcePool. Note that ExecutorResourcePool does not persist a struct of this type, but rather builds one on the fly when ExecutorResourcePool::get_resource_info() is called.
A container to store requested and minimum neccessary resource requests across all resource types cur...
size_t get_chunk_bytes_not_in_pool(const ChunkRequestInfo &chunk_request_info) const
size_t outstanding_cpu_result_mem_requests
ResourcePoolInfo get_resource_info() const
Returns a struct detailing the allocated and total available resources of each type tracked in Execut...
std::array< size_t, ResourceSubtypeSize > allocated_resources_
void init_max_resource_grants_per_requests()
size_t allocated_cpu_buffers
std::shared_mutex resource_mutex_
size_t buffer_mem_per_slot
size_t allocated_temp_gpu_buffer_pool_mem
bool can_currently_satisfy_request(const ResourceGrant &min_resource_grant, const ChunkRequestInfo &chunk_request_info) const
std::array< bool, ResourceTypeSize > resource_type_validity_
size_t outstanding_gpu_slots_requests
std::string to_string() const
size_t get_allocated_resource_of_subtype(const ResourceSubtype resource_subtype) const
std::array< size_t, ResourceTypeSize > total_resources_
ChunkRequestInfo get_requested_chunks_not_in_pool(const ChunkRequestInfo &chunk_request_info) const
size_t allocated_cpu_slots
void set_resource(const ResourceType resource_type, const size_t resource_quantity)
Sets the quantity of resource_type to resource_quantity. If pool has outstanding requests, will throw. Responsibility of allowing the pool to empty and preventing concurrent requests while this operation is running is left to the caller (in particular, ExecutorResourceMgr::set_resource pauses the process queue, which waits until all executing requests are finished before yielding to the caller, before calling this method).
const ResourceGrantPolicy & get_max_resource_grant_per_request_policy(const ResourceSubtype resource_subtype) const
void deallocate_resources(const ResourceGrant &resource_grant, const ChunkRequestInfo &chunk_request_info)
Deallocates resources granted to a requestor such that they can be used for other requests...
ResourceType
Stores the resource type for a ExecutorResourcePool request.
size_t allocated_gpu_buffers
std::vector< ResourceSubtype > map_resource_type_to_resource_subtypes(const ResourceType resource_type)
Returns the 1-or-more ResourceSubtypes associated with a given ResourceType.
bool is_resource_valid(const ResourceType resource_type) const
void init_concurrency_policies()
bool can_currently_satisfy_request_impl(const ResourceGrant &min_resource_grant, const ChunkRequestInfo &chunk_request_info) const
size_t calc_max_resource_grant_for_request(const size_t requested_resource_quantity, const size_t min_requested_resource_quantity, const size_t max_grantable_resource_quantity) const
std::map< ChunkKey, std::pair< size_t, size_t >> BufferPoolChunkMap
Specifies the policies for resource grants in the presence of other requests, both under situations o...
void add_chunk_requests_to_allocated_pool(const ResourceGrant &resource_grant, const ChunkRequestInfo &chunk_request_info)
size_t determine_dynamic_single_resource_grant(const size_t min_resource_requested, const size_t max_resource_requested, const size_t resource_allocated, const size_t total_resource, const double max_request_backoff_ratio) const
std::array< size_t, ResourceTypeSize > total_per_resource_num_requests_
ResourceSubtype
Stores the resource sub-type for a ExecutorResourcePool request.
bool can_currently_satisfy_chunk_request(const ResourceGrant &min_resource_grant, const ChunkRequestInfo &chunk_request_info) const
size_t get_total_allocated_buffer_pool_mem_for_level(const ExecutorDeviceType memory_pool_type) const
size_t increment_outstanding_per_resource_num_requests(const ResourceType resource_type)
BufferPoolChunkMap allocated_cpu_buffer_pool_chunks_
std::pair< ResourceGrant, ResourceGrant > calc_min_max_resource_grants_for_request(const RequestInfo &resource_request) const
Given the provided resource_request, statically calculate the minimum and maximum grantable resources...
std::vector< ResourceRequestGrant > calc_static_resource_grant_ranges_for_request(const std::vector< ResourceRequest > &resource_requests) const
size_t allocated_cpu_result_mem
void allocate_resources(const ResourceGrant &resource_grant, const ChunkRequestInfo &chunk_request_info)
Given a resource grant (assumed to be computed in determine_dynamic_resource_grant), actually allocate (reserve) the resources in the pool so other requestors (queries) cannot use those resources until returned to the pool.
Specifies the resources of each type for a given resource grant.
void set_concurrent_resource_grant_policy(const ConcurrentResourceGrantPolicy &concurrent_resource_grant_policy)
Resets the concurrent resource grant policy object, which specifies a ResourceType as well as normal ...
ResourcePoolInfo(const size_t total_cpu_slots, const size_t total_gpu_slots, const size_t total_cpu_result_mem, const size_t total_cpu_buffer_pool_mem, const size_t total_gpu_buffer_pool_mem, const size_t allocated_cpu_slots, const size_t allocated_gpu_slots, const size_t allocated_cpu_result_mem, const size_t allocated_cpu_buffer_pool_mem, const size_t allocated_gpu_buffer_pool_mem, const size_t allocated_cpu_buffers, const size_t allocated_gpu_buffers, const size_t allocated_temp_cpu_buffer_pool_mem, const size_t allocated_temp_gpu_buffer_pool_mem, const size_t total_requests, const size_t outstanding_requests, const size_t outstanding_cpu_slots_requests, const size_t outstanding_gpu_slots_requests, const size_t outstanding_cpu_result_mem_requests, const size_t outstanding_cpu_buffer_pool_mem_requests, const size_t outstanding_gpu_buffer_pool_mem_requests)
size_t outstanding_requests
size_t increment_total_per_resource_num_requests(const ResourceType resource_type)
size_t buffer_mem_for_given_slots
std::pair< size_t, size_t > calc_max_dependent_resource_grant_for_request(const size_t requested_dependent_resource_quantity, const size_t min_requested_dependent_resource_quantity, const size_t max_grantable_dependent_resource_quantity, const size_t min_requested_independent_resource_quantity, const size_t max_grantable_independent_resource_quantity, const size_t dependent_to_independent_resource_ratio) const
size_t total_cpu_buffer_pool_mem
bool check_request_against_global_policy(const size_t resource_total, const size_t resource_allocated, const ConcurrentResourceGrantPolicy &concurrent_resource_grant_policy) const
ExecutorResourcePool(const std::vector< std::pair< ResourceType, size_t >> &total_resources, const std::vector< ConcurrentResourceGrantPolicy > &concurrent_resource_grant_policies, const std::vector< ResourceGrantPolicy > &max_per_request_resource_grant_policies)
Specifies the policy for granting a resource of a specific ResourceSubtype. Note that this policy onl...
size_t allocated_temp_cpu_buffer_pool_mem
ExecutorResourcePool keeps track of available compute and memory resources and can be queried to get ...
size_t total_cpu_result_mem
size_t decrement_total_per_resource_num_requests(const ResourceType resource_type)
void sanity_check_requests_against_allocations() const
std::pair< bool, ResourceGrant > determine_dynamic_resource_grant(const ResourceGrant &min_resource_grant, const ResourceGrant &max_resource_grant, const ChunkRequestInfo &chunk_request_info, const double max_request_backoff_ratio) const
Determines the actual resource grant to give a query (which will be somewhere between the provided mi...
std::pair< size_t, size_t > calc_min_dependent_resource_grant_for_request(const size_t min_requested_dependent_resource_quantity, const size_t min_requested_independent_resource_quantity, const size_t dependent_to_independent_resource_ratio) const
BufferPoolChunkMap allocated_gpu_buffer_pool_chunks_
size_t outstanding_num_requests_
std::array< ConcurrentResourceGrantPolicy, ResourceTypeSize > concurrent_resource_grant_policies_
size_t total_gpu_buffer_pool_mem
ResourceType map_resource_subtype_to_resource_type(const ResourceSubtype resource_subtype)
Returns the ResourceType associated with a given ResourceSubtype
void remove_chunk_requests_from_allocated_pool(const ResourceGrant &resource_grant, const ChunkRequestInfo &chunk_request_info)
void init(const std::vector< std::pair< ResourceType, size_t >> &total_resources, const std::vector< ConcurrentResourceGrantPolicy > &concurrent_resource_grant_policies, const std::vector< ResourceGrantPolicy > &max_per_request_resource_grant_policies)
void log_parameters() const
size_t get_outstanding_per_resource_num_requests(const ResourceType resource_type) const
std::array< size_t, ResourceTypeSize > outstanding_per_resource_num_requests_
size_t total_num_requests_
size_t outstanding_gpu_buffer_pool_mem_requests
size_t allocated_gpu_buffer_pool_mem
const bool sanity_check_pool_state_on_deallocations_
size_t get_max_resource_grant_per_request(const ResourceSubtype resource_subtype) const
bool check_request_against_policy(const size_t resource_request, const size_t resource_total, const size_t resource_allocated, const size_t global_outstanding_requests, const ConcurrentResourceGrantPolicy &concurrent_resource_grant_policy) const
size_t allocated_gpu_slots
std::shared_timed_mutex shared_mutex
Specifies all DataMgr chunks needed for a query step/request, along with their sizes in bytes...
size_t get_total_per_resource_num_requests(const ResourceType resource_type) const
bool buffer_mem_gated_per_slot
std::array< size_t, ResourceSubtypeSize > max_resource_grants_per_request_
size_t decrement_outstanding_per_resource_num_requests(const ResourceType resource_type)
void throw_insufficient_resource_error(const ResourceSubtype resource_subtype, const size_t min_resource_requested) const
size_t get_allocated_resource_of_type(const ResourceType resource_type) const
size_t allocated_cpu_buffer_pool_mem
std::array< ResourceGrantPolicy, ResourceSubtypeSize > max_resource_grants_per_request_policies_
size_t outstanding_cpu_slots_requests
size_t outstanding_cpu_buffer_pool_mem_requests
ConcurrentResourceGrantPolicy get_concurrent_resource_grant_policy(const ResourceType resource_type) const