add hipsparse to the local_config_rocm repository
This commit is contained in:
parent
9a4295cb3d
commit
9e7eae9f71
7
third_party/gpus/rocm/BUILD.tpl
vendored
7
third_party/gpus/rocm/BUILD.tpl
vendored
@ -137,4 +137,11 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_import(
|
||||||
|
name = "hipsparse",
|
||||||
|
hdrs = glob(["rocm/include/hipsparse/**",]),
|
||||||
|
shared_library = "rocm/lib/%{hipsparse_lib}",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
%{copy_rules}
|
%{copy_rules}
|
||||||
|
2
third_party/gpus/rocm/rocm_config.h.tpl
vendored
2
third_party/gpus/rocm/rocm_config.h.tpl
vendored
@ -16,6 +16,6 @@ limitations under the License.
|
|||||||
#ifndef ROCM_ROCM_CONFIG_H_
|
#ifndef ROCM_ROCM_CONFIG_H_
|
||||||
#define ROCM_ROCM_CONFIG_H_
|
#define ROCM_ROCM_CONFIG_H_
|
||||||
|
|
||||||
#define TF_ROCM_TOOLKIT_PATH "/opt/rocm"
|
#define TF_ROCM_TOOLKIT_PATH "%{rocm_toolkit_path}"
|
||||||
|
|
||||||
#endif // ROCM_ROCM_CONFIG_H_
|
#endif // ROCM_ROCM_CONFIG_H_
|
||||||
|
89
third_party/gpus/rocm_configure.bzl
vendored
89
third_party/gpus/rocm_configure.bzl
vendored
@ -191,54 +191,54 @@ def _rocm_include_path(repository_ctx, rocm_config):
|
|||||||
inc_dirs.append(rocm_config.rocm_toolkit_path + "/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/include")
|
||||||
|
|
||||||
# Add HSA headers
|
# Add HSA headers
|
||||||
inc_dirs.append("/opt/rocm/hsa/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hsa/include")
|
||||||
|
|
||||||
# Add HIP headers
|
# Add HIP headers
|
||||||
inc_dirs.append("/opt/rocm/include/hip")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/include/hip")
|
||||||
inc_dirs.append("/opt/rocm/include/hip/hcc_detail")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/include/hip/hcc_detail")
|
||||||
inc_dirs.append("/opt/rocm/hip/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hip/include")
|
||||||
|
|
||||||
# Add HIP-Clang headers
|
# Add HIP-Clang headers
|
||||||
inc_dirs.append("/opt/rocm/llvm/lib/clang/8.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/llvm/lib/clang/8.0/include")
|
||||||
inc_dirs.append("/opt/rocm/llvm/lib/clang/9.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/llvm/lib/clang/9.0.0/include")
|
||||||
inc_dirs.append("/opt/rocm/llvm/lib/clang/10.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/llvm/lib/clang/10.0.0/include")
|
||||||
|
|
||||||
# Add rocrand and hiprand headers
|
# Add rocrand and hiprand headers
|
||||||
inc_dirs.append("/opt/rocm/rocrand/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/rocrand/include")
|
||||||
inc_dirs.append("/opt/rocm/hiprand/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hiprand/include")
|
||||||
|
|
||||||
# Add rocfft headers
|
# Add rocfft headers
|
||||||
inc_dirs.append("/opt/rocm/rocfft/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/rocfft/include")
|
||||||
|
|
||||||
# Add rocBLAS headers
|
# Add rocBLAS headers
|
||||||
inc_dirs.append("/opt/rocm/rocblas/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/rocblas/include")
|
||||||
|
|
||||||
# Add MIOpen headers
|
# Add MIOpen headers
|
||||||
inc_dirs.append("/opt/rocm/miopen/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/miopen/include")
|
||||||
|
|
||||||
# Add RCCL headers
|
# Add RCCL headers
|
||||||
inc_dirs.append("/opt/rocm/rccl/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/rccl/include")
|
||||||
|
|
||||||
# Add hcc headers
|
# Add hcc headers
|
||||||
inc_dirs.append("/opt/rocm/hcc/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/include")
|
||||||
inc_dirs.append("/opt/rocm/hcc/compiler/lib/clang/7.0.0/include/")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/compiler/lib/clang/7.0.0/include/")
|
||||||
inc_dirs.append("/opt/rocm/hcc/lib/clang/7.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/lib/clang/7.0.0/include")
|
||||||
|
|
||||||
# Newer hcc builds use/are based off of clang 8.0.0.
|
# Newer hcc builds use/are based off of clang 8.0.0.
|
||||||
inc_dirs.append("/opt/rocm/hcc/compiler/lib/clang/8.0.0/include/")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/compiler/lib/clang/8.0.0/include/")
|
||||||
inc_dirs.append("/opt/rocm/hcc/lib/clang/8.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/lib/clang/8.0.0/include")
|
||||||
|
|
||||||
# Support hcc based off clang 9.0.0, included in ROCm2.2
|
# Support hcc based off clang 9.0.0, included in ROCm2.2
|
||||||
inc_dirs.append("/opt/rocm/hcc/compiler/lib/clang/9.0.0/include/")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/compiler/lib/clang/9.0.0/include/")
|
||||||
inc_dirs.append("/opt/rocm/hcc/lib/clang/9.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/lib/clang/9.0.0/include")
|
||||||
|
|
||||||
# Support hcc based off clang 10.0.0, included in ROCm2.8
|
# Support hcc based off clang 10.0.0, included in ROCm2.8
|
||||||
inc_dirs.append("/opt/rocm/hcc/compiler/lib/clang/10.0.0/include/")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/compiler/lib/clang/10.0.0/include/")
|
||||||
inc_dirs.append("/opt/rocm/hcc/lib/clang/10.0.0/include")
|
inc_dirs.append(rocm_config.rocm_toolkit_path + "/hcc/lib/clang/10.0.0/include")
|
||||||
|
|
||||||
return inc_dirs
|
return inc_dirs
|
||||||
|
|
||||||
def _enable_rocm(repository_ctx):
|
def enable_rocm(repository_ctx):
|
||||||
if "TF_NEED_ROCM" in repository_ctx.os.environ:
|
if "TF_NEED_ROCM" in repository_ctx.os.environ:
|
||||||
enable_rocm = repository_ctx.os.environ["TF_NEED_ROCM"].strip()
|
enable_rocm = repository_ctx.os.environ["TF_NEED_ROCM"].strip()
|
||||||
if enable_rocm == "1":
|
if enable_rocm == "1":
|
||||||
@ -300,11 +300,12 @@ def _hipcc_env(repository_ctx):
|
|||||||
repository_ctx.os.environ[name].strip() + "\";")
|
repository_ctx.os.environ[name].strip() + "\";")
|
||||||
return hipcc_env.strip()
|
return hipcc_env.strip()
|
||||||
|
|
||||||
def _hipcc_is_hipclang(repository_ctx):
|
def _hipcc_is_hipclang(repository_ctx, rocm_config):
|
||||||
"""Returns if hipcc is based on hip-clang toolchain.
|
"""Returns if hipcc is based on hip-clang toolchain.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
repository_ctx: The repository context.
|
repository_ctx: The repository context.
|
||||||
|
rocm_config: The path to the hip compiler.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A string "True" if hipcc is based on hip-clang toolchain.
|
A string "True" if hipcc is based on hip-clang toolchain.
|
||||||
@ -319,7 +320,7 @@ def _hipcc_is_hipclang(repository_ctx):
|
|||||||
# grep for "HIP_COMPILER=clang" in /opt/rocm/hip/lib/.hipInfo
|
# grep for "HIP_COMPILER=clang" in /opt/rocm/hip/lib/.hipInfo
|
||||||
grep_result = _execute(
|
grep_result = _execute(
|
||||||
repository_ctx,
|
repository_ctx,
|
||||||
["grep", "HIP_COMPILER=clang", "/opt/rocm/hip/lib/.hipInfo"],
|
["grep", "HIP_COMPILER=clang", rocm_config.rocm_toolkit_path + "/hip/lib/.hipInfo"],
|
||||||
empty_stdout_fine = True,
|
empty_stdout_fine = True,
|
||||||
)
|
)
|
||||||
result = grep_result.stdout
|
result = grep_result.stdout
|
||||||
@ -327,13 +328,14 @@ def _hipcc_is_hipclang(repository_ctx):
|
|||||||
return "True"
|
return "True"
|
||||||
return "False"
|
return "False"
|
||||||
|
|
||||||
def _if_hipcc_is_hipclang(repository_ctx, if_true, if_false = []):
|
def _if_hipcc_is_hipclang(repository_ctx, rocm_config, if_true, if_false = []):
|
||||||
"""
|
"""
|
||||||
Returns either the if_true or if_false arg based on whether hipcc
|
Returns either the if_true or if_false arg based on whether hipcc
|
||||||
is based on the hip-clang toolchain
|
is based on the hip-clang toolchain
|
||||||
|
|
||||||
Args :
|
Args :
|
||||||
repository_ctx: The repository context.
|
repository_ctx: The repository context.
|
||||||
|
rocm_config: The path to the hip compiler.
|
||||||
if_true : value to return if hipcc is hip-clang based
|
if_true : value to return if hipcc is hip-clang based
|
||||||
if_false : value to return if hipcc is not hip-clang based
|
if_false : value to return if hipcc is not hip-clang based
|
||||||
(optional, defaults to empty list)
|
(optional, defaults to empty list)
|
||||||
@ -341,7 +343,7 @@ def _if_hipcc_is_hipclang(repository_ctx, if_true, if_false = []):
|
|||||||
Returns :
|
Returns :
|
||||||
either the if_true arg or the of_False arg
|
either the if_true arg or the of_False arg
|
||||||
"""
|
"""
|
||||||
if _hipcc_is_hipclang(repository_ctx) == "True":
|
if _hipcc_is_hipclang(repository_ctx, rocm_config) == "True":
|
||||||
return if_true
|
return if_true
|
||||||
return if_false
|
return if_false
|
||||||
|
|
||||||
@ -478,6 +480,11 @@ def _find_libs(repository_ctx, rocm_config):
|
|||||||
repository_ctx,
|
repository_ctx,
|
||||||
rocm_config.rocm_toolkit_path + "/rccl",
|
rocm_config.rocm_toolkit_path + "/rccl",
|
||||||
),
|
),
|
||||||
|
"hipsparse": _find_rocm_lib(
|
||||||
|
"hipsparse",
|
||||||
|
repository_ctx,
|
||||||
|
rocm_config.rocm_toolkit_path + "/hipsparse",
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_rocm_config(repository_ctx):
|
def _get_rocm_config(repository_ctx):
|
||||||
@ -558,6 +565,7 @@ def _create_dummy_repository(repository_ctx):
|
|||||||
"%{rccl_lib}": _lib_name("rccl"),
|
"%{rccl_lib}": _lib_name("rccl"),
|
||||||
"%{rocfft_lib}": _lib_name("rocfft"),
|
"%{rocfft_lib}": _lib_name("rocfft"),
|
||||||
"%{hiprand_lib}": _lib_name("hiprand"),
|
"%{hiprand_lib}": _lib_name("hiprand"),
|
||||||
|
"%{hipsparse_lib}": _lib_name("hipsparse"),
|
||||||
"%{copy_rules}": "",
|
"%{copy_rules}": "",
|
||||||
"%{rocm_headers}": "",
|
"%{rocm_headers}": "",
|
||||||
},
|
},
|
||||||
@ -703,6 +711,12 @@ def _create_local_rocm_repository(repository_ctx):
|
|||||||
src_dir = rocm_toolkit_path + "/rccl/include",
|
src_dir = rocm_toolkit_path + "/rccl/include",
|
||||||
out_dir = "rocm/include/rccl",
|
out_dir = "rocm/include/rccl",
|
||||||
),
|
),
|
||||||
|
make_copy_dir_rule(
|
||||||
|
repository_ctx,
|
||||||
|
name = "hipsparse-include",
|
||||||
|
src_dir = rocm_toolkit_path + "/hipsparse/include",
|
||||||
|
out_dir = "rocm/include/hipsparse",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
rocm_libs = _find_libs(repository_ctx, rocm_config)
|
rocm_libs = _find_libs(repository_ctx, rocm_config)
|
||||||
@ -740,16 +754,19 @@ def _create_local_rocm_repository(repository_ctx):
|
|||||||
"%{hiprand_lib}": rocm_libs["hiprand"].file_name,
|
"%{hiprand_lib}": rocm_libs["hiprand"].file_name,
|
||||||
"%{miopen_lib}": rocm_libs["miopen"].file_name,
|
"%{miopen_lib}": rocm_libs["miopen"].file_name,
|
||||||
"%{rccl_lib}": rocm_libs["rccl"].file_name,
|
"%{rccl_lib}": rocm_libs["rccl"].file_name,
|
||||||
|
"%{hipsparse_lib}": rocm_libs["hipsparse"].file_name,
|
||||||
"%{copy_rules}": "\n".join(copy_rules),
|
"%{copy_rules}": "\n".join(copy_rules),
|
||||||
"%{rocm_headers}": ('":rocm-include",\n' +
|
"%{rocm_headers}": ('":rocm-include",\n' +
|
||||||
'":rocfft-include",\n' +
|
'":rocfft-include",\n' +
|
||||||
'":rocblas-include",\n' +
|
'":rocblas-include",\n' +
|
||||||
'":miopen-include",\n' +
|
'":miopen-include",\n' +
|
||||||
'":rccl-include",'),
|
'":rccl-include",\n' +
|
||||||
|
'":hipsparse-include",'),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set up crosstool/
|
# Set up crosstool/
|
||||||
|
|
||||||
cc = find_cc(repository_ctx)
|
cc = find_cc(repository_ctx)
|
||||||
|
|
||||||
host_compiler_includes = get_cxx_inc_directories(repository_ctx, cc)
|
host_compiler_includes = get_cxx_inc_directories(repository_ctx, cc)
|
||||||
@ -762,7 +779,7 @@ def _create_local_rocm_repository(repository_ctx):
|
|||||||
|
|
||||||
rocm_defines["%{host_compiler_prefix}"] = host_compiler_prefix
|
rocm_defines["%{host_compiler_prefix}"] = host_compiler_prefix
|
||||||
|
|
||||||
rocm_defines["%{linker_bin_path}"] = "/opt/rocm/hcc/compiler/bin"
|
rocm_defines["%{linker_bin_path}"] = rocm_config.rocm_toolkit_path + "/hcc/compiler/bin"
|
||||||
|
|
||||||
# For gcc, do not canonicalize system header paths; some versions of gcc
|
# For gcc, do not canonicalize system header paths; some versions of gcc
|
||||||
# pick the shortest possible path for system includes when creating the
|
# pick the shortest possible path for system includes when creating the
|
||||||
@ -775,7 +792,7 @@ def _create_local_rocm_repository(repository_ctx):
|
|||||||
"-DTENSORFLOW_USE_ROCM=1",
|
"-DTENSORFLOW_USE_ROCM=1",
|
||||||
"-D__HIP_PLATFORM_HCC__",
|
"-D__HIP_PLATFORM_HCC__",
|
||||||
"-DEIGEN_USE_HIP",
|
"-DEIGEN_USE_HIP",
|
||||||
] + _if_hipcc_is_hipclang(repository_ctx, [
|
] + _if_hipcc_is_hipclang(repository_ctx, rocm_config, [
|
||||||
#
|
#
|
||||||
# define "TENSORFLOW_COMPILER_IS_HIP_CLANG" when we are using clang
|
# define "TENSORFLOW_COMPILER_IS_HIP_CLANG" when we are using clang
|
||||||
# based hipcc to compile/build tensorflow
|
# based hipcc to compile/build tensorflow
|
||||||
@ -815,14 +832,14 @@ def _create_local_rocm_repository(repository_ctx):
|
|||||||
"crosstool:clang/bin/crosstool_wrapper_driver_rocm",
|
"crosstool:clang/bin/crosstool_wrapper_driver_rocm",
|
||||||
{
|
{
|
||||||
"%{cpu_compiler}": str(cc),
|
"%{cpu_compiler}": str(cc),
|
||||||
"%{hipcc_path}": "/opt/rocm/bin/hipcc",
|
"%{hipcc_path}": rocm_config.rocm_toolkit_path + "/bin/hipcc",
|
||||||
"%{hipcc_env}": _hipcc_env(repository_ctx),
|
"%{hipcc_env}": _hipcc_env(repository_ctx),
|
||||||
"%{hipcc_is_hipclang}": _hipcc_is_hipclang(repository_ctx),
|
"%{hipcc_is_hipclang}": _hipcc_is_hipclang(repository_ctx, rocm_config),
|
||||||
"%{rocr_runtime_path}": "/opt/rocm/lib",
|
"%{rocr_runtime_path}": rocm_config.rocm_toolkit_path + "/lib",
|
||||||
"%{rocr_runtime_library}": "hsa-runtime64",
|
"%{rocr_runtime_library}": "hsa-runtime64",
|
||||||
"%{hip_runtime_path}": "/opt/rocm/hip/lib",
|
"%{hip_runtime_path}": rocm_config.rocm_toolkit_path + "/hip/lib",
|
||||||
"%{hip_runtime_library}": "hip_hcc",
|
"%{hip_runtime_library}": "hip_hcc",
|
||||||
"%{hcc_runtime_path}": "/opt/rocm/hcc/lib",
|
"%{hcc_runtime_path}": rocm_config.rocm_toolkit_path + "/hcc/lib",
|
||||||
"%{hcc_runtime_library}": "mcwamp",
|
"%{hcc_runtime_library}": "mcwamp",
|
||||||
"%{crosstool_verbose}": _crosstool_verbose(repository_ctx),
|
"%{crosstool_verbose}": _crosstool_verbose(repository_ctx),
|
||||||
"%{gcc_host_compiler_path}": str(cc),
|
"%{gcc_host_compiler_path}": str(cc),
|
||||||
@ -878,7 +895,7 @@ def _create_remote_rocm_repository(repository_ctx, remote_config_repo):
|
|||||||
|
|
||||||
def _rocm_autoconf_impl(repository_ctx):
|
def _rocm_autoconf_impl(repository_ctx):
|
||||||
"""Implementation of the rocm_autoconf repository rule."""
|
"""Implementation of the rocm_autoconf repository rule."""
|
||||||
if not _enable_rocm(repository_ctx):
|
if not enable_rocm(repository_ctx):
|
||||||
_create_dummy_repository(repository_ctx)
|
_create_dummy_repository(repository_ctx)
|
||||||
elif _TF_ROCM_CONFIG_REPO in repository_ctx.os.environ:
|
elif _TF_ROCM_CONFIG_REPO in repository_ctx.os.environ:
|
||||||
_create_remote_rocm_repository(
|
_create_remote_rocm_repository(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user