From c5e9e9be061ccbbf9a275a69298844132e68900d Mon Sep 17 00:00:00 2001 From: ethanglaser Date: Mon, 8 Jul 2024 16:05:37 -0700 Subject: [PATCH] dpc bazel test fixes --- WORKSPACE | 5 +++ dev/bazel/deps/micromkldpc.tpl.BUILD | 1 + dev/bazel/deps/opencl.bzl | 46 ++++++++++++++++++++++++++++ dev/bazel/deps/opencl.tpl.BUILD | 8 +++++ 4 files changed, 60 insertions(+) create mode 100644 dev/bazel/deps/opencl.bzl create mode 100644 dev/bazel/deps/opencl.tpl.BUILD diff --git a/WORKSPACE b/WORKSPACE index e1030e909a9..7020d6b5bae 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,6 +17,11 @@ declare_onedal_extra_toolchain( name = "onedal_extra_toolchain", ) +load("@onedal//dev/bazel/deps:opencl.bzl", "opencl_repo") +opencl_repo( + name = "opencl", +) + load("@onedal//dev/bazel/deps:micromkl.bzl", "micromkl_repo", "micromkl_dpc_repo") micromkl_repo( name = "micromkl", diff --git a/dev/bazel/deps/micromkldpc.tpl.BUILD b/dev/bazel/deps/micromkldpc.tpl.BUILD index 7c485effcf1..844e1150264 100644 --- a/dev/bazel/deps/micromkldpc.tpl.BUILD +++ b/dev/bazel/deps/micromkldpc.tpl.BUILD @@ -13,5 +13,6 @@ cc_library( ], deps = [ ":headers", + "@opencl//:opencl_binary", ], ) diff --git a/dev/bazel/deps/opencl.bzl b/dev/bazel/deps/opencl.bzl new file mode 100644 index 00000000000..05e95fb556b --- /dev/null +++ b/dev/bazel/deps/opencl.bzl @@ -0,0 +1,46 @@ +#=============================================================================== +# Copyright 2020 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#=============================================================================== + +load("@onedal//dev/bazel:repos.bzl", "repos") +load("@onedal//dev/bazel:utils.bzl", "paths") + +def _get_dpcpp_compiler_root(repo_ctx): + dpcpp_path = repo_ctx.which("icpx") + return dpcpp_path and str(dpcpp_path.dirname.dirname.realpath) + +def _opencl_repo_impl(repo_ctx): + dpcpp_root = _get_dpcpp_compiler_root(repo_ctx) + if dpcpp_root: + lib_dir = paths.join(dpcpp_root, "lib") + libs = [ + "libOpenCL.so", + "libOpenCL.so.1", + "libOpenCL.so.1.2", + ] + repos.create_symlinks(repo_ctx, lib_dir, libs) + repo_ctx.template( + "BUILD", + Label("@onedal//dev/bazel/deps:opencl.tpl.BUILD"), + ) + +opencl_repo = repository_rule( + implementation = _opencl_repo_impl, + environ = [ + "PATH", + ], + local = True, + configure = True, +) diff --git a/dev/bazel/deps/opencl.tpl.BUILD b/dev/bazel/deps/opencl.tpl.BUILD new file mode 100644 index 00000000000..0d37c4b1307 --- /dev/null +++ b/dev/bazel/deps/opencl.tpl.BUILD @@ -0,0 +1,8 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "opencl_binary", + srcs = [ + "libOpenCL.so.1.2", + ], +)