Open3D (C++ API)  0.17.0
CPUHashBackendBufferAccessor.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2023 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <assert.h>
30
31#include <atomic>
32#include <memory>
33#include <vector>
34
36
37namespace open3d {
38namespace core {
39
41public:
44 : capacity_(hashmap_buffer.GetCapacity()),
45 key_dsize_(hashmap_buffer.GetKeyDsize()),
46 value_dsizes_(hashmap_buffer.GetValueDsizes()),
47 heap_(hashmap_buffer.GetIndexHeap().GetDataPtr<buf_index_t>()),
48 key_buffer_ptr_(hashmap_buffer.GetKeyBuffer().GetDataPtr<uint8_t>()) {
49 std::vector<Tensor> value_buffers = hashmap_buffer.GetValueBuffers();
50 for (size_t i = 0; i < value_buffers.size(); ++i) {
51 void *value_buffer_ptr = value_buffers[i].GetDataPtr();
52 std::memset(value_buffer_ptr, 0, capacity_ * value_dsizes_[i]);
53 value_buffer_ptrs_.push_back(
54 static_cast<uint8_t *>(value_buffer_ptr));
55 }
56 heap_top_ = &(hashmap_buffer.GetHeapTop().cpu);
57 }
58
59 buf_index_t DeviceAllocate() { return heap_[(*heap_top_).fetch_add(1)]; }
60 void DeviceFree(buf_index_t buf_index) {
61 heap_[(*heap_top_).fetch_sub(1) - 1] = buf_index;
62 }
63
64 void *GetKeyPtr(buf_index_t buf_index) {
65 return key_buffer_ptr_ + buf_index * key_dsize_;
66 }
67 void *GetValuePtr(buf_index_t buf_index, int value_idx = 0) {
68 return value_buffer_ptrs_[value_idx] +
69 buf_index * value_dsizes_[value_idx];
70 }
71
72public:
73 int64_t capacity_;
74 int64_t key_dsize_;
75 std::vector<int64_t> value_dsizes_;
76
77 buf_index_t *heap_; /* [N] */
78 std::atomic<int> *heap_top_; /* [1] */
79
80 uint8_t *key_buffer_ptr_; /* [N] * sizeof(Key) */
81 std::vector<uint8_t *> value_buffer_ptrs_; /* [N] * sizeof(Value) */
82};
83
84} // namespace core
85} // namespace open3d
Definition: CPUHashBackendBufferAccessor.hpp:40
buf_index_t * heap_
Definition: CPUHashBackendBufferAccessor.hpp:77
std::vector< uint8_t * > value_buffer_ptrs_
Definition: CPUHashBackendBufferAccessor.hpp:81
void DeviceFree(buf_index_t buf_index)
Definition: CPUHashBackendBufferAccessor.hpp:60
int64_t key_dsize_
Definition: CPUHashBackendBufferAccessor.hpp:74
CPUHashBackendBufferAccessor(HashBackendBuffer &hashmap_buffer)
Must initialize from a non-const buffer to grab the heap top.
Definition: CPUHashBackendBufferAccessor.hpp:43
void * GetKeyPtr(buf_index_t buf_index)
Definition: CPUHashBackendBufferAccessor.hpp:64
uint8_t * key_buffer_ptr_
Definition: CPUHashBackendBufferAccessor.hpp:80
void * GetValuePtr(buf_index_t buf_index, int value_idx=0)
Definition: CPUHashBackendBufferAccessor.hpp:67
buf_index_t DeviceAllocate()
Definition: CPUHashBackendBufferAccessor.hpp:59
std::vector< int64_t > value_dsizes_
Definition: CPUHashBackendBufferAccessor.hpp:75
int64_t capacity_
Definition: CPUHashBackendBufferAccessor.hpp:73
std::atomic< int > * heap_top_
Definition: CPUHashBackendBufferAccessor.hpp:78
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