Skip to content

Commit 9c013e5

Browse files
LinGeLinrhdong
authored andcommitted
[feat] Change to use hkv release version beta6 and replace the Cuckoo underlying implementation with hkv.
1 parent 95de77a commit 9c013e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2647
-7380
lines changed

WORKSPACE

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,60 @@ http_archive(
5454
url = "https://github.com/sewenew/redis-plus-plus/archive/refs/tags/1.2.3.zip",
5555
)
5656

57+
http_archive(
58+
name = "hkv",
59+
build_file = "//build_deps/toolchains/hkv:hkv.BUILD",
60+
# TODO(LinGeLin) remove this when update hkv
61+
patch_cmds = [
62+
"""sed -i.bak '1772i\\'$'\\n ThrustAllocator<uint8_t> thrust_allocator_;\\n' include/merlin_hashtable.cuh""",
63+
"""sed -i.bak '225i\\'$'\\n thrust_allocator_.set_allocator(allocator_);\\n' include/merlin_hashtable.cuh""",
64+
"sed -i.bak 's/thrust::sort_by_key(thrust_par.on(stream)/thrust::sort_by_key(thrust_par(thrust_allocator_).on(stream)/' include/merlin_hashtable.cuh",
65+
"sed -i.bak 's/reduce(thrust_par.on(stream)/reduce(thrust_par(thrust_allocator_).on(stream)/' include/merlin_hashtable.cuh",
66+
"""sed -i.bak '125i\\'$'\\n template <typename T>\\n' include/merlin/allocator.cuh""",
67+
"""sed -i.bak '126i\\'$'\\n struct ThrustAllocator : thrust::device_malloc_allocator<T> {\\n' include/merlin/allocator.cuh""",
68+
"""sed -i.bak '127i\\'$'\\n public:\\n' include/merlin/allocator.cuh""",
69+
"""sed -i.bak '128i\\'$'\\n typedef thrust::device_malloc_allocator<T> super_t;\\n' include/merlin/allocator.cuh""",
70+
"""sed -i.bak '129i\\'$'\\n typedef typename super_t::pointer pointer;\\n' include/merlin/allocator.cuh""",
71+
"""sed -i.bak '130i\\'$'\\n typedef typename super_t::size_type size_type;\\n' include/merlin/allocator.cuh""",
72+
"""sed -i.bak '131i\\'$'\\n public:\\n' include/merlin/allocator.cuh""",
73+
"""sed -i.bak '132i\\'$'\\n pointer allocate(size_type n) {\\n' include/merlin/allocator.cuh""",
74+
"""sed -i.bak '133i\\'$'\\n void* ptr = nullptr;\\n' include/merlin/allocator.cuh""",
75+
"""sed -i.bak '134i\\'$'\\n MERLIN_CHECK(\\n' include/merlin/allocator.cuh""",
76+
"""sed -i.bak '135i\\'$'\\n allocator_ != nullptr,\\n' include/merlin/allocator.cuh""",
77+
"""sed -i.bak '136i\\'$'\\n "[ThrustAllocator] set_allocator should be called in advance!");\\n' include/merlin/allocator.cuh""",
78+
"""sed -i.bak '137i\\'$'\\n allocator_->alloc(MemoryType::Device, &ptr, sizeof(T) * n);\\n' include/merlin/allocator.cuh""",
79+
"""sed -i.bak '138i\\'$'\\n return pointer(reinterpret_cast<T*>(ptr));\\n' include/merlin/allocator.cuh""",
80+
"""sed -i.bak '139i\\'$'\\n }\\n' include/merlin/allocator.cuh""",
81+
"""sed -i.bak '140i\\'$'\\n void deallocate(pointer p, size_type n) {\\n' include/merlin/allocator.cuh""",
82+
"""sed -i.bak '141i\\'$'\\n MERLIN_CHECK(\\n' include/merlin/allocator.cuh""",
83+
"""sed -i.bak '142i\\'$'\\n allocator_ != nullptr,\\n' include/merlin/allocator.cuh""",
84+
"""sed -i.bak '143i\\'$'\\n "[ThrustAllocator] set_allocator should be called in advance!");\\n' include/merlin/allocator.cuh""",
85+
"""sed -i.bak '144i\\'$'\\n allocator_->free(MemoryType::Device, reinterpret_cast<void*>(p.get()));\\n' include/merlin/allocator.cuh""",
86+
"""sed -i.bak '145i\\'$'\\n }\\n' include/merlin/allocator.cuh""",
87+
"""sed -i.bak '146i\\'$'\\n void set_allocator(BaseAllocator* allocator) { allocator_ = allocator; }\\n' include/merlin/allocator.cuh""",
88+
"""sed -i.bak '147i\\'$'\\n public:\\n' include/merlin/allocator.cuh""",
89+
"""sed -i.bak '148i\\'$'\\n BaseAllocator* allocator_ = nullptr;\\n' include/merlin/allocator.cuh""",
90+
"""sed -i.bak '149i\\'$'\\n };\\n' include/merlin/allocator.cuh""",
91+
"""sed -i.bak '20i\\'$'\\n #include <thrust/device_malloc_allocator.h>\\n' include/merlin/allocator.cuh""",
92+
"""sed -i.bak '367i\\'$'\\n for (auto addr : (*table)->buckets_address) {\\n' include/merlin/core_kernels.cuh""",
93+
"""sed -i.bak '368i\\'$'\\n allocator->free(MemoryType::Device, addr);\\n' include/merlin/core_kernels.cuh""",
94+
"""sed -i.bak '369i\\'$'\\n }\\n' include/merlin/core_kernels.cuh""",
95+
"""sed -i.bak '370i\\'$'\\n /*\\n' include/merlin/core_kernels.cuh""",
96+
"""sed -i.bak '382i\\'$'\\n */\\n' include/merlin/core_kernels.cuh""",
97+
"""sed -i.bak '224i\\'$'\\n uint8_t* address = nullptr;\\n' include/merlin/core_kernels.cuh""",
98+
"""sed -i.bak '225i\\'$'\\n allocator->alloc(MemoryType::Device, (void**)&(address), bucket_memory_size * (end - start));\\n' include/merlin/core_kernels.cuh""",
99+
"""sed -i.bak '226i\\'$'\\n (*table)->buckets_address.push_back(address);\\n' include/merlin/core_kernels.cuh""",
100+
"""sed -i.bak '228i\\'$'\\n allocate_bucket_others<K, V, S><<<1, 1>>>((*table)->buckets, i, address + (bucket_memory_size * (i-start)), reserve_size, bucket_max_size);\\n' include/merlin/core_kernels.cuh""",
101+
"""sed -i.bak '229i\\'$'\\n /*\\n' include/merlin/core_kernels.cuh""",
102+
"""sed -i.bak '235i\\'$'\\n */\\n' include/merlin/core_kernels.cuh""",
103+
"""sed -i.bak '22i\\'$'\\n#include <vector>\\n' include/merlin/types.cuh""",
104+
"""sed -i.bak '143i\\'$'\\n std::vector<uint8_t*> buckets_address;\\n' include/merlin/types.cuh""",
105+
],
106+
sha256 = "f8179c445a06a558262946cda4d8ae7252d313e73f792586be9b1bc0c993b1cf",
107+
strip_prefix = "HierarchicalKV-0.1.0-beta.6",
108+
url = "https://github.com/NVIDIA-Merlin/HierarchicalKV/archive/refs/tags/v0.1.0-beta.6.tar.gz",
109+
)
110+
57111
tf_configure(
58112
name = "local_config_tf",
59113
)

build_deps/toolchains/gpu/cuda_configure.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ _DEFAULT_CUDA_COMPUTE_CAPABILITIES = {
6868

6969
_DEFAULT_CUDA_COMPUTE_CAPABILITIES.update(
7070
{"11.{}".format(v): [
71-
"6.0",
72-
"6.1",
7371
"7.0",
7472
"7.5",
7573
"8.0",

build_deps/toolchains/hkv/BUILD

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda", "if_cuda_is_configured")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "hkv",
7+
hdrs = glob([
8+
"include/merlin/core_kernels/*.cuh",
9+
"include/merlin/*.cuh",
10+
"include/*.cuh",
11+
"include/*.hpp",
12+
]),
13+
copts = [
14+
"-Ofast",
15+
],
16+
include_prefix = "include",
17+
includes = ["include"],
18+
)

docs/api_docs/tfra/dynamic_embedding.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Export dynamic_embedding APIs.
4747

4848
[`class ModelMode`](../tfra/dynamic_embedding/ModelMode.md): The global config of model modes.
4949

50+
[`class HkvHashTable`](../tfra/dynamic_embedding/HkvHashTable.md): A generic mutable hash table implementation.
51+
52+
[`class HkvHashTableConfig`](../tfra/dynamic_embedding/HkvHashTableConfig.md): HkvHashTableConfig config init_capacity, max_capacity, max_hbm_for_values of HkvHashTable
53+
54+
[`class HkvHashTableCreator`](../tfra/dynamic_embedding/HkvHashTableCreator.md): A generic KV table creator.
55+
5056
[`class RedisTable`](../tfra/dynamic_embedding/RedisTable.md): A generic mutable hash table implementation.
5157

5258
[`class RedisTableConfig`](../tfra/dynamic_embedding/RedisTableConfig.md): RedisTableConfig config json file for connecting Redis service and

docs/api_docs/tfra/dynamic_embedding/CuckooHashTable.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ remove method. It does not support initialization via the init method.
5353
```python
5454
table = tfra.dynamic_embedding.CuckooHashTable(key_dtype=tf.string,
5555
value_dtype=tf.int64,
56-
default_value=-1)
56+
default_value=-1,
57+
device=['/GPU:0'])
5758
sess.run(table.insert(keys, values))
5859
out = table.lookup(query_keys)
5960
print(out.eval())
@@ -106,6 +107,10 @@ A `CuckooHashTable` object.
106107
* <b>`ValueError`</b>: If checkpoint is True and no name was specified.
107108

108109

110+
## <b>`Important update!!`</b>
111+
112+
We have made updates to the underlying implementation of the CuckooHashTable. The original CPU table remains unchanged, but the GPU table now uses the HKV implementation instead of nvhash. To ensure interface consistency, the init_capacity and max_capacity of HKV will be set to the init_size value you pass in. It is important to note that after this setting, the GPU hash table will not automatically resize, and the final capacity will be the same as the init_size. The max_hbm_for_values parameter of hkv will be set to a sufficiently large number to ensure that all your data is stored in the GPU table. Additionally, hkv has requirements for GPU compute capability, which needs to be 8.0 or above. For more detailed information about HKV, please refer to the documentation of HKV.
113+
109114

110115
## Properties
111116

docs/api_docs/tfra/dynamic_embedding/CuckooHashTableCreator.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ class for creating the real KV table backend(TF resource).
4141

4242
#### Example usage:
4343

44-
44+
Due to CuckooHashTableConfig include nothing for parameter default satisfied. Just setting the parameter saver is enough.
4545

4646
```python
47-
redis_config1=tfra.dynamic_embedding.RedisTableConfig(
48-
redis_config_abs_dir="xx/yy.json"
49-
)
50-
redis_creator1=tfra.dynamic_embedding.RedisTableCreator(redis_config1)
47+
cuckoo_creator=tfra.dynamic_embedding.CuckooHashTableCreator(saver=de.FileSystemSaver())
5148
```
5249

5350
<h2 id="__init__"><code>__init__</code></h2>

0 commit comments

Comments
 (0)