Skip to content

Commit

Permalink
support bazel build
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Nineteen authored and rhdong committed Apr 4, 2023
1 parent f8a15cc commit 349b09c
Show file tree
Hide file tree
Showing 23 changed files with 3,942 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build -c opt
build --copt -O3
build --copt -pthread
build --linkopt -pthread
build --linkopt -ldl
build --incompatible_linkopts_to_linklibs
build --copt -g --strip=never
build --experimental_repo_remote_exec

# This config refers to building CUDA kernels with nvcc.
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain

# CUDA options
build:cuda --action_env GCC_HOST_COMPILER_PATH="/opt/rh/devtoolset-9/root/usr/bin/gcc"
build:cuda --action_env CUDA_TOOLKIT_PATH="/usr/local/cuda"
build:cuda --action_env CUDA_VERSION="11"
build:cuda --action_env CUDNN_VERSION="8"
build:cuda --action_env CUDNN_INSTALL_PATH="/usr/local/cuda"
build:cuda --action_env CUDA_COMPUTE_CAPABILITIES="7.5"
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and also open for public contributions, bug fixes, and documentation. [[Contribu

Basically, HierarchicalKV is a headers only library, the commands below only create binaries for benchmark and unit testing.

### with cmake
```shell
git clone --recursive https://github.com/NVIDIA-Merlin/HierarchicalKV.git
cd HierarchicalKV && mkdir -p build && cd build
Expand All @@ -73,6 +74,17 @@ For Unit Test:
./merlin_hashtable_test
```

### with bazel
```shell
git clone --recursive https://github.com/NVIDIA-Merlin/HierarchicalKV.git
cd HierarchicalKV && bazel build --config=cuda //...
```

For Benchmark:
```shell
./benchmark_util
```

Your environment must meet the following requirements:

- CUDA version >= 11.2
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
workspace(name = "HierarchicalKV")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//build_deps/gpus:configure.bzl", "cuda_configure")

http_archive(
name = "bazel_skylib",
sha256 = "1dde365491125a3db70731e25658dfdd3bc5dbdfd11b840b3e987ecf043c7ca0",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz",
],
)

cuda_configure(name = "local_config_cuda")
24 changes: 24 additions & 0 deletions benchmark/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library")

cc_binary(
name = "benchmark_util",
deps = [
":benchmark_lib",
],
)

cuda_library(
name = "benchmark_lib",
srcs = [
"merlin_hashtable_benchmark.cc.cu",
],
hdrs = [
"benchmark_util.cuh",
],
copts = ["-Iinclude/"],
linkopts = ["-pthread"],
deps = [
"//include:merlin_hashtable",
"@local_config_cuda//cuda",
],
)
Empty file added build_deps/gpus/BUILD
Empty file.
86 changes: 86 additions & 0 deletions build_deps/gpus/check_cuda_libs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Verifies that a list of libraries is installed on the system.
Takes a list of arguments with every two subsequent arguments being a logical
tuple of (path, check_soname). The path to the library and either True or False
to indicate whether to check the soname field on the shared library.
Example Usage:
./check_cuda_libs.py /path/to/lib1.so True /path/to/lib2.so False
"""
import os
import os.path
import platform
import subprocess
import sys

# pylint: disable=g-import-not-at-top,g-importing-member
try:
from shutil import which
except ImportError:
from distutils.spawn import find_executable as which
# pylint: enable=g-import-not-at-top,g-importing-member


class ConfigError(Exception):
pass


def check_cuda_lib(path, check_soname=True):
"""Tests if a library exists on disk and whether its soname matches the filename.
Args:
path: the path to the library.
check_soname: whether to check the soname as well.
Raises:
ConfigError: If the library does not exist or if its soname does not match
the filename.
"""
if not os.path.isfile(path):
raise ConfigError("No library found under: " + path)
objdump = which("objdump")
if check_soname and objdump is not None:
# Decode is necessary as in py3 the return type changed from str to bytes
output = subprocess.check_output([objdump, "-p", path]).decode("utf-8")
output = [line for line in output.splitlines() if "SONAME" in line]
sonames = [line.strip().split(" ")[-1] for line in output]
if not any(soname == os.path.basename(path) for soname in sonames):
raise ConfigError("None of the libraries match their SONAME: " +
path)


def main():
try:
args = [argv for argv in sys.argv[1:]]
if len(args) % 2 == 1:
raise ConfigError("Expected even number of arguments")
checked_paths = []
for i in range(0, len(args), 2):
path = args[i]
check_cuda_lib(path, check_soname=args[i + 1] == "True")
checked_paths.append(path)
# pylint: disable=superfluous-parens
print(os.linesep.join(checked_paths))
# pylint: enable=superfluous-parens
except ConfigError as e:
sys.stderr.write(str(e))
sys.exit(1)


if __name__ == "__main__":
main()
Loading

0 comments on commit 349b09c

Please sign in to comment.