Skip to content

Commit

Permalink
[feat] add Hashtable On GPU
Browse files Browse the repository at this point in the history
  • Loading branch information
rhdong committed May 11, 2021
1 parent c292754 commit 1404bd0
Show file tree
Hide file tree
Showing 154 changed files with 49,815 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.7.2
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ artifacts/# File patterns to ignore; see `git help ignore` for more information.
# Lines that start with '#' are comments.

*.whl
/build_deps/
/bazel-bin/
/bazel-out/
/bazel-recommenders-addons/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ If you need to work with other versions of TensorFlow, we recommend you installi


#### Installing from Source
You can also install from source. This requires the [Bazel](https://bazel.build/) build system (version >= 1.0.0).
You can also install from source. This requires the [Bazel](https://bazel.build/) build system (version == 3.7.2).

```
git clone https://github.com/tensorflow/recommenders-addons.git
Expand Down
13 changes: 12 additions & 1 deletion 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 with:
Install Clang-format 9 for Ubuntu:

```bash
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
Expand All @@ -27,6 +27,17 @@ format all with:
clang-format-9 -i --style=google **/*.cc **/*.h
```

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

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

#### Python
Recommenders Addons use [Yapf](https://github.com/google/yapf) to format our code.
The continuous integration check will fail if you do not use it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ cc_toolchain_config(
"/dt7/usr/lib/gcc/x86_64-pc-linux-gnu/7/include",
"/dt7/usr/lib/gcc/x86_64-pc-linux-gnu/7/include-fixed",
"/dt7/usr/include",
"/usr/local/cuda-10.1/targets/x86_64-linux/include",
"/usr/local/cuda-10.1/include",
"/usr/local/cuda-10.1/extras/CUPTI/include",
"/usr/local/cuda-11.0/targets/x86_64-linux/include",
"/usr/local/cuda-11.0/include",
"/usr/local/cuda-11.0/extras/CUPTI/include",
"/usr/include",
],
cpu = "local",
Expand Down Expand Up @@ -93,6 +93,9 @@ cc_toolchain_config(
"/dt7/usr/lib/gcc/x86_64-pc-linux-gnu/7/include",
"/dt7/usr/lib/gcc/x86_64-pc-linux-gnu/7/include-fixed",
"/dt7/usr/include",
"/usr/local/cuda-11.0/targets/x86_64-linux/include",
"/usr/local/cuda-11.0/include",
"/usr/local/cuda-11.0/extras/CUPTI/include",
"/usr/include",
],
cpu = "darwin",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ import pipes
CPU_COMPILER = ('/dt7/usr/bin/gcc')
GCC_HOST_COMPILER_PATH = ('/dt7/usr/bin/gcc')

NVCC_PATH = '/usr/local/cuda-10.1/bin/nvcc'
NVCC_PATH = '/usr/local/cuda-11.0/bin/nvcc'
PREFIX_DIR = os.path.dirname(GCC_HOST_COMPILER_PATH)
NVCC_VERSION = '10.1'

NVCC_VERSION = '11.0'

def Log(s):
print('gpus/crosstool: {0}'.format(s))
Expand All @@ -55,7 +54,7 @@ def GetOptionValue(argv, option):
Args:
argv: A list of strings, possibly the argv passed to main().
option: The option whose value to extract, without the leading '-'.
option: The option whose value to extract, with the leading '-'.
Returns:
A list of values, either directly following the option,
Expand All @@ -64,7 +63,8 @@ def GetOptionValue(argv, option):
"""

parser = ArgumentParser()
parser.add_argument('-' + option, nargs='*', action='append')
parser.add_argument(option, nargs='*', action='append')
option = option.lstrip('-').replace('-', '_')
args, _ = parser.parse_known_args(argv)
if not args or not vars(args)[option]:
return []
Expand Down Expand Up @@ -109,17 +109,13 @@ def GetHostCompilerOptions(argv):

return opts


def _update_options(nvcc_options):
if NVCC_VERSION in ("7.0",):
return nvcc_options

update_options = {"relaxed-constexpr": "expt-relaxed-constexpr"}
return [
update_options[opt] if opt in update_options else opt
for opt in nvcc_options
]

update_options = { "relaxed-constexpr" : "expt-relaxed-constexpr" }
return [ update_options[opt] if opt in update_options else opt
for opt in nvcc_options ]

def GetNvccOptions(argv):
"""Collect the -nvcc_options values from argv.
Expand All @@ -138,9 +134,24 @@ def GetNvccOptions(argv):

if args.nvcc_options:
options = _update_options(sum(args.nvcc_options, []))
return ' '.join(['--' + a for a in options])
return ' '.join(['--'+a for a in options])
return ''

def system(cmd):
"""Invokes cmd with os.system().
Args:
cmd: The command.
Returns:
The exit code if the process exited with exit() or -signal
if the process was terminated by a signal.
"""
retv = os.system(cmd)
if os.WIFEXITED(retv):
return os.WEXITSTATUS(retv)
else:
return -os.WTERMSIG(retv)

def InvokeNvcc(argv, log=False):
"""Call nvcc with arguments assembled from argv.
Expand All @@ -150,32 +161,32 @@ def InvokeNvcc(argv, log=False):
log: True if logging is requested.
Returns:
The return value of calling os.system('nvcc ' + args)
The return value of calling system('nvcc ' + args)
"""

host_compiler_options = GetHostCompilerOptions(argv)
nvcc_compiler_options = GetNvccOptions(argv)
opt_option = GetOptionValue(argv, 'O')
m_options = GetOptionValue(argv, 'm')
opt_option = GetOptionValue(argv, '-O')
m_options = GetOptionValue(argv, '-m')
m_options = ''.join([' -m' + m for m in m_options if m in ['32', '64']])
include_options = GetOptionValue(argv, 'I')
out_file = GetOptionValue(argv, 'o')
depfiles = GetOptionValue(argv, 'MF')
defines = GetOptionValue(argv, 'D')
include_options = GetOptionValue(argv, '-I')
out_file = GetOptionValue(argv, '-o')
depfiles = GetOptionValue(argv, '-MF')
defines = GetOptionValue(argv, '-D')
defines = ''.join([' -D' + define for define in defines])
undefines = GetOptionValue(argv, 'U')
undefines = GetOptionValue(argv, '-U')
undefines = ''.join([' -U' + define for define in undefines])
std_options = GetOptionValue(argv, 'std')
# currently only c++11 is supported by Cuda 7.0 std argument
nvcc_allowed_std_options = ["c++11"]
std_options = ''.join([
' -std=' + define for define in std_options
if define in nvcc_allowed_std_options
])
std_options = GetOptionValue(argv, '-std')
# Supported -std flags as of CUDA 9.0. Only keep last to mimic gcc/clang.
nvcc_allowed_std_options = ["c++03", "c++11", "c++14"]
std_options = ''.join([' -std=' + define
for define in std_options if define in nvcc_allowed_std_options][-1:])
fatbin_options = ''.join([' --fatbin-options=' + option
for option in GetOptionValue(argv, '-Xcuda-fatbinary')])

# The list of source files get passed after the -c option. I don't know of
# any other reliable way to just get the list of source files to be compiled.
src_files = GetOptionValue(argv, 'c')
src_files = GetOptionValue(argv, '-c')

# Pass -w through from host to nvcc, but don't do anything fancier with
# warnings-related flags, since they're not necessarily the same across
Expand All @@ -187,55 +198,61 @@ def InvokeNvcc(argv, log=False):
if len(out_file) != 1:
return 1

opt = (' -O2' if
(len(opt_option) > 0 and int(opt_option[0]) > 0) else ' -g -G')
opt = (' -O2' if (len(opt_option) > 0 and int(opt_option[0]) > 0)
else ' -g')

includes = (' -I ' + ' -I '.join(include_options)
if len(include_options) > 0 else '')
if len(include_options) > 0
else '')

# Unfortunately, there are other options that have -c prefix too.
# So allowing only those look like C/C++ files.
src_files = [
f for f in src_files if re.search('\.cpp$|\.cc$|\.c$|\.cxx$|\.C$', f)
]
src_files = [f for f in src_files if
re.search('\.cpp$|\.cc$|\.c$|\.cxx$|\.C$', f)]
srcs = ' '.join(src_files)
out = ' -o ' + out_file[0]

supported_cuda_compute_capabilities = ["3.0", "6.0"]
nvccopts = '-D_FORCE_INLINES '
for capability in supported_cuda_compute_capabilities:
capability = capability.replace('.', '')
nvccopts += r'-gencode=arch=compute_%s,\"code=sm_%s,compute_%s\" ' % (
capability, capability, capability)
nvccopts += ' ' + nvcc_compiler_options
for capability in GetOptionValue(argv, "--cuda-gpu-arch"):
capability = capability[len('sm_'):]
nvccopts += r'-gencode=arch=compute_%s,\"code=sm_%s\" ' % (capability,
capability)
for capability in GetOptionValue(argv, '--cuda-include-ptx'):
capability = capability[len('sm_'):]
nvccopts += r'-gencode=arch=compute_%s,\"code=compute_%s\" ' % (capability,
capability)
nvccopts += nvcc_compiler_options
nvccopts += undefines
nvccopts += defines
nvccopts += std_options
nvccopts += m_options
nvccopts += warning_options
nvccopts += fatbin_options

if depfiles:
# Generate the dependency file
depfile = depfiles[0]
cmd = (NVCC_PATH + ' ' + nvccopts + ' --compiler-options "' +
host_compiler_options + '"' + ' --compiler-bindir=' +
GCC_HOST_COMPILER_PATH + ' -I .' + ' -x cu ' + opt + includes +
' ' + srcs + ' -M -o ' + depfile)
cmd = (NVCC_PATH + ' ' + nvccopts +
' --compiler-options "' + host_compiler_options + '"' +
' --compiler-bindir=' + GCC_HOST_COMPILER_PATH +
' -I .' +
' -x cu ' + opt + includes + ' ' + srcs + ' -M -o ' + depfile)
if log: Log(cmd)
exit_status = os.system(cmd)
exit_status = system(cmd)
if exit_status != 0:
return exit_status

cmd = (NVCC_PATH + ' ' + nvccopts + ' --compiler-options "' +
host_compiler_options + ' -fPIC"' + ' --compiler-bindir=' +
GCC_HOST_COMPILER_PATH + ' -I .' + ' -x cu ' + opt + includes +
' -c ' + srcs + out)
cmd = (NVCC_PATH + ' ' + nvccopts +
' --compiler-options "' + host_compiler_options + ' -fPIC"' +
' --compiler-bindir=' + GCC_HOST_COMPILER_PATH +
' -I .' +
' -x cu ' + opt + includes + ' -c ' + srcs + out)

# TODO(zhengxq): for some reason, 'gcc' needs this help to find 'as'.
# Need to investigate and fix.
cmd = 'PATH=' + PREFIX_DIR + ':$PATH ' + cmd
if log: Log(cmd)
return os.system(cmd)
return system(cmd)


def main():
Expand All @@ -255,12 +272,10 @@ def main():
# We not only want to pass -x to the CPU compiler, but also keep it in its
# relative location in the argv list (the compiler is actually sensitive to
# this).
cpu_compiler_flags = [
flag for flag in sys.argv[1:] if not flag.startswith(('--cuda_log'))
]
cpu_compiler_flags = [flag for flag in sys.argv[1:]
if not flag.startswith(('--cuda_log'))]

return subprocess.call([CPU_COMPILER] + cpu_compiler_flags)


if __name__ == '__main__':
sys.exit(main())
16 changes: 15 additions & 1 deletion build_deps/toolchains/gpu/cuda_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ _PYTHON_BIN_PATH = "PYTHON_BIN_PATH"
_DEFAULT_CUDA_COMPUTE_CAPABILITIES = [
"3.5",
"5.2",
"6.1",
"7.0",
"7.5",
"8.0",
"8.6",
]

def _get_python_bin(repository_ctx):
Expand Down Expand Up @@ -555,7 +560,7 @@ def _find_libs(repository_ctx, cuda_config):
repository_ctx,
cpu_value,
cuda_config.config["cuda_library_dir"],
cuda_config.cuda_version,
cuda_config.cudart_version,
),
"cudart_static": _find_cuda_lib(
"cudart_static",
Expand Down Expand Up @@ -622,6 +627,7 @@ def _get_cuda_config(repository_ctx):
cuda_toolkit_path: The CUDA toolkit installation directory.
cudnn_install_basedir: The cuDNN installation directory.
cuda_version: The version of CUDA on the system.
cudart_version: The CUDA runtime version on the system.
cudnn_version: The version of cuDNN on the system.
compute_capabilities: A list of the system's CUDA compute capabilities.
cpu_value: The name of the host operating system.
Expand All @@ -639,6 +645,11 @@ def _get_cuda_config(repository_ctx):
cudnn_version = ("64_%s" if is_windows else "%s") % config["cudnn_version"]

if int(cuda_major) >= 11:
# The libcudart soname in CUDA 11.x is versioned as 11.0 for backward compatability.
if int(cuda_major) == 11:
cudart_version = "64_110" if is_windows else "11.0"
else:
cudart_version = ("64_%s" if is_windows else "%s") % cuda_major
cublas_version = ("64_%s" if is_windows else "%s") % config["cublas_version"].split(".")[0]
cusolver_version = ("64_%s" if is_windows else "%s") % config["cusolver_version"].split(".")[0]
curand_version = ("64_%s" if is_windows else "%s") % config["curand_version"].split(".")[0]
Expand All @@ -651,15 +662,18 @@ def _get_cuda_config(repository_ctx):
cusolver_version = cuda_lib_version
curand_version = cuda_lib_version
cufft_version = cuda_lib_version
cudart_version = cuda_version
else:
cublas_version = cuda_version
cusolver_version = cuda_version
curand_version = cuda_version
cufft_version = cuda_version
cudart_version = cuda_version

return struct(
cuda_toolkit_path = toolkit_path,
cuda_version = cuda_version,
cudart_version = cudart_version,
cublas_version = cublas_version,
cusolver_version = cusolver_version,
curand_version = curand_version,
Expand Down
Loading

0 comments on commit 1404bd0

Please sign in to comment.