Skip to content

tilecpp: create the cubin cache directory on first compile, not at import - #226

Merged
hannahli-nv merged 2 commits into
NVIDIA:mainfrom
0z5a:tilecpp-lazy-cache-dir
Nov 12, 2026
Merged

hannahli-nv merged 2 commits into
NVIDIA:mainfrom
0z5a:tilecpp-lazy-cache-dir

Conversation

@0z5a

@0z5a 0z5a commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

tilegym/ops/tilecpp/utils/_cuda_utils.py runs mkdir on the cubin cache directory (TILECPP_CACHE_DIR, $XDG_CACHE_HOME/tilecpp or ~/.cache/tilecpp) when the module is imported. tilegym imports this module while it probes the tilecpp backend, so an unusable cache location breaks import tilegym itself, including for users who never touch the tilecpp backend:

  • read-only home directory (common in containers and on CI runners): PermissionError
  • TILECPP_CACHE_DIR or HOME pointing below a regular file: NotADirectoryError / FileExistsError

This change keeps resolving the path at import time but creates the directory only right before the compiler writes the wrapper .cu and the cubin.

Tests (tests/test_tilecpp_compiler.py):

  • test_cache_dir_lookup_does_not_create_it: resolving a cache path under a regular file no longer raises and creates nothing. Fails on main with NotADirectoryError.
  • test_compile_creates_missing_output_dir: the first compile creates the missing output directory. Fails on main with FileNotFoundError.

On main: 2 failed. With this change: 7 passed. The 7 Linux-only /proc tests in this file were skipped in my run.

I emailed my signed CLA (individual) to TileGym@nvidia.com on 2026-11-03.

CI Configuration

config:
  build: true
  # valid options are "ops", "benchmark", and "sanity"
  test: ["ops", "benchmark"]

Checklist

  • Code formatted and imports sorted via repo specifications (./format.sh)
  • Documentation updated (if needed)
  • CI configuration reviewed

…port

_cuda_utils resolves CACHE_DIR at module import and immediately ran
mkdir on it. tilegym imports this module while probing the tilecpp
backend, so an unwritable or unusable cache location (read-only home,
HOME pointing at a file, TILECPP_CACHE_DIR under a regular file) made
`import tilegym` fail with PermissionError / NotADirectoryError even for
users who never touch the tilecpp backend.

Keep resolving the path at import, but create the directory right before
the compiler writes the wrapper source and cubin.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@GordonWuCn GordonWuCn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@hannahli-nv

Copy link
Copy Markdown
Collaborator

/ok to test 618a3fa

@hannahli-nv
hannahli-nv merged commit 759fb1a into NVIDIA:main Nov 12, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants