Skip to content

Commit afdb4eb

Browse files
ddunlcopybara-github
authored andcommitted
Remake configure.py to be XLA specific
Also, move it to `build_tools/configure/configure.py` and add tests PiperOrigin-RevId: 603158260
1 parent 0b0bc50 commit afdb4eb

18 files changed

+915
-1229
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ build:elinux_armhf --copt -mfp16-format=ieee
577577

578578
# Load rc file written by ./configure.
579579
try-import %workspace%/.tf_configure.bazelrc
580+
try-import %workspace%/xla_configure.bazelrc
580581

581582
# Load rc file with user-specific options.
582583
try-import %workspace%/.bazelrc.user

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bazel-testlogs
1010

1111
# Ignore files produced by `configure`
1212
.tf_configure.bazelrc
13+
xla_configure.bazelrc
1314
tools/python_bin_path.sh
1415

1516
# Emacs autosaves

build_tools/configure/BUILD

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2024 The OpenXLA Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ============================================================================
15+
16+
load("//xla:pytype.default.bzl", "pytype_strict_library")
17+
18+
# Placeholder: load py_test
19+
load("@local_config_cuda//cuda:build_defs.bzl", "cuda_library")
20+
21+
package(
22+
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
23+
licenses = ["notice"],
24+
)
25+
26+
pytype_strict_library(
27+
name = "configure",
28+
srcs = ["configure.py"],
29+
)
30+
31+
py_test(
32+
name = "configure_test",
33+
srcs = ["configure_test.py"],
34+
data = [
35+
"testdata/clang.bazelrc",
36+
"testdata/cuda_clang.bazelrc",
37+
"testdata/gcc.bazelrc",
38+
"testdata/nvcc_clang.bazelrc",
39+
"testdata/nvcc_gcc.bazelrc",
40+
],
41+
deps = [
42+
":configure",
43+
"//build_tools:test_utils",
44+
"@absl_py//absl/testing:absltest",
45+
],
46+
)
47+
48+
# Below targets are just for checking if the host/CUDA compiler are configured
49+
# as expected.
50+
cc_library(
51+
name = "assert_clang",
52+
srcs = ["assert_clang.cc"],
53+
tags = ["manual"],
54+
)
55+
56+
cc_library(
57+
name = "assert_gcc",
58+
srcs = ["assert_gcc.cc"],
59+
tags = ["manual"],
60+
)
61+
62+
cuda_library(
63+
name = "assert_cuda_clang",
64+
srcs = ["assert_cuda_clang.cu.cc"],
65+
tags = [
66+
"gpu",
67+
"manual",
68+
],
69+
deps = ["@local_config_cuda//cuda:cuda_headers"],
70+
)
71+
72+
cuda_library(
73+
name = "assert_nvcc",
74+
srcs = ["assert_nvcc.cu.cc"],
75+
tags = [
76+
"gpu",
77+
"manual",
78+
],
79+
# Notably, this builds fine in OSS without this dependency. Apparently,
80+
# NVCC can give targets access to CUDA headers without letting Bazel know,
81+
# while CUDA clang cannot.
82+
deps = ["@local_config_cuda//cuda:cuda_headers"],
83+
)

build_tools/configure/assert_clang.cc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright 2024 The OpenXLA Authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
#ifndef __clang__
17+
#error "__clang__ not defined!"
18+
#endif // #ifdef __clang__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright 2024 The OpenXLA Authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
#if !defined(__clang__) || !defined(__CUDA__)
17+
#error "__clang__ or __CUDA__ not defined!"
18+
#endif // #if !defined(__clang__) || !defined(__CUDA__)

build_tools/configure/assert_gcc.cc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright 2024 The OpenXLA Authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
// Notably, clang will define `__GNUC__`, so need to make sure __clang__ is not
17+
// defined to detect GCC (or, most correctly, some compiler that supports GNU
18+
// extensions that is not clang).
19+
#if !defined(__GNUC__) || defined(__clang__)
20+
#error "__GNUC__ is not defined independently of __clang__!"
21+
#endif // #if !defined(__GNUC__) || defined(__clang__)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright 2024 The OpenXLA Authors.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
#ifndef __NVCC__
16+
#error "__NVCC__ not defined!"
17+
#endif // #ifdef __NVCC__

0 commit comments

Comments
 (0)