Skip to content

Commit

Permalink
Remake configure.py to be XLA specific
Browse files Browse the repository at this point in the history
Also, move it to `build_tools/configure/configure.py` and add tests

PiperOrigin-RevId: 603158260
  • Loading branch information
ddunl authored and tensorflower-gardener committed Jan 31, 2024
1 parent 84a2d75 commit 277eed5
Show file tree
Hide file tree
Showing 20 changed files with 921 additions and 1,229 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ build:elinux_armhf --copt -mfp16-format=ieee

# Load rc file written by ./configure.
try-import %workspace%/.tf_configure.bazelrc
try-import %workspace%/xla_configure.bazelrc

# Load rc file with user-specific options.
try-import %workspace%/.bazelrc.user
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
node_modules
/.bazelrc.user
/.tf_configure.bazelrc
/xla_configure.bazelrc
/bazel-*
/bazel_pip
/tools/python_bin_path.sh
Expand Down
1 change: 1 addition & 0 deletions third_party/xla/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ build:elinux_armhf --copt -mfp16-format=ieee

# Load rc file written by ./configure.
try-import %workspace%/.tf_configure.bazelrc
try-import %workspace%/xla_configure.bazelrc

# Load rc file with user-specific options.
try-import %workspace%/.bazelrc.user
Expand Down
1 change: 1 addition & 0 deletions third_party/xla/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bazel-testlogs

# Ignore files produced by `configure`
.tf_configure.bazelrc
xla_configure.bazelrc
tools/python_bin_path.sh

# Emacs autosaves
Expand Down
88 changes: 88 additions & 0 deletions third_party/xla/build_tools/configure/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2024 The OpenXLA Authors.
#
# 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("//xla:pytype.default.bzl", "pytype_strict_library")

# Placeholder: load py_test
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library")

package(
default_visibility = ["//visibility:public"],
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
licenses = ["notice"],
)

pytype_strict_library(
name = "configure",
srcs = ["configure.py"],
)

py_test(
name = "configure_test",
srcs = ["configure_test.py"],
data = [
"testdata/clang.bazelrc",
"testdata/cuda_clang.bazelrc",
"testdata/gcc.bazelrc",
"testdata/nvcc_clang.bazelrc",
"testdata/nvcc_gcc.bazelrc",
],
deps = [
":configure",
"//build_tools:test_utils",
"@absl_py//absl/testing:absltest",
],
)

# Below targets are just for checking if the host/CUDA compiler are configured
# as expected.
cc_library(
name = "assert_clang",
srcs = ["assert_clang.cc"],
tags = ["manual"],
visibility = ["//visibility:public"],
)

cc_library(
name = "assert_gcc",
srcs = ["assert_gcc.cc"],
tags = ["manual"],
visibility = ["//visibility:public"],
)

cuda_library(
name = "assert_cuda_clang",
srcs = ["assert_cuda_clang.cu.cc"],
tags = [
"gpu",
"manual",
],
visibility = ["//visibility:public"],
deps = ["@local_config_cuda//cuda:cuda_headers"],
)

cuda_library(
name = "assert_nvcc",
srcs = ["assert_nvcc.cu.cc"],
tags = [
"gpu",
"manual",
],
visibility = ["//visibility:public"],
# Notably, this builds fine in OSS without this dependency. Apparently,
# NVCC can give targets access to CUDA headers without letting Bazel know,
# while CUDA clang cannot.
deps = ["@local_config_cuda//cuda:cuda_headers"],
)
18 changes: 18 additions & 0 deletions third_party/xla/build_tools/configure/assert_clang.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright 2024 The OpenXLA Authors.
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.
==============================================================================*/

#ifndef __clang__
#error "__clang__ not defined!"
#endif // #ifdef __clang__
18 changes: 18 additions & 0 deletions third_party/xla/build_tools/configure/assert_cuda_clang.cu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright 2024 The OpenXLA Authors.
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.
==============================================================================*/

#if !defined(__clang__) || !defined(__CUDA__)
#error "__clang__ or __CUDA__ not defined!"
#endif // #if !defined(__clang__) || !defined(__CUDA__)
21 changes: 21 additions & 0 deletions third_party/xla/build_tools/configure/assert_gcc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2024 The OpenXLA Authors.
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.
==============================================================================*/

// Notably, clang will define `__GNUC__`, so need to make sure __clang__ is not
// defined to detect GCC (or, most correctly, some compiler that supports GNU
// extensions that is not clang).
#if !defined(__GNUC__) || defined(__clang__)
#error "__GNUC__ is not defined independently of __clang__!"
#endif // #if !defined(__GNUC__) || defined(__clang__)
17 changes: 17 additions & 0 deletions third_party/xla/build_tools/configure/assert_nvcc.cu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2024 The OpenXLA Authors.
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.
==============================================================================*/
#ifndef __NVCC__
#error "__NVCC__ not defined!"
#endif // #ifdef __NVCC__
Loading

0 comments on commit 277eed5

Please sign in to comment.