Skip to content

Commit

Permalink
[Refactor] redesign APIs.
Browse files Browse the repository at this point in the history
Co-authored-by: Lifann <[email protected]>
Co-authored-by: rhdong <[email protected]>
  • Loading branch information
3 people committed Aug 7, 2022
1 parent 87f0a23 commit 3b1a23b
Show file tree
Hide file tree
Showing 30 changed files with 1,318 additions and 4,167 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Google
DerivePointerAlignment: false
IncludeBlocks: Merge
SortIncludes: true
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
option(CLANGFORMAT "Clangformat source code before compiling" ON)
if(CLANGFORMAT)
include(ClangFormat)
file(GLOB_RECURSE clangformat_srcs ${PROJECT_SOURCE_DIR}/cpp *.cpp *.hpp *.cu *.cuh)
file(GLOB_RECURSE clangformat_srcs ${PROJECT_SOURCE_DIR}/ *.cpp *.hpp *.cu *.cuh)
clangformat_setup("${clangformat_srcs}")
endif()

Expand Down Expand Up @@ -37,7 +37,7 @@ foreach(cuda_arch ${cuda_arch_list})
endforeach()

include_directories(
${PROJECT_SOURCE_DIR}/cpp/include
${PROJECT_SOURCE_DIR}/include
)

link_directories(
Expand All @@ -46,10 +46,14 @@ link_directories(
file(GLOB_RECURSE merlin_hkvs_src RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.cu)

# TODO:
# add_library(merlin_hkvs STATIC ${merlin_hkvs_src})
# target_compile_features(merlin_hkvs PUBLIC cxx_std_17)
# target_link_libraries(merlin_hkvs PUBLIC ...)
# add_library(merlin_kv STATIC ${merlin_hkvs_src})
# target_compile_features(merlin_kv PUBLIC cxx_std_17)
# target_link_libraries(merlin_kv PUBLIC ...)

add_executable(merlin_hashtable_test cpp/tests/merlin_hashtable_test.cc.cu)
add_executable(merlin_hashtable_test tests/merlin_hashtable_test.cc.cu)
target_compile_features(merlin_hashtable_test PUBLIC cxx_std_17)
set_target_properties(merlin_hashtable_test PROPERTIES CUDA_ARCHITECTURES OFF)

add_executable(merlin_hashtable_benchmark benchmark/merlin_hashtable_benchmark.cc.cu)
target_compile_features(merlin_hashtable_benchmark PUBLIC cxx_std_17)
set_target_properties(merlin_hashtable_benchmark PROPERTIES CUDA_ARCHITECTURES OFF)
79 changes: 41 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Merlin-KV
# Merlin-KV: A generic Key-Value library designed for RecSys
-----------------
![Merlin KV logo](assets/merlin-hkvs.png)

[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](docs/api_docs/)

# What's the Merlin-KV?
Expand Down Expand Up @@ -35,53 +33,58 @@ makes building, evaluating, and serving sophisticated recommenders models easy.
Merlin-KV is maintianed by [NVIDIA Merlin Team](https://github.com/NVIDIA-Merlin)
and also open for public contributions, bug fixes, and documentation. [[Contribute](CONTRIBUTING.md)]

<a href="https://github.com/NVIDIA-Merlin">
<kbd> <img src="./assets/merilin.png" height="70" /> </kbd>
</a>
## How to build

Basically, Merlin-KV is a headers only library, the commands below only create binary for unit testing and benchmark.
```bash
git clone -b 0.1.0-beta https://github.com/NVIDIA-Merlin/merlin-kv.git
cd merlin-kv && mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DSM=80 .. && make -j
```


## Benchmark

* Update time: Aug 4, 2022
* version: tag [r0.1.0](https://github.com/NVIDIA-Merlin/merlin-kv/tree/r0.1.0)
* Key Type = uint64_t
* Value Type = float32 * dim

***Througput Unit: Billion-KV/second***
* Key-Values per OP = 1,048,576
* ***Througput Unit: Billion-KV/second***


### On pure HBM mode:

| dim | capacity | keys_num_per_op | load_factor | HBM(GB) | HMEM(GB) | insert | find |
|----:|------------:|----------------:|------------:|--------:|---------:|-------:|------:|
| 4 | 67108864 | 1048576 | 0.50 | 16 | 0 | 1.167 | 1.750 |
| 4 | 67108864 | 1048576 | 0.75 | 16 | 0 | 0.897 | 1.386 |
| 4 | 67108864 | 1048576 | 1.00 | 16 | 0 | 0.213 | 0.678 |
| 16 | 67108864 | 1048576 | 0.50 | 16 | 0 | 1.114 | 1.564 |
| 16 | 67108864 | 1048576 | 0.75 | 16 | 0 | 0.894 | 1.258 |
| 16 | 67108864 | 1048576 | 1.00 | 16 | 0 | 0.215 | 0.640 |
| 64 | 67108864 | 1048576 | 0.50 | 16 | 0 | 0.873 | 0.915 |
| 64 | 67108864 | 1048576 | 0.75 | 16 | 0 | 0.767 | 0.823 |
| 64 | 67108864 | 1048576 | 1.00 | 16 | 0 | 0.206 | 0.492 |
| 128 | 134217728 | 1048576 | 0.50 | 64 | 0 | 0.664 | 0.613 |
| 128 | 134217728 | 1048576 | 0.75 | 64 | 0 | 0.593 | 0.560 |
| 128 | 134217728 | 1048576 | 1.00 | 64 | 0 | 0.191 | 0.387 |
| dim | capacity | load_factor | HBM(GB) | HMEM(GB) | insert | find |
|----:|------------:|------------:|--------:|---------:|-------:|------:|
| 4 | 67108864 | 0.50 | 16 | 0 | 1.167 | 1.750 |
| 4 | 67108864 | 0.75 | 16 | 0 | 0.897 | 1.386 |
| 4 | 67108864 | 1.00 | 16 | 0 | 0.213 | 0.678 |
| 16 | 67108864 | 0.50 | 16 | 0 | 1.114 | 1.564 |
| 16 | 67108864 | 0.75 | 16 | 0 | 0.894 | 1.258 |
| 16 | 67108864 | 1.00 | 16 | 0 | 0.215 | 0.640 |
| 64 | 67108864 | 0.50 | 16 | 0 | 0.873 | 0.915 |
| 64 | 67108864 | 0.75 | 16 | 0 | 0.767 | 0.823 |
| 64 | 67108864 | 1.00 | 16 | 0 | 0.206 | 0.492 |
| 128 | 134217728 | 0.50 | 64 | 0 | 0.664 | 0.613 |
| 128 | 134217728 | 0.75 | 64 | 0 | 0.593 | 0.560 |
| 128 | 134217728 | 1.00 | 64 | 0 | 0.191 | 0.387 |

### On HBM+HMEM hybrid mode:

| dim | capacity | keys_num_per_op | load_factor | HBM(GB) | HMEM(GB) | insert | find |
|----:|------------:|----------------:|------------:|--------:|---------:|-------:|------:|
| 64 | 134217728 | 1048576 | 0.50 | 16 | 16 | 0.107 | 0.103 |
| 64 | 134217728 | 1048576 | 0.75 | 16 | 16 | 0.106 | 0.101 |
| 64 | 134217728 | 1048576 | 1.00 | 16 | 16 | 0.077 | 0.094 |
| 64 | 1073741824 | 1048576 | 0.50 | 56 | 200 | 0.037 | 0.040 |
| 64 | 1073741824 | 1048576 | 0.75 | 56 | 200 | 0.037 | 0.040 |
| 64 | 1073741824 | 1048576 | 1.00 | 56 | 200 | 0.030 | 0.036 |
| 128 | 67108864 | 1048576 | 0.50 | 16 | 16 | 0.076 | 0.072 |
| 128 | 67108864 | 1048576 | 0.75 | 16 | 16 | 0.071 | 0.071 |
| 128 | 67108864 | 1048576 | 1.00 | 16 | 16 | 0.059 | 0.068 |
| 128 | 536870912 | 1048576 | 0.50 | 56 | 200 | 0.039 | 0.040 |
| 128 | 536870912 | 1048576 | 0.75 | 56 | 200 | 0.041 | 0.040 |
| 128 | 536870912 | 1048576 | 1.00 | 56 | 200 | 0.035 | 0.038 |
| dim | capacity | load_factor | HBM(GB) | HMEM(GB) | insert | find |
|----:|------------:|------------:|--------:|---------:|-------:|------:|
| 64 | 134217728 | 0.50 | 16 | 16 | 0.107 | 0.103 |
| 64 | 134217728 | 0.75 | 16 | 16 | 0.106 | 0.101 |
| 64 | 134217728 | 1.00 | 16 | 16 | 0.077 | 0.094 |
| 64 | 1073741824 | 0.50 | 56 | 200 | 0.037 | 0.040 |
| 64 | 1073741824 | 0.75 | 56 | 200 | 0.037 | 0.040 |
| 64 | 1073741824 | 1.00 | 56 | 200 | 0.030 | 0.036 |
| 128 | 67108864 | 0.50 | 16 | 16 | 0.076 | 0.072 |
| 128 | 67108864 | 0.75 | 16 | 16 | 0.071 | 0.071 |
| 128 | 67108864 | 1.00 | 16 | 16 | 0.059 | 0.068 |
| 128 | 536870912 | 0.50 | 56 | 200 | 0.039 | 0.040 |
| 128 | 536870912 | 0.75 | 56 | 200 | 0.041 | 0.040 |
| 128 | 536870912 | 1.00 | 56 | 200 | 0.035 | 0.038 |


## Tutorials & Demos
Expand All @@ -91,7 +94,7 @@ Merlin-KV is positioned as a header-only library. The environment requirement is
- CUDA version >= 11.2
- NVIDIA GPU with Compute capbility 8.0 8.6 or 8.7

See [tutorials](docs/api_docs/html/index.html) and [demo(TBD)](cpp/tests/merlin_hashtable_test.cc.cu) for end-to-end examples of each subpackages.
See [tutorials](docs/api_docs/html/index.html) and [demo(TBD)](tests/merlin_hashtable_test.cc.cu) for end-to-end examples of each subpackages.

## API docs

Expand Down
63 changes: 2 additions & 61 deletions STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int formatted_code;
void formatted_code_again;
```

Install Clang-format 9 for Ubuntu:
Install Clang-format 9 (9.0.1-12) for Ubuntu:

```bash
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Expand All @@ -24,64 +24,5 @@ sudo apt install clang-format-9

format all with:
```bash
find ./ -iname *.h -o -iname *.cpp -o -iname *.cc -o -iname *.cu -o -iname *.cuh | xargs clang-format-9 -i --style=google
find ./ -iname *.h -o -iname *.cpp -o -iname *.cc -o -iname *.cu -o -iname *.cuh | xargs clang-format-9 -i --style=file
```

Install Clang-format for MacOS:
```bash
brew update
brew install clang-format
```

format all with:
```bash
clang-format -i --style=google **/*.cc merlin_kv/**/*.h
```

#### Python
Merlin-KV use [Yapf](https://github.com/google/yapf) to format our code.
The continuous integration check will fail if you do not use it.

Install them with:
```
pip install yapf
```

Be sure to run it before you push your commits, otherwise the CI will fail!

```
find . -name '*.py' -print0 | xargs -0 yapf --style=./.yapf -ir
```

#### Bazel BUILD
Use [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md) in project [bazelbuild/buildtools](https://github.com/bazelbuild/buildtools) to format the bazel code.

Install it with:
```bash
git clone https://github.com/bazelbuild/buildtools.git
cd buildtools
bazel build //buildifier
```
Then copy the binary to directory on $PATH. (such as "/usr/local/bin")
```bash
cp bazel-bin/buildifier/buildifier_/buildifier /usr/local/bin
```

Run following commmand to see whether if installation ok:
```bash
buildifier --version
```

Use `buildifier`
```bash
buildifier -mode diff ${your_file_name}
```
to see formating problem in the BUILD file, or:
```bash
buildifier -mode diff ${directory}
```
for all BUILD files in ${directory}.

#### TensorFlow Conventions

Follow the guidance in the [TensorFlow Style Guide - Conventions](https://www.tensorflow.org/community/contribute/code_style#tensorflow_conventions_and_special_uses).
Binary file removed assets/merlin-hkvs.png
Binary file not shown.
Loading

0 comments on commit 3b1a23b

Please sign in to comment.