Skip to content

Commit 63aff25

Browse files
authored
jit: defer ninja generation (#1792)
<!-- .github/pull_request_template.md --> ## 📌 Description Defer ninja generation till build, JitSpec generation should not rely on the existence of nvcc, this PR changes the behavior to make sure we can still `generate_jit_spec` on environments without nvcc installation. For example: ```bash python -m flashinfer module-status ``` would fail for no-nvcc environment, and after this PR, it should pass. ## 🔍 Related Issues <!-- Link any related issues here --> ## 🚀 Pull Request Checklist Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete. ### ✅ Pre-commit Checks - [ ] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [ ] I have installed the hooks with `pre-commit install`. - [ ] I have run the hooks manually with `pre-commit run --all-files` and fixed any reported issues. > If you are unsure about how to set up `pre-commit`, see [the pre-commit documentation](https://pre-commit.com/). ## 🧪 Tests - [ ] Tests have been added or updated as needed. - [ ] All tests are passing (`unittest`, etc.). ## Reviewer Notes <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. -->
1 parent 8438ec0 commit 63aff25

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

flashinfer/jit/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,18 @@ def write_ninja(self) -> None:
219219
)
220220
write_if_different(ninja_path, content)
221221

222+
@property
223+
def is_ninja_generated(self) -> bool:
224+
return self.ninja_path.exists()
225+
222226
def build(self, verbose: bool, need_lock: bool = True) -> None:
223227
lock = (
224228
FileLock(self.lock_path, thread_local=False) if need_lock else nullcontext()
225229
)
226230
with lock:
231+
# Write ninja file if it doesn't exist (deferred case)
232+
if not self.is_ninja_generated:
233+
self.write_ninja()
227234
run_ninja(jit_env.FLASHINFER_JIT_DIR, self.ninja_path, verbose)
228235

229236
def load(self, so_path: Path, class_name: str = None):
@@ -304,7 +311,6 @@ def gen_jit_spec(
304311
),
305312
needs_device_linking=needs_device_linking,
306313
)
307-
spec.write_ninja()
308314

309315
# Register the spec in the global registry
310316
jit_spec_registry.register(spec)
@@ -330,6 +336,9 @@ def build_jit_specs(
330336
if skip_prebuilt and spec.aot_path.exists():
331337
continue
332338
lines.append(f"subninja {spec.ninja_path}")
339+
if not spec.is_ninja_generated:
340+
with FileLock(spec.lock_path, thread_local=False):
341+
spec.write_ninja()
333342
if not lines:
334343
return
335344

0 commit comments

Comments
 (0)