diff --git a/third_party/tsl/third_party/gpus/sycl/BUILD.tpl b/third_party/tsl/third_party/gpus/sycl/BUILD.tpl index 1eb4b07538fe3..cfa4b7cd36202 100644 --- a/third_party/tsl/third_party/gpus/sycl/BUILD.tpl +++ b/third_party/tsl/third_party/gpus/sycl/BUILD.tpl @@ -16,6 +16,7 @@ cc_library( ".", "sycl/include", "sycl/include/sycl", + "level-zero/include", ], visibility = ["//visibility:public"], ) @@ -32,7 +33,7 @@ cc_library( ".", "sycl/include", ], - linkopts = ["-lze_loader"], + deps = [":level-zero"], linkstatic = 1, visibility = ["//visibility:public"], ) @@ -60,4 +61,20 @@ cc_library( visibility = ["//visibility:public"], ) -%{copy_rules} \ No newline at end of file +cc_library( + name = "level-zero", + srcs = [ + %{level_zero_libs} + ], + data = [ + %{level_zero_libs} + ], + includes = [ + ".", + "level-zero/include", + ], + linkstatic = 1, + visibility = ["//visibility:public"], +) + +%{copy_rules} diff --git a/third_party/tsl/third_party/gpus/sycl_configure.bzl b/third_party/tsl/third_party/gpus/sycl_configure.bzl index 2f3c7de39682a..d0c0e939597c5 100644 --- a/third_party/tsl/third_party/gpus/sycl_configure.bzl +++ b/third_party/tsl/third_party/gpus/sycl_configure.bzl @@ -40,6 +40,16 @@ def _sycl_header_path(repository_ctx, sycl_config, bash_bin): auto_configure_fail("Cannot find sycl headers in {}".format(include_dir)) return sycl_header_path +def _get_default_l0_path(): + return "/usr" + +def _get_l0_path(repository_ctx, bash_bin): + l0_path = get_host_environ(repository_ctx, "TF_L0_PATH", _get_default_l0_path()) + lib_path = "/lib/x86_64-linux-gnu/libze_loader.so" + if not files_exist(repository_ctx, [l0_path + lib_path], bash_bin)[0]: + auto_configure_fail("Cannot find level zero library in %s" % (l0_path)) + return l0_path + def _sycl_include_path(repository_ctx, sycl_config, bash_bin): """Generates the cxx_builtin_include_directory entries for sycl inc dirs. @@ -57,6 +67,7 @@ def _sycl_include_path(repository_ctx, sycl_config, bash_bin): inc_dirs.append(_mkl_path(sycl_config) + "/include") inc_dirs.append(_sycl_header_path(repository_ctx, sycl_config, bash_bin) + "/include") inc_dirs.append(_sycl_header_path(repository_ctx, sycl_config, bash_bin) + "/include/sycl") + inc_dirs.append(_get_l0_path(repository_ctx, bash_bin) + "/include") return inc_dirs @@ -203,6 +214,7 @@ def _find_libs(repository_ctx, sycl_config, bash_bin): libs_paths.append(("mkl_sycl_rng", _sycl_lib_paths(repository_ctx, "mkl_sycl_rng", mkl_path))) libs_paths.append(("mkl_sycl_stats", _sycl_lib_paths(repository_ctx, "mkl_sycl_stats", mkl_path))) libs_paths.append(("mkl_sycl_data_fitting", _sycl_lib_paths(repository_ctx, "mkl_sycl_data_fitting", mkl_path))) + libs_paths.append(("ze_loader", [repository_ctx.path("%s/lib/x86_64-linux-gnu/%s" % (_get_l0_path(repository_ctx, bash_bin), _lib_name("ze_loader", version = "", static = False)))])) return _select_sycl_lib_paths(repository_ctx, libs_paths, bash_bin) def find_sycl_config(repository_ctx): @@ -359,6 +371,7 @@ def _create_dummy_repository(repository_ctx): "%{core_sycl_libs}": "", "%{copy_rules}": "", "%{sycl_headers}": "", + "%{level_zero_libs}": "", }, ) @@ -407,6 +420,12 @@ def _create_local_sycl_repository(repository_ctx): src_dir = _mkl_path(sycl_config) + "/include", out_dir = "sycl/include", )) + copy_rules.append(make_copy_dir_rule( + repository_ctx, + name = "level-zero-include", + src_dir = _get_l0_path(repository_ctx, bash_bin) + "/include", + out_dir = "level-zero/include", + )) sycl_libs = _find_libs(repository_ctx, sycl_config, bash_bin) sycl_lib_srcs = [] @@ -450,6 +469,7 @@ def _create_local_sycl_repository(repository_ctx): "sycl/lib/" + sycl_libs["sycl"].file_name, "sycl/lib/" + sycl_libs["OpenCL"].file_name, ) + level_zero_libs = '"{}",\n'.format("sycl/lib/libze_loader.so") repository_dict = { "%{mkl_intel_ilp64_lib}": sycl_libs["mkl_intel_ilp64"].file_name, "%{mkl_sequential_lib}": sycl_libs["mkl_sequential"].file_name, @@ -457,7 +477,8 @@ def _create_local_sycl_repository(repository_ctx): "%{mkl_sycl_libs}": mkl_sycl_libs, "%{core_sycl_libs}": core_sycl_libs, "%{copy_rules}": "\n".join(copy_rules), - "%{sycl_headers}": ('":mkl-include",\n":sycl-include",\n'), + "%{sycl_headers}": ('":mkl-include",\n":sycl-include",\n":level-zero-include",\n'), + "%{level_zero_libs}": level_zero_libs, } repository_ctx.template( "sycl/BUILD", diff --git a/tools/intel_build/build.sh b/tools/intel_build/build.sh new file mode 100644 index 0000000000000..0909bda0e56b0 --- /dev/null +++ b/tools/intel_build/build.sh @@ -0,0 +1,7 @@ + +workspace=$1 +cd $workspace/jax +export SYCL_TOOLKIT_PATH=$workspace/oneapi/compiler/2024.0/ +export TF_L0_PATH=$workspace/level_zero/usr +bazel clean --expunge +python build/build.py --enable_sycl --bazel_options=--override_repository=xla=$workspace/xla diff --git a/tools/intel_build/clean.sh b/tools/intel_build/clean.sh new file mode 100644 index 0000000000000..cc2b1df1e2e63 --- /dev/null +++ b/tools/intel_build/clean.sh @@ -0,0 +1,5 @@ + +workspace=$1 +SCRIPT_PATH="`dirname \"$0\"`" +bash $SCRIPT_PATH/uninstall_oneapi.sh $workspace +rm -rf $workspace diff --git a/tools/intel_build/install_l0.sh b/tools/intel_build/install_l0.sh new file mode 100644 index 0000000000000..dfd3f9dfa71e7 --- /dev/null +++ b/tools/intel_build/install_l0.sh @@ -0,0 +1,9 @@ + +workspace=$1 +cd $workspace +mkdir -p level_zero +cd level_zero +wget -c https://repositories.intel.com/gpu/ubuntu/pool/unified/l/level-zero-loader/level-zero-dev_1.14.0-744~22.04_amd64.deb +wget -c https://repositories.intel.com/gpu/ubuntu/pool/unified/l/level-zero-loader/level-zero_1.14.0-744~22.04_amd64.deb +dpkg-deb -x level-zero-dev_1.14.0-744~22.04_amd64.deb $workspace/level_zero +dpkg-deb -x level-zero_1.14.0-744~22.04_amd64.deb $workspace/level_zero diff --git a/tools/intel_build/install_oneapi.sh b/tools/intel_build/install_oneapi.sh new file mode 100644 index 0000000000000..0ad9eaa1891b9 --- /dev/null +++ b/tools/intel_build/install_oneapi.sh @@ -0,0 +1,10 @@ + +workspace=$1 +echo "Install Intel OneAPI in $workspace/oneapi" +cd $workspace +mkdir -p oneapi +if ! [ -f $workspace/l_BaseKit_p_2024.0.1.46.sh ]; then + echo "Download oneAPI package" + wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/163da6e4-56eb-4948-aba3-debcec61c064/l_BaseKit_p_2024.0.1.46.sh +fi +bash l_BaseKit_p_2024.0.1.46.sh -a -s --eula accept --install-dir $workspace/oneapi --log-dir $workspace/oneapi/log --download-cache $workspace/oneapi/cache --components=intel.oneapi.lin.dpcpp-cpp-compiler:intel.oneapi.lin.mkl.devel diff --git a/tools/intel_build/setup.sh b/tools/intel_build/setup.sh new file mode 100644 index 0000000000000..dfdd6b0f46c91 --- /dev/null +++ b/tools/intel_build/setup.sh @@ -0,0 +1,16 @@ + +workspace=$1 +SCRIPT_PATH="`dirname \"$0\"`" +bash $SCRIPT_PATH/install_oneapi.sh $workspace +bash $SCRIPT_PATH/install_l0.sh $workspace +cd $workspace +git clone -b yang/runtime https://github.com/Intel-tensorflow/xla xla +cd $workspace/xla +git apply $SCRIPT_PATH/xla.patch +cd $workspace +git clone https://github.com/google/jax jax +git clone https://github.com/intel/intel-extension-for-openxla ixla +cd $workspace/jax +git checkout ceb198582b62b9e6f6bdf20ab74839b0cf1db16e +git apply $workspace/ixla/test/jax.patch +bash $SCRIPT_PATH/build.sh $workspace diff --git a/tools/intel_build/uninstall_oneapi.sh b/tools/intel_build/uninstall_oneapi.sh new file mode 100644 index 0000000000000..d549e118f1450 --- /dev/null +++ b/tools/intel_build/uninstall_oneapi.sh @@ -0,0 +1,10 @@ + +workspace=$1 +echo "Uninstall Intel OneAPI in $workspace/oneapi" +cd $workspace +if ! [ -f $workspace/l_BaseKit_p_2024.0.1.46.sh ]; then + echo "Download oneAPI package for uninstallation." + wget https://registrationcenter-download.intel.com/akdlm/IRC_NAS/163da6e4-56eb-4948-aba3-debcec61c064/l_BaseKit_p_2024.0.1.46.sh +fi + +bash l_BaseKit_p_2024.0.1.46.sh -a -s --eula accept --action remove --install-dir $workspace/oneapi --log-dir $workspace/oneapi/log --download-cache $workspace/oneapi/cache --components=intel.oneapi.lin.dpcpp-cpp-compiler:intel.oneapi.lin.mkl.devel