OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RenderAllocator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 #ifdef HAVE_CUDA
20 #include <cuda.h>
21 #else
22 #include "Shared/nocuda.h"
23 #endif // HAVE_CUDA
24 
25 #include <cstdlib>
26 #include <memory>
27 #include <mutex>
28 #include <stdexcept>
29 #include <vector>
30 
32 
33 namespace QueryRenderer {
34 class JSONLocation;
35 class QueryRenderManager;
36 struct QueryDataLayout;
37 } // namespace QueryRenderer
38 
39 class OutOfRenderMemory : public std::runtime_error {
40  public:
41  OutOfRenderMemory(const size_t device_id,
42  const size_t total_bytes,
43  const size_t requested_bytes);
44 };
45 
46 class StreamingTopNNotSupportedInRenderQuery : public std::runtime_error {
47  public:
49  : std::runtime_error("Streaming-Top-N not supported in Render Query") {}
50 };
51 
52 class RenderAllocator : public Allocator {
53  public:
54  RenderAllocator(int8_t* preallocated_ptr,
55  const size_t preallocated_size,
56  const size_t device_id);
57 
58  int8_t* alloc(const size_t bytes) final;
59 
60  void markChunkComplete();
61 
62  size_t getCurrentChunkOffset() const;
63  size_t getCurrentChunkSize() const;
64  size_t getAllocatedSize() const;
65 
66  int8_t* getBasePtr() const;
67 
68  private:
70  const size_t preallocated_size_;
71  const size_t device_id_;
74 
75  std::unique_ptr<std::mutex> alloc_mtx_ptr_;
76 };
77 
79  public:
80  RenderAllocatorMap(::QueryRenderer::QueryRenderManager* render_manager);
82 
83  RenderAllocator* getRenderAllocator(size_t device_id);
84  RenderAllocator* operator[](size_t device_id);
85  size_t size() const { return render_allocator_map_.size(); }
86 
87  void bufferData(int8_t* data, const size_t num_data_bytes, const size_t device_id);
88  void setDataLayout(
89  const std::shared_ptr<::QueryRenderer::QueryDataLayout>& query_data_layout);
90  void prepForRendering(
91  const std::shared_ptr<::QueryRenderer::QueryDataLayout>& query_data_layout);
92 
93  private:
94  ::QueryRenderer::QueryRenderManager* render_manager_;
95  std::vector<RenderAllocator> render_allocator_map_;
96 };
int8_t * alloc(const size_t bytes) final
std::vector< RenderAllocator > render_allocator_map_
RenderAllocator * getRenderAllocator(size_t device_id)
const size_t preallocated_size_
::QueryRenderer::QueryRenderManager * render_manager_
RenderAllocator(int8_t *preallocated_ptr, const size_t preallocated_size, const size_t device_id)
size_t getCurrentChunkOffset() const
std::unique_ptr< std::mutex > alloc_mtx_ptr_
const size_t device_id_
size_t getAllocatedSize() const
size_t crt_chunk_offset_bytes_
size_t size() const
void bufferData(int8_t *data, const size_t num_data_bytes, const size_t device_id)
int8_t * preallocated_ptr_
RenderAllocator * operator[](size_t device_id)
Abstract class for managing device memory allocations.
size_t getCurrentChunkSize() const
RenderAllocatorMap(::QueryRenderer::QueryRenderManager *render_manager)
void prepForRendering(const std::shared_ptr<::QueryRenderer::QueryDataLayout > &query_data_layout)
int8_t * getBasePtr() const
void setDataLayout(const std::shared_ptr<::QueryRenderer::QueryDataLayout > &query_data_layout)
size_t crt_allocated_bytes_
OutOfRenderMemory(const size_t device_id, const size_t total_bytes, const size_t requested_bytes)