Skip to content

Commit

Permalink
Add sycl runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ShengYang1 committed Feb 18, 2024
1 parent d6cfa24 commit 8b322f8
Show file tree
Hide file tree
Showing 70 changed files with 4,936 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ build:rocm --define=using_rocm_hipcc=true
build:rocm --define=tensorflow_mkldnn_contraction_kernel=0
build:rocm --repo_env TF_NEED_ROCM=1

build:sycl --crosstool_top=@local_config_sycl//crosstool:toolchain
build:sycl --define=using_sycl=true
build:sycl --define=tensorflow_mkldnn_contraction_kernel=0
build:sycl --repo_env TF_NEED_SYCL=1

# Options to disable default on features
build:noaws --define=no_aws_support=true
build:nogcp --define=no_gcp_support=true
Expand Down
71 changes: 71 additions & 0 deletions third_party/tsl/third_party/gpus/crosstool/BUILD.sycl.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This file is expanded from a template sycl_configure.bzl
# Update sycl_configure.bzl#verify_build_defines when adding new variables.

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

licenses(["restricted"])

package(default_visibility = ["//visibility:public"])

toolchain(
name = "toolchain-linux-x86_64",
exec_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
target_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
toolchain = ":cc-compiler-local",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

cc_toolchain_suite(
name = "toolchain",
toolchains = {
"local|compiler": ":cc-compiler-local",
"k8": ":cc-compiler-local",
},
)

cc_toolchain(
name = "cc-compiler-local",
all_files = ":crosstool_wrapper_driver_is_not_gcc",
compiler_files = ":crosstool_wrapper_driver_is_not_gcc",
ar_files = ":crosstool_wrapper_driver_is_not_gcc",
as_files = ":crosstool_wrapper_driver_is_not_gcc",
dwp_files = ":empty",
linker_files = ":crosstool_wrapper_driver_is_not_gcc",
objcopy_files = ":empty",
strip_files = ":empty",
# To support linker flags that need to go to the start of command line
# we need the toolchain to support parameter files. Parameter files are
# last on the command line and contain all shared libraries to link, so all
# regular options will be left of them.
supports_param_files = 1,
toolchain_identifier = "local_linux",
toolchain_config = ":cc-compiler-local-config",
)

cc_toolchain_config(
name = "cc-compiler-local-config",
cpu = "local",
builtin_include_directories = [%{cxx_builtin_include_directories}],
extra_no_canonical_prefixes_flags = [%{extra_no_canonical_prefixes_flags}],
host_compiler_path = "%{host_compiler_path}",
host_compiler_prefix = "%{host_compiler_prefix}",
host_unfiltered_compile_flags = [%{unfiltered_compile_flags}],
linker_bin_path = "%{linker_bin_path}",
compiler = "unknown",
)

filegroup(
name = "empty",
srcs = [],
)

filegroup(
name = "crosstool_wrapper_driver_is_not_gcc",
srcs = ["clang/bin/crosstool_wrapper_driver_is_not_gcc"]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
"""Crosstool wrapper for compiling SYCL program
SYNOPSIS:
crosstool_wrapper_driver_sycl [options passed in by cc_library()
or cc_binary() rule]
DESCRIPTION:
This script is expected to be called by the cc_library() or cc_binary() bazel
rules. When the option "sycl_compile" is present in the list of arguments passed
to this script, it invokes the sycl compiler. When "sycl_compile" is not
present, this wrapper invokes gcc with the input arguments as is.
"""

from __future__ import print_function
from argparse import ArgumentParser
import os
import subprocess
import sys
import shlex

CPU_COMPILER = ('%{cpu_compiler}')

def system(cmd):
"""Invokes cmd with os.system()"""

ret = os.system(cmd)
if os.WIFEXITED(ret):
return os.WEXITSTATUS(ret)
else:
return -os.WTERMSIG(ret)

def call_compiler(argv):
parser = ArgumentParser()
parser.add_argument('-c', nargs=1, action='append')
parser.add_argument('-o', nargs=1, action='append')
args, leftover = parser.parse_known_args(argv)

flags = leftover

common_flags = []
common_flags.append("-fno-finite-math-only")
common_flags.append("-fno-fast-math")
common_flags.append("-fexceptions")

in_files, out_files = [], []
if args.c:
in_files.append('-c')
in_files.extend(args.c[0])
if args.o:
out_files.append('-o')
out_files.extend(args.o[0])
flags += (common_flags + in_files + out_files)
print("cmd: ", " ".join([CPU_COMPILER] + flags))
return subprocess.call([CPU_COMPILER] + flags)

def main():
parser = ArgumentParser()
parser = ArgumentParser(fromfile_prefix_chars='@')
parser.add_argument('-sycl_compile', action='store_true')
args, leftover = parser.parse_known_args(sys.argv[1:])

return call_compiler(leftover)

if __name__ == '__main__':
sys.exit(main())
Loading

0 comments on commit 8b322f8

Please sign in to comment.