From 1ae2f817bfe15f6301e49256c60ae267223fcaff Mon Sep 17 00:00:00 2001 From: Cheng Date: Thu, 24 Jul 2025 15:39:09 +0900 Subject: [PATCH] Use ccache in CI --- .circleci/config.yml | 24 ++++++++++++++++++++++-- setup.py | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f33e80f0c..fb2d50e0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -212,22 +212,42 @@ jobs: resource_class: gpu.nvidia.small.gen2 steps: - checkout + - restore_cache: + keys: + - mlx-v1-cuda-{{ arch }}- - run: - name: Install Python package + name: Install dependencies command: | sudo apt-get update sudo apt-get install libcudnn9-dev-cuda-12 sudo apt-get install libblas-dev liblapack-dev liblapacke-dev + curl -sL https://github.com/ccache/ccache/releases/download/v4.11.3/ccache-4.11.3-linux-x86_64.tar.xz | tar xJf - + sudo mv ccache-4.11.3-linux-x86_64/ccache /usr/bin/ccache + rm -rf ccache-4.11.3-linux-x86_64 + - run: + name: Install Python package + command: | python3 -m venv env source env/bin/activate CMAKE_ARGS="-DMLX_BUILD_CUDA=ON -DCMAKE_CUDA_COMPILER=`which nvcc`" \ - pip install -e ".[dev]" + pip install -e ".[dev]" -v - run: name: Run Python tests command: | source env/bin/activate LOW_MEMORY=1 DEVICE=cpu python -m unittest discover python/tests -v LOW_MEMORY=1 DEVICE=gpu python -m tests discover python/tests -v + - run: + name: CCache report + command: | + ccache --show-stats + ccache --zero-stats + ccache --max-size 400MB + ccache --cleanup + - save_cache: + key: mlx-v1-cuda-{{ arch }}-{{ epoch }} + paths: + - /home/circleci/.cache/ccache build_release: parameters: diff --git a/setup.py b/setup.py index 8a5517112..87159a0aa 100644 --- a/setup.py +++ b/setup.py @@ -113,6 +113,9 @@ class CMakeBuild(build_ext): if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: build_args += [f"-j{os.cpu_count()}"] + # Avoid cache miss when building from temporary dirs. + os.environ["CCACHE_BASEDIR"] = os.path.abspath(self.build_temp) + subprocess.run( ["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True )