Open3D (C++ API)
0.19.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp
open3d
core
hashmap
CPU
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
16
#include "
open3d/core/hashmap/HashBackendBuffer.h
"
17
18
namespace
open3d
{
19
namespace
core
{
20
21
class
CPUHashBackendBufferAccessor
{
22
public
:
24
CPUHashBackendBufferAccessor
(
HashBackendBuffer
&hashmap_buffer)
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
HashBackendBuffer.h
open3d::core::CPUHashBackendBufferAccessor::heap_
buf_index_t * heap_
Definition
CPUHashBackendBufferAccessor.hpp:58
open3d::core::CPUHashBackendBufferAccessor::value_buffer_ptrs_
std::vector< uint8_t * > value_buffer_ptrs_
Definition
CPUHashBackendBufferAccessor.hpp:62
open3d::core::CPUHashBackendBufferAccessor::DeviceFree
void DeviceFree(buf_index_t buf_index)
Definition
CPUHashBackendBufferAccessor.hpp:41
open3d::core::CPUHashBackendBufferAccessor::key_dsize_
int64_t key_dsize_
Definition
CPUHashBackendBufferAccessor.hpp:55
open3d::core::CPUHashBackendBufferAccessor::CPUHashBackendBufferAccessor
CPUHashBackendBufferAccessor(HashBackendBuffer &hashmap_buffer)
Must initialize from a non-const buffer to grab the heap top.
Definition
CPUHashBackendBufferAccessor.hpp:24
open3d::core::CPUHashBackendBufferAccessor::GetKeyPtr
void * GetKeyPtr(buf_index_t buf_index)
Definition
CPUHashBackendBufferAccessor.hpp:45
open3d::core::CPUHashBackendBufferAccessor::key_buffer_ptr_
uint8_t * key_buffer_ptr_
Definition
CPUHashBackendBufferAccessor.hpp:61
open3d::core::CPUHashBackendBufferAccessor::GetValuePtr
void * GetValuePtr(buf_index_t buf_index, int value_idx=0)
Definition
CPUHashBackendBufferAccessor.hpp:48
open3d::core::CPUHashBackendBufferAccessor::DeviceAllocate
buf_index_t DeviceAllocate()
Definition
CPUHashBackendBufferAccessor.hpp:40
open3d::core::CPUHashBackendBufferAccessor::value_dsizes_
std::vector< int64_t > value_dsizes_
Definition
CPUHashBackendBufferAccessor.hpp:56
open3d::core::CPUHashBackendBufferAccessor::capacity_
int64_t capacity_
Definition
CPUHashBackendBufferAccessor.hpp:54
open3d::core::CPUHashBackendBufferAccessor::heap_top_
std::atomic< int > * heap_top_
Definition
CPUHashBackendBufferAccessor.hpp:59
open3d::core::HashBackendBuffer
Definition
HashBackendBuffer.h:46
open3d::core::HashBackendBuffer::GetHeapTop
HeapTop & GetHeapTop()
Definition
HashBackendBuffer.cpp:99
open3d::core::HashBackendBuffer::GetValueBuffers
std::vector< Tensor > GetValueBuffers() const
Return the value buffer tensors.
Definition
HashBackendBuffer.cpp:112
open3d::core
Definition
AdvancedIndexing.cpp:15
open3d::core::buf_index_t
uint32_t buf_index_t
Definition
HashBackendBuffer.h:44
open3d
Definition
PinholeCameraIntrinsic.cpp:16
Generated by
1.17.0