Scanner C++ API
memory.h
1 /* Copyright 2018 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "scanner/util/common.h"
19 
20 #include <cstddef>
21 
22 namespace scanner {
23 
24 static const i64 DEFAULT_POOL_SIZE = 2L * 1024L * 1024L * 1024L;
25 
26 typedef struct {
27  u8* buffer;
28  size_t size;
29  i32 refs;
30  std::string call_file;
31  i32 call_line;
32 } Allocation;
33 
34 void init_memory_allocators(MemoryPoolConfig config,
35  std::vector<i32> gpu_device_ids);
36 
37 void destroy_memory_allocators();
38 
39 u8* new_buffer_(DeviceHandle device, size_t size, std::string call_file,
40  i32 call_line);
41 
42 #define new_buffer(device__, size__) \
43  new_buffer_(device__, size__, __FILE__, __LINE__)
44 
45 u8* new_block_buffer_(DeviceHandle device, size_t size, i32 refs,
46  std::string call_file, i32 call_line);
47 
48 #define new_block_buffer(device__, size__, refs__) \
49  new_block_buffer_(device__, size__, refs__, __FILE__, __LINE__)
50 
51 u8* new_block_buffer_sizes_(DeviceHandle device, const std::vector<size_t>& sizes,
52  std::string call_file, i32 call_line);
53 
54 #define new_block_buffer_sizes(device__, sizes__) \
55  new_block_buffer_sizes_(device__, sizes__, __FILE__, __LINE__)
56 
57 u8* new_block_buffer_size_(DeviceHandle device, size_t size, i32 copies,
58  std::string call_file, i32 call_line);
59 
60 #define new_block_buffer_size(device__, size__, copies__) \
61  new_block_buffer_size_(device__, size__, copies__, __FILE__, __LINE__)
62 
63 void add_buffer_ref(DeviceHandle device, u8* buffer);
64 
65 void add_buffer_refs(DeviceHandle device, u8* buffer, i32 refs);
66 
67 void delete_buffer(DeviceHandle device, u8* buffer);
68 
69 void memcpy_buffer(u8* dest_buffer, DeviceHandle dest_device,
70  const u8* src_buffer, DeviceHandle src_device, size_t size);
71 
72 void memcpy_vec(std::vector<u8*>& dest_buffers, DeviceHandle dest_device,
73  const std::vector<u8*>& src_buffers, DeviceHandle src_device,
74  const std::vector<size_t>& sizes);
75 
76 void copy_or_ref_buffers(std::vector<u8*>& dest_buffers,
77  DeviceHandle dest_device,
78  const std::vector<u8*>& src_buffers,
79  DeviceHandle src_device,
80  const std::vector<size_t>& sizes);
81 
82 u64 current_memory_allocated(DeviceHandle device);
83 
84 u64 max_memory_allocated(DeviceHandle device);
85 
86 const std::vector<Allocation> allocator_allocations(DeviceHandle device);
87 
88 }
Definition: memory.h:26
Definition: common.h:53
Definition: database.cpp:36