One pain point in maintaining a large code base is that even the smallest code change can lead to long recompilation times when significant dependencies exist throughout an application.
If only there were a way for the compiler to access a log of previous builds that maps already pre-processed hashed source files from prior compilations to expected output object files. Using those hashed files and the build map as input, the compiler would then be able to bypass most of the syntax and dependency analysis work usually needed, moving directly to low-level optimization and object generation.
This is exactly how Ccache works. It is effectively a compiler cache for C and C++. If you ever were in a situation of running
$ make clean; make
several times on the same day, you know the benefit this can bring. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation is being done again.
The Intel® oneAPI DPC++/C++ Compiler 2025.1 now comes bundled with Ccache support.
Ccache has been carefully written to always produce the same compiler output you would get without the cache. The speed is the only way you should be able to tell that you are using ccache.
When you compile a source file, the C preprocessor is invoked, and the resulting text is hashed. The cache is then queried with this hash, at which point one of two things can happen:
- A cache miss. The C/C++ compiler is invoked, and the resulting object file is stored in the cache. The compiler is slow, compared to a cache file read, so we want to avoid this case as much as possible.
- A cache hit. The pre-compiled object file is immediately available in the cache, and there's no need to invoke a compiler.
After building a project from scratch for the first time, you can clean your build directory and rebuild everything without invoking the compiler (assuming your cache is large enough).
Using Ccache with the Intel oneAPI DPC++/C++ Compiler its benefits are also available with SYCL code! |
Usage
Ccache can be used with Intel® Compilers on Linux*. It can also be used when compiling SYCL* code with the Intel® oneAPI DPC++/C++ Compiler C++ frontend driver icpx.
Examples
For direct compilations, prefix your compilation command with ccache:
ccache icx -c test.c
ccache icpx -fsycl -c sycl_test.cpp
When using CMake, set CMAKE_CXX_COMPILER_LAUNCHER to ccache:
cmake -DCMAKE_CXX_COMPILER=icpx -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
The size and location of the cache maintained by Ccache can be adjusted via the LLVM_CCACHE_MAXSIZE and LLVM_CCACHE_DIR options, which are passed to the CCACHE_MAXSIZE and CCACHE_DIR environment variables, respectively.
Download the Compiler Now
Take advantage of Ccache and many other features, whether using C, C++, or C++ with SYCL code now.
Give it a go.
Accelerate your software development productivity with the Intel oneAPI DPC++/C++ Compiler, available stand-alone or as part of the Intel® oneAPI Toolkits. It is also available in source code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.