--- a/configure.py +++ b/configure.py @@ -1347,7 +1347,7 @@ if (environ_cp.get('TF_NEED_ROCM') == '1' and environ_cp.get('ROCM_PATH')): write_action_env_to_bazelrc('ROCM_PATH', environ_cp.get('ROCM_PATH')) write_action_env_to_bazelrc('ROCBLAS_TENSILE_LIBPATH', - environ_cp.get('ROCM_PATH') + '/lib/library') + environ_cp.get('ROCM_PATH') + '/lib64/rocblas/library') if (environ_cp.get('TF_NEED_ROCM') == '1' and environ_cp.get('HIP_PLATFORM')): write_action_env_to_bazelrc('HIP_PLATFORM', environ_cp.get('HIP_PLATFORM')) --- a/tensorflow/core/util/gpu_solvers.h +++ b/tensorflow/core/util/gpu_solvers.h @@ -32,7 +32,7 @@ #include "third_party/gpus/cuda/include/cusolverDn.h" #else #include "rocm/include/hip/hip_complex.h" -#include "rocm/include/rocblas.h" +#include "rocm/include/rocblas/rocblas.h" #include "tensorflow/stream_executor/blas.h" #include "tensorflow/stream_executor/rocm/rocsolver_wrapper.h" #endif --- a/tensorflow/stream_executor/rocm/hipsolver_wrapper.h +++ b/tensorflow/stream_executor/rocm/hipsolver_wrapper.h @@ -24,7 +24,7 @@ #if TF_ROCM_VERSION >= 40500 -#include "rocm/include/hipsolver.h" +#include "rocm/include/hipsolver/hipsolver.h" #include "tensorflow/stream_executor/lib/env.h" #include "tensorflow/stream_executor/platform/dso_loader.h" #include "tensorflow/stream_executor/platform/port.h" --- a/tensorflow/stream_executor/rocm/rocblas_wrapper.h +++ b/tensorflow/stream_executor/rocm/rocblas_wrapper.h @@ -20,7 +20,7 @@ #ifndef TENSORFLOW_STREAM_EXECUTOR_ROCM_ROCBLAS_WRAPPER_H_ #define TENSORFLOW_STREAM_EXECUTOR_ROCM_ROCBLAS_WRAPPER_H_ -#include "rocm/include/rocblas.h" +#include "rocm/include/rocblas/rocblas.h" #include "tensorflow/stream_executor/gpu/gpu_activation.h" #include "tensorflow/stream_executor/lib/env.h" #include "tensorflow/stream_executor/platform/dso_loader.h" --- a/tensorflow/stream_executor/rocm/rocm_blas.h +++ b/tensorflow/stream_executor/rocm/rocm_blas.h @@ -21,7 +21,7 @@ #define TENSORFLOW_STREAM_EXECUTOR_ROCM_ROCM_BLAS_H_ #include "absl/synchronization/mutex.h" -#include "rocm/include/rocblas.h" +#include "rocm/include/rocblas/rocblas.h" #include "tensorflow/core/platform/thread_annotations.h" #include "tensorflow/stream_executor/blas.h" #include "tensorflow/stream_executor/platform/port.h" --- a/tensorflow/compiler/mlir/tools/kernel_gen/transforms/gpu_kernel_to_blob_pass.cc +++ b/tensorflow/compiler/mlir/tools/kernel_gen/transforms/gpu_kernel_to_blob_pass.cc @@ -229,7 +229,8 @@ "compute_)"); } int arch; - if (!absl::SimpleAtoi(consumable_arch, &arch)) { + absl::SimpleAtoi(consumable_arch, &arch); + if(arch <= 0) { return tensorflow::errors::Internal( "Could not parse cuda architecture number"); } --- a/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc +++ b/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc @@ -739,7 +739,7 @@ // Locate lld. // TODO(whchung@gmail.com): change to tensorflow::ROCmRoot() after // ROCm-Device-Libs PR. - std::string lld_path = tensorflow::io::JoinPath("/opt/rocm", "llvm/bin"); + std::string lld_path = tensorflow::io::JoinPath("@GENTOO_PORTAGE_EPREFIX@/usr", "bin"); auto lld_program = llvm::sys::findProgramByName("ld.lld", {lld_path}); if (!lld_program) { return xla::InternalError("unable to find ld.lld in PATH: %s", --- a/tensorflow/core/platform/default/rocm_rocdl_path.cc +++ b/tensorflow/core/platform/default/rocm_rocdl_path.cc @@ -36,7 +36,7 @@ } string RocdlRoot() { - return tensorflow::io::JoinPath(tensorflow::RocmRoot(), "amdgcn/bitcode"); + return tensorflow::io::JoinPath(tensorflow::RocmRoot(), "lib64/amdgcn/bitcode"); } } // namespace tensorflow --- a/tensorflow/stream_executor/gpu/asm_compiler.cc +++ b/tensorflow/stream_executor/gpu/asm_compiler.cc @@ -431,7 +431,7 @@ port::StatusOr> BundleGpuAsm( std::vector images, const std::string rocm_root_dir) { std::string clang_offload_bundler_path = - findRocmExecutable("llvm/bin/clang-offload-bundler", rocm_root_dir); + findRocmExecutable("lib/llvm/bin/14/clang-offload-bundler", rocm_root_dir); // Initialise the "--inputs" / "--targets" arguments for the // clang-offload-bundler with a dummy file / host target triple... --- a/third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_rocm.tpl +++ b/third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_rocm.tpl @@ -53,10 +53,10 @@ parser = ArgumentParser() parser.add_argument('-' + option, nargs='*', action='append') args, _ = parser.parse_known_args(argv) - if not args or not vars(args)[option]: + if not args or not vars(args)[option.strip('-').replace('-','_')]: return [] else: - return sum(vars(args)[option], []) + return sum(vars(args)[option.strip('-').replace('-','_')], []) def GetHostCompilerOptions(argv): @@ -136,6 +136,7 @@ hipcc_allowed_std_options = ["c++11", "c++14"] std_options = ''.join([' -std=' + define for define in std_options if define in hipcc_allowed_std_options]) + gpu_archs = GetOptionValue(argv, '-amdgpu-target') # 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. @@ -177,6 +178,7 @@ hipccopts += defines hipccopts += std_options hipccopts += m_options + hipccopts += ' ' + ' '.join(['--amdgpu-target=' + arch for arch in gpu_archs]) if depfiles: # Generate the dependency file --- a/third_party/gpus/find_rocm_config.py +++ b/third_party/gpus/find_rocm_config.py @@ -110,7 +110,7 @@ def _find_hipruntime_config(rocm_install_path): def hipruntime_version_number(path): - version_file = os.path.join(path, "hip/include/hip/hip_version.h") + version_file = os.path.join(path, "include/hip/hip_version.h") if not os.path.exists(version_file): raise ConfigError( 'HIP Runtime version file "{}" not found'.format(version_file)) @@ -132,7 +132,7 @@ def _find_miopen_config(rocm_install_path): def miopen_version_numbers(path): - version_file = os.path.join(path, "miopen/include/miopen/version.h") + version_file = os.path.join(path, "include/miopen/version.h") if not os.path.exists(version_file): raise ConfigError( 'MIOpen version file "{}" not found'.format(version_file)) @@ -155,8 +155,8 @@ def rocblas_version_numbers(path): possible_version_files = [ - "rocblas/include/rocblas-version.h", # ROCm 3.7 and prior - "rocblas/include/internal/rocblas-version.h", # ROCm 3.8 + "include/rocblas/rocblas-version.h", # ROCm 3.7 and prior + "include/rocblas/internal/rocblas-version.h", # ROCm 3.8 ] version_file = None for f in possible_version_files: @@ -212,7 +212,7 @@ def _find_rocfft_config(rocm_install_path): def rocfft_version_numbers(path): - version_file = os.path.join(path, "rocfft/include/rocfft-version.h") + version_file = os.path.join(path, "include/rocfft/rocfft-version.h") if not os.path.exists(version_file): raise ConfigError( 'rocfft version file "{}" not found'.format(version_file)) @@ -234,7 +234,7 @@ def _find_hipfft_config(rocm_install_path): def hipfft_version_numbers(path): - version_file = os.path.join(path, "hipfft/include/hipfft-version.h") + version_file = os.path.join(path, "include/hipfft/hipfft-version.h") if not os.path.exists(version_file): raise ConfigError( 'hipfft version file "{}" not found'.format(version_file)) @@ -256,7 +256,7 @@ def _find_roctracer_config(rocm_install_path): def roctracer_version_numbers(path): - version_file = os.path.join(path, "roctracer/include/roctracer.h") + version_file = os.path.join(path, "include/roctracer/roctracer.h") if not os.path.exists(version_file): raise ConfigError( 'roctracer version file "{}" not found'.format(version_file)) @@ -279,7 +279,7 @@ def _find_hipsparse_config(rocm_install_path): def hipsparse_version_numbers(path): - version_file = os.path.join(path, "hipsparse/include/hipsparse-version.h") + version_file = os.path.join(path, "include/hipsparse/hipsparse-version.h") if not os.path.exists(version_file): raise ConfigError( 'hipsparse version file "{}" not found'.format(version_file)) @@ -301,8 +301,8 @@ def hipsolver_version_numbers(path): possible_version_files = [ - "hipsolver/include/hipsolver-version.h", # ROCm 5.0 and prior - "hipsolver/include/internal/hipsolver-version.h", # ROCm 5.1 + "include/hipsolver/hipsolver-version.h", # ROCm 5.0 and prior + "include/hipsolver/internal/hipsolver-version.h", # ROCm 5.1 ] version_file = None for f in possible_version_files: @@ -331,7 +331,7 @@ def _find_rocsolver_config(rocm_install_path): def rocsolver_version_numbers(path): - version_file = os.path.join(path, "rocsolver/include/rocsolver-version.h") + version_file = os.path.join(path, "include/rocsolver/rocsolver-version.h") if not os.path.exists(version_file): raise ConfigError( 'rocsolver version file "{}" not found'.format(version_file)) --- a/third_party/gpus/rocm_configure.bzl +++ b/third_party/gpus/rocm_configure.bzl @@ -182,20 +182,7 @@ # Add HIP-Clang headers (realpath relative to compiler binary) rocm_toolkit_path = realpath(repository_ctx, rocm_config.rocm_toolkit_path, bash_bin) - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/8.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/9.0.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/10.0.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/11.0.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/12.0.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/13.0.0/include") - inc_dirs.append(rocm_toolkit_path + "/llvm/lib/clang/14.0.0/include") - - # Support hcc based off clang 10.0.0 (for ROCm 3.3) - inc_dirs.append(rocm_toolkit_path + "/hcc/compiler/lib/clang/10.0.0/include/") - inc_dirs.append(rocm_toolkit_path + "/hcc/lib/clang/10.0.0/include") - - # Add hcc headers - inc_dirs.append(rocm_toolkit_path + "/hcc/include") + inc_dirs.append("@GENTOO_PORTAGE_EPREFIX@/usr/lib/clang/14.0.6/include") return inc_dirs @@ -328,20 +315,20 @@ libs_paths = [ (name, _rocm_lib_paths(repository_ctx, name, path)) for name, path in [ - ("amdhip64", rocm_config.rocm_toolkit_path + "/hip"), - ("rocblas", rocm_config.rocm_toolkit_path + "/rocblas"), - (hipfft_or_rocfft, rocm_config.rocm_toolkit_path + "/" + hipfft_or_rocfft), - ("hiprand", rocm_config.rocm_toolkit_path), - ("MIOpen", rocm_config.rocm_toolkit_path + "/miopen"), - ("rccl", rocm_config.rocm_toolkit_path + "/rccl"), - ("hipsparse", rocm_config.rocm_toolkit_path + "/hipsparse"), - ("roctracer64", rocm_config.rocm_toolkit_path + "/roctracer"), - ("rocsolver", rocm_config.rocm_toolkit_path + "/rocsolver"), + ("amdhip64", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("rocblas", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + (hipfft_or_rocfft, "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("hiprand", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("MIOpen", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("rccl", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("hipsparse", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("roctracer64", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), + ("rocsolver", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"), ] ] if int(rocm_config.rocm_version_number) >= 40500: - libs_paths.append(("hipsolver", _rocm_lib_paths(repository_ctx, "hipsolver", rocm_config.rocm_toolkit_path + "/hipsolver"))) - libs_paths.append(("hipblas", _rocm_lib_paths(repository_ctx, "hipblas", rocm_config.rocm_toolkit_path + "/hipblas"))) + libs_paths.append(("hipsolver", _rocm_lib_paths(repository_ctx, "hipsolver", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"))) + libs_paths.append(("hipblas", _rocm_lib_paths(repository_ctx, "hipblas", "@GENTOO_PORTAGE_EPREFIX@/usr/lib64"))) return _select_rocm_lib_paths(repository_ctx, libs_paths, bash_bin) def _exec_find_rocm_config(repository_ctx, script_path): @@ -556,53 +543,82 @@ copy_rules = [ make_copy_dir_rule( repository_ctx, - name = "rocm-include", - src_dir = rocm_toolkit_path + "/include", - out_dir = "rocm/include", - exceptions = ["gtest", "gmock"], - ), - make_copy_dir_rule( - repository_ctx, name = hipfft_or_rocfft + "-include", - src_dir = rocm_toolkit_path + "/" + hipfft_or_rocfft + "/include", + src_dir = rocm_toolkit_path + "/include/" + hipfft_or_rocfft, out_dir = "rocm/include/" + hipfft_or_rocfft, ), make_copy_dir_rule( repository_ctx, name = "rocblas-include", - src_dir = rocm_toolkit_path + "/rocblas/include", + src_dir = rocm_toolkit_path + "/include/rocblas", out_dir = "rocm/include/rocblas", ), make_copy_dir_rule( repository_ctx, name = "rocblas-hsaco", - src_dir = rocm_toolkit_path + "/rocblas/lib/library", - out_dir = "rocm/lib/rocblas/lib/library", + src_dir = rocm_toolkit_path + "/lib64/rocblas/library", + out_dir = "rocm/lib/rocblas/lib/library", ), make_copy_dir_rule( repository_ctx, name = "miopen-include", - src_dir = rocm_toolkit_path + "/miopen/include", + src_dir = rocm_toolkit_path + "/include/miopen", out_dir = "rocm/include/miopen", ), make_copy_dir_rule( repository_ctx, name = "rccl-include", - src_dir = rocm_toolkit_path + "/rccl/include", + src_dir = rocm_toolkit_path + "/include/rccl", out_dir = "rocm/include/rccl", ), make_copy_dir_rule( repository_ctx, name = "hipsparse-include", - src_dir = rocm_toolkit_path + "/hipsparse/include", + src_dir = rocm_toolkit_path + "/include/hipsparse", out_dir = "rocm/include/hipsparse", ), make_copy_dir_rule( repository_ctx, name = "rocsolver-include", - src_dir = rocm_toolkit_path + "/rocsolver/include", + src_dir = rocm_toolkit_path + "/include/rocsolver", out_dir = "rocm/include/rocsolver", ), + make_copy_dir_rule( + repository_ctx, + name = "rocprim-include", + src_dir = rocm_toolkit_path + "/include/rocprim", + out_dir = "rocm/include/rocprim", + ), + make_copy_dir_rule( + repository_ctx, + name = "hipcub-include", + src_dir = rocm_toolkit_path + "/include/hipcub", + out_dir = "rocm/include/hipcub", + ), + make_copy_dir_rule( + repository_ctx, + name = "roctracer-include", + src_dir = rocm_toolkit_path + "/include/roctracer", + out_dir = "rocm/include/roctracer", + ), + make_copy_dir_rule( + repository_ctx, + name = "hip-include", + src_dir = rocm_toolkit_path + "/include/hip", + out_dir = "rocm/include/hip", + ), + make_copy_dir_rule( + repository_ctx, + name = "rocrand-include", + src_dir = rocm_toolkit_path + "/include/rocrand", + out_dir = "rocm/include/rocrand", + ), + make_copy_dir_rule( + repository_ctx, + name = "hiprand-include", + src_dir = rocm_toolkit_path + "/include/hiprand", + out_dir = "rocm/include/hiprand", + ), ] # Add Hipsolver on ROCm4.5+ @@ -611,7 +627,7 @@ make_copy_dir_rule( repository_ctx, name = "hipsolver-include", - src_dir = rocm_toolkit_path + "/hipsolver/include", + src_dir = rocm_toolkit_path + "/include/hipsolver", out_dir = "rocm/include/hipsolver", ), ) @@ -619,42 +635,11 @@ make_copy_dir_rule( repository_ctx, name = "hipblas-include", - src_dir = rocm_toolkit_path + "/hipblas/include", + src_dir = rocm_toolkit_path + "/include/hipblas", out_dir = "rocm/include/hipblas", ), ) - # explicitly copy (into the local_config_rocm repo) the $ROCM_PATH/hiprand/include and - # $ROCM_PATH/rocrand/include dirs, only once the softlink to them in $ROCM_PATH/include - # dir has been removed. This removal will happen in a near-future ROCm release. - hiprand_include = "" - hiprand_include_softlink = rocm_config.rocm_toolkit_path + "/include/hiprand" - softlink_exists = files_exist(repository_ctx, [hiprand_include_softlink], bash_bin) - if not softlink_exists[0]: - hiprand_include = '":hiprand-include",\n' - copy_rules.append( - make_copy_dir_rule( - repository_ctx, - name = "hiprand-include", - src_dir = rocm_toolkit_path + "/hiprand/include", - out_dir = "rocm/include/hiprand", - ), - ) - - rocrand_include = "" - rocrand_include_softlink = rocm_config.rocm_toolkit_path + "/include/rocrand" - softlink_exists = files_exist(repository_ctx, [rocrand_include_softlink], bash_bin) - if not softlink_exists[0]: - rocrand_include = '":rocrand-include",\n' - copy_rules.append( - make_copy_dir_rule( - repository_ctx, - name = "rocrand-include", - src_dir = rocm_toolkit_path + "/rocrand/include", - out_dir = "rocm/include/rocrand", - ), - ) - rocm_libs = _find_libs(repository_ctx, rocm_config, hipfft_or_rocfft, bash_bin) rocm_lib_srcs = [] rocm_lib_outs = [] @@ -709,14 +694,17 @@ "%{roctracer_lib}": rocm_libs["roctracer64"].file_name, "%{rocsolver_lib}": rocm_libs["rocsolver"].file_name, "%{copy_rules}": "\n".join(copy_rules), - "%{rocm_headers}": ('":rocm-include",\n' + - '":' + hipfft_or_rocfft + '-include",\n' + + "%{rocm_headers}": ('":' + hipfft_or_rocfft + '-include",\n' + '":rocblas-include",\n' + + '":roctracer-include",\n' + + '":hipcub-include",\n' + + '":hip-include",\n' + '":miopen-include",\n' + '":rccl-include",\n' + - hiprand_include + - rocrand_include + '":hipsparse-include",\n' + + '":hiprand-include",\n' + + '":rocrand-include",\n' + + '":rocprim-include",\n' + '":rocsolver-include"'), } if rocm_version_number >= 40500: @@ -761,7 +749,7 @@ rocm_defines["%{host_compiler_path}"] = "clang/bin/crosstool_wrapper_driver_is_not_gcc" rocm_defines["%{cxx_builtin_include_directories}"] = to_list_of_strings( - host_compiler_includes + _rocm_include_path(repository_ctx, rocm_config, bash_bin), + host_compiler_includes + _rocm_include_path(repository_ctx, rocm_config, bash_bin) + ['@GENTOO_PORTAGE_EPREFIX@/usr/include/hip', '@GENTOO_PORTAGE_EPREFIX@/usr/lib/llvm/14/include'], ) verify_build_defines(rocm_defines) @@ -785,11 +773,11 @@ tpl_paths["crosstool:clang/bin/crosstool_wrapper_driver_rocm"], { "%{cpu_compiler}": str(cc), - "%{hipcc_path}": rocm_config.rocm_toolkit_path + "/hip/bin/hipcc", + "%{hipcc_path}": rocm_config.rocm_toolkit_path + "/bin/hipcc", "%{hipcc_env}": _hipcc_env(repository_ctx), - "%{rocr_runtime_path}": rocm_config.rocm_toolkit_path + "/lib", + "%{rocr_runtime_path}": rocm_config.rocm_toolkit_path + "/lib64", "%{rocr_runtime_library}": "hsa-runtime64", - "%{hip_runtime_path}": rocm_config.rocm_toolkit_path + "/hip/lib", + "%{hip_runtime_path}": rocm_config.rocm_toolkit_path + "/lib64", "%{hip_runtime_library}": "amdhip64", "%{crosstool_verbose}": _crosstool_verbose(repository_ctx), "%{gcc_host_compiler_path}": str(cc),