Skip to content

add L0 build #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: yang/runtime
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions third_party/tsl/third_party/gpus/sycl/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cc_library(
".",
"sycl/include",
"sycl/include/sycl",
"level-zero/include",
],
visibility = ["//visibility:public"],
)
Expand All @@ -32,7 +33,7 @@ cc_library(
".",
"sycl/include",
],
linkopts = ["-lze_loader"],
deps = [":level-zero"],
linkstatic = 1,
visibility = ["//visibility:public"],
)
Expand Down Expand Up @@ -60,4 +61,20 @@ cc_library(
visibility = ["//visibility:public"],
)

%{copy_rules}
cc_library(
name = "level-zero",
srcs = [
%{level_zero_libs}
],
data = [
%{level_zero_libs}
],
includes = [
".",
"level-zero/include",
],
linkstatic = 1,
visibility = ["//visibility:public"],
)

%{copy_rules}
23 changes: 22 additions & 1 deletion third_party/tsl/third_party/gpus/sycl_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -359,6 +371,7 @@ def _create_dummy_repository(repository_ctx):
"%{core_sycl_libs}": "",
"%{copy_rules}": "",
"%{sycl_headers}": "",
"%{level_zero_libs}": "",
},
)

Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -450,14 +469,16 @@ 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,
"%{mkl_core_lib}": sycl_libs["mkl_core"].file_name,
"%{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",
Expand Down
7 changes: 7 additions & 0 deletions tools/intel_build/build.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tools/intel_build/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

workspace=$1
SCRIPT_PATH="`dirname \"$0\"`"
bash $SCRIPT_PATH/uninstall_oneapi.sh $workspace
rm -rf $workspace
9 changes: 9 additions & 0 deletions tools/intel_build/install_l0.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tools/intel_build/install_oneapi.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions tools/intel_build/setup.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tools/intel_build/uninstall_oneapi.sh
Original file line number Diff line number Diff line change
@@ -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