Skip to content

Commit f5d53d3

Browse files
nouiznluehr
authored andcommitted
[TF1] port ccache
1 parent 623b18d commit f5d53d3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

configure.py

+2
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,8 @@ def main():
14471447
write_action_env_to_bazelrc('LD_LIBRARY_PATH',
14481448
environ_cp.get('LD_LIBRARY_PATH'))
14491449

1450+
write_action_env_to_bazelrc("TF_USE_CCACHE",
1451+
environ_cp.get('TF_USE_CCACHE', '0'))
14501452
environ_cp['TF_NEED_CUDA'] = str(
14511453
int(get_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)))
14521454
if (environ_cp.get('TF_NEED_CUDA') == '1' and

third_party/gpus/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc.tpl

+12-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ GCC_HOST_COMPILER_PATH = ('%{gcc_host_compiler_path}')
5252
NVCC_PATH = '%{nvcc_path}'
5353
PREFIX_DIR = os.path.dirname(GCC_HOST_COMPILER_PATH)
5454
NVCC_VERSION = '%{cuda_version}'
55+
CCACHE = '%{ccache}'
5556

5657
def Log(s):
5758
print('gpus/crosstool: {0}'.format(s))
@@ -217,10 +218,14 @@ def InvokeNvcc(argv, log=False):
217218
nvccopts += m_options
218219
nvccopts += warning_options
219220

221+
ccache = ''
222+
if CCACHE:
223+
ccache = CCACHE + ' '
224+
220225
if depfiles:
221226
# Generate the dependency file
222227
depfile = depfiles[0]
223-
cmd = (NVCC_PATH + ' ' + nvccopts +
228+
cmd = (ccache + NVCC_PATH + ' ' + nvccopts +
224229
' --compiler-options "' + host_compiler_options + '"' +
225230
' --compiler-bindir=' + GCC_HOST_COMPILER_PATH +
226231
' -I .' +
@@ -230,7 +235,7 @@ def InvokeNvcc(argv, log=False):
230235
if exit_status != 0:
231236
return exit_status
232237

233-
cmd = (NVCC_PATH + ' ' + nvccopts +
238+
cmd = (ccache + NVCC_PATH + ' ' + nvccopts +
234239
' --compiler-options "' + host_compiler_options + ' -fPIC"' +
235240
' --compiler-bindir=' + GCC_HOST_COMPILER_PATH +
236241
' -I .' +
@@ -262,8 +267,12 @@ def main():
262267
# this).
263268
cpu_compiler_flags = [flag for flag in sys.argv[1:]
264269
if not flag.startswith(('--cuda_log'))]
270+
if CCACHE:
271+
cmd = [CCACHE, CPU_COMPILER] + cpu_compiler_flags
272+
else:
273+
cmd = [CPU_COMPILER] + cpu_compiler_flags
265274

266-
return subprocess.call([CPU_COMPILER] + cpu_compiler_flags)
275+
return subprocess.call(cmd)
267276

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

third_party/gpus/cuda_configure.bzl

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* `TF_CUDA_COMPUTE_CAPABILITIES`: The CUDA compute capabilities. Default is
2424
`3.5,5.2`.
2525
* `PYTHON_BIN_PATH`: The python binary path
26+
* `TF_USE_CCACHE`: Prepend ccache to compilation commands.
2627
"""
2728

2829
load("//third_party/clang_toolchain:download_clang.bzl", "download_clang")
@@ -49,6 +50,7 @@ _TF_CUDA_COMPUTE_CAPABILITIES = "TF_CUDA_COMPUTE_CAPABILITIES"
4950
_TF_CUDA_CONFIG_REPO = "TF_CUDA_CONFIG_REPO"
5051
_TF_DOWNLOAD_CLANG = "TF_DOWNLOAD_CLANG"
5152
_PYTHON_BIN_PATH = "PYTHON_BIN_PATH"
53+
_TF_USE_CCACHE = "TF_USE_CCACHE"
5254

5355
_DEFAULT_CUDA_COMPUTE_CAPABILITIES = ["3.5", "5.2"]
5456

@@ -1289,6 +1291,9 @@ def _create_local_cuda_repository(repository_ctx):
12891291
cuda_defines["%{linker_files}"] = ":crosstool_wrapper_driver_is_not_gcc"
12901292
cuda_defines["%{win_linker_files}"] = ":windows_msvc_wrapper_files"
12911293

1294+
ccache = ""
1295+
if repository_ctx.os.environ.get(_TF_USE_CCACHE) == "1":
1296+
ccache = "ccache"
12921297
wrapper_defines = {
12931298
"%{cpu_compiler}": str(cc),
12941299
"%{cuda_version}": cuda_config.cuda_version,
@@ -1298,6 +1303,7 @@ def _create_local_cuda_repository(repository_ctx):
12981303
["\"%s\"" % c for c in cuda_config.compute_capabilities],
12991304
),
13001305
"%{nvcc_tmp_dir}": _get_nvcc_tmp_dir_for_windows(repository_ctx),
1306+
"%{ccache}": ccache
13011307
}
13021308
_tpl(
13031309
repository_ctx,
@@ -1409,6 +1415,7 @@ cuda_configure = repository_rule(
14091415
"TMP",
14101416
"TMPDIR",
14111417
"TF_CUDA_PATHS",
1418+
_TF_USE_CCACHE,
14121419
],
14131420
)
14141421

0 commit comments

Comments
 (0)