36 class DeviceHashBackend;
44 const Dtype& key_dtype,
46 const Dtype& value_dtype,
55 const Dtype& key_dtype,
57 const std::vector<Dtype>& dtypes_value,
58 const std::vector<SizeVector>& element_shapes_value,
76 std::pair<Tensor, Tensor>
Insert(
const Tensor& input_keys,
77 const Tensor& input_values);
83 std::pair<Tensor, Tensor>
Insert(
85 const std::vector<Tensor>& input_values_soa);
98 std::pair<Tensor, Tensor>
Find(
const Tensor& input_keys);
114 const Tensor& input_values,
115 Tensor& output_buf_indices,
122 const std::vector<Tensor>& input_values_soa,
123 Tensor& output_buf_indices,
130 Tensor& output_buf_indices,
137 Tensor& output_buf_indices,
155 void Save(
const std::string& file_name);
168 int64_t
Size()
const;
202 return device_hashmap_;
206 void Init(int64_t init_capacity,
211 const std::vector<Tensor>& input_values_soa,
212 Tensor& output_buf_indices,
214 bool is_activate_op =
false);
219 const std::vector<Tensor>& input_values_soa)
const;
222 const std::vector<Tensor>& input_values_soa)
const;
230 std::shared_ptr<DeviceHashBackend> device_hashmap_;
235 std::vector<Dtype> dtypes_value_;
236 std::vector<SizeVector> element_shapes_value_;
HashMap Clone() const
Clone the hash map with buffers.
Definition: HashMap.cpp:245
std::vector< Tensor > GetValueTensors() const
Definition: HashMap.cpp:293
void CheckKeyLength(const Tensor &input_keys) const
Definition: HashMap.cpp:376
void CheckKeyCompatibility(const Tensor &input_keys) const
Definition: HashMap.cpp:402
void CheckValueCompatibility(const std::vector< Tensor > &input_values_soa) const
Definition: HashMap.cpp:417
void PrepareIndicesOutput(Tensor &output_buf_indices, int64_t length) const
Definition: HashMap.cpp:448
~HashMap()=default
Default destructor.
int64_t GetCapacity() const
Get the capacity of the hash map.
Definition: HashMap.cpp:276
float LoadFactor() const
Return size / bucket_count.
Definition: HashMap.cpp:335
void Save(const std::string &file_name)
Definition: HashMap.cpp:237
static HashMap Load(const std::string &file_name)
Definition: HashMap.cpp:241
int64_t GetBucketCount() const
Get the number of buckets of the internal hash map.
Definition: HashMap.cpp:278
Tensor GetKeyTensor() const
Definition: HashMap.cpp:284
void PrepareMasksOutput(Tensor &output_masks, int64_t length) const
Definition: HashMap.cpp:457
HashMap(int64_t init_capacity, const Dtype &key_dtype, const SizeVector &key_element_shape, const Dtype &value_dtype, const SizeVector &value_element_shapes, const Device &device, const HashBackendType &backend=HashBackendType::Default)
Initialize a hash map given a key and a value dtype and element shape.
Definition: HashMap.cpp:38
std::pair< int64_t, std::vector< int64_t > > GetCommonValueSizeDivisor()
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
Definition: HashMap.h:201
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys, const Tensor &input_values)
Definition: HashMap.cpp:98
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
Definition: HashMap.cpp:118
Device GetDevice() const
Get the device of the hash map.
Definition: HashMap.cpp:282
std::pair< Tensor, Tensor > Activate(const Tensor &input_keys)
Definition: HashMap.cpp:112
Tensor GetValueTensor(size_t index=0) const
Definition: HashMap.cpp:312
void Init(int64_t init_capacity, const Device &device, const HashBackendType &backend)
Definition: HashMap.cpp:337
int64_t Size() const
Get the size (number of active entries) of the hash map.
Definition: HashMap.cpp:274
void CheckKeyValueLengthCompatibility(const Tensor &input_keys, const std::vector< Tensor > &input_values_soa) const
Definition: HashMap.cpp:383
Tensor Erase(const Tensor &input_keys)
Definition: HashMap.cpp:124
HashMap To(const Device &device, bool copy=false) const
Convert the hash map to another device.
Definition: HashMap.cpp:247
void Reserve(int64_t capacity)
Reserve the internal hash map with the given capacity by rehashing.
Definition: HashMap.cpp:66
void InsertImpl(const Tensor &input_keys, const std::vector< Tensor > &input_values_soa, Tensor &output_buf_indices, Tensor &output_masks, bool is_activate_op=false)
Definition: HashMap.cpp:136
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Definition: HashMap.cpp:331
void Clear()
Clear stored map without reallocating the buffers.
Definition: HashMap.cpp:235
Tensor GetActiveIndices() const
Definition: HashMap.cpp:130
Definition: SizeVector.h:79
HashBackendType
Definition: HashMap.h:38
Definition: PinholeCameraIntrinsic.cpp:35