Open3D (C++ API)  0.19.0
CPUHashBackendBufferAccessor.hpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <assert.h>
11 
12 #include <atomic>
13 #include <memory>
14 #include <vector>
15 
17 
18 namespace open3d {
19 namespace core {
20 
22 public:
25  : capacity_(hashmap_buffer.GetCapacity()),
26  key_dsize_(hashmap_buffer.GetKeyDsize()),
27  value_dsizes_(hashmap_buffer.GetValueDsizes()),
28  heap_(hashmap_buffer.GetIndexHeap().GetDataPtr<buf_index_t>()),
29  key_buffer_ptr_(hashmap_buffer.GetKeyBuffer().GetDataPtr<uint8_t>()) {
30  std::vector<Tensor> value_buffers = hashmap_buffer.GetValueBuffers();
31  for (size_t i = 0; i < value_buffers.size(); ++i) {
32  void *value_buffer_ptr = value_buffers[i].GetDataPtr();
33  std::memset(value_buffer_ptr, 0, capacity_ * value_dsizes_[i]);
34  value_buffer_ptrs_.push_back(
35  static_cast<uint8_t *>(value_buffer_ptr));
36  }
37  heap_top_ = &(hashmap_buffer.GetHeapTop().cpu);
38  }
39 
40  buf_index_t DeviceAllocate() { return heap_[(*heap_top_).fetch_add(1)]; }
41  void DeviceFree(buf_index_t buf_index) {
42  heap_[(*heap_top_).fetch_sub(1) - 1] = buf_index;
43  }
44 
45  void *GetKeyPtr(buf_index_t buf_index) {
46  return key_buffer_ptr_ + buf_index * key_dsize_;
47  }
48  void *GetValuePtr(buf_index_t buf_index, int value_idx = 0) {
49  return value_buffer_ptrs_[value_idx] +
50  buf_index * value_dsizes_[value_idx];
51  }
52 
53 public:
54  int64_t capacity_;
55  int64_t key_dsize_;
56  std::vector<int64_t> value_dsizes_;
57 
58  buf_index_t *heap_; /* [N] */
59  std::atomic<int> *heap_top_; /* [1] */
60 
61  uint8_t *key_buffer_ptr_; /* [N] * sizeof(Key) */
62  std::vector<uint8_t *> value_buffer_ptrs_; /* [N] * sizeof(Value) */
63 };
64 
65 } // namespace core
66 } // namespace open3d
Definition: CPUHashBackendBufferAccessor.hpp:21
buf_index_t * heap_
Definition: CPUHashBackendBufferAccessor.hpp:58
std::vector< uint8_t * > value_buffer_ptrs_
Definition: CPUHashBackendBufferAccessor.hpp:62
void DeviceFree(buf_index_t buf_index)
Definition: CPUHashBackendBufferAccessor.hpp:41
int64_t key_dsize_
Definition: CPUHashBackendBufferAccessor.hpp:55
CPUHashBackendBufferAccessor(HashBackendBuffer &hashmap_buffer)
Must initialize from a non-const buffer to grab the heap top.
Definition: CPUHashBackendBufferAccessor.hpp:24
void * GetValuePtr(buf_index_t buf_index, int value_idx=0)
Definition: CPUHashBackendBufferAccessor.hpp:48
uint8_t * key_buffer_ptr_
Definition: CPUHashBackendBufferAccessor.hpp:61
void * GetKeyPtr(buf_index_t buf_index)
Definition: CPUHashBackendBufferAccessor.hpp:45
buf_index_t DeviceAllocate()
Definition: CPUHashBackendBufferAccessor.hpp:40
std::vector< int64_t > value_dsizes_
Definition: CPUHashBackendBufferAccessor.hpp:56
int64_t capacity_
Definition: CPUHashBackendBufferAccessor.hpp:54
std::atomic< int > * heap_top_
Definition: CPUHashBackendBufferAccessor.hpp:59
Definition: HashBackendBuffer.h:46
HeapTop & GetHeapTop()
Definition: HashBackendBuffer.cpp:99
std::vector< Tensor > GetValueBuffers() const
Return the value buffer tensors.
Definition: HashBackendBuffer.cpp:112
uint32_t buf_index_t
Definition: HashBackendBuffer.h:44
Definition: PinholeCameraIntrinsic.cpp:16
std::atomic< int > cpu
Definition: HashBackendBuffer.h:50