Skip to content

Commit c95d45f

Browse files
cyx-6junrushao
authored andcommitted
[Unity] Fix ccache env for nn.SourceModule (#16257)
This PR refactors the compilation of `nn.SourceModule` to enable ccache by using the relative path, instead of using absolute path. Also it adds the ccache env to not hash the directory.
1 parent 1bf4437 commit c95d45f

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

python/tvm/relax/frontend/nn/extern.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,24 @@ def compile(self, output_path: Path) -> None:
371371
"""Compiles the source code in a provided directory and returns the compiled artifact."""
372372
with tempfile.TemporaryDirectory() as temp_dir_str:
373373
temp_dir = Path(temp_dir_str)
374-
source_path = temp_dir / f"main{self.source_suffix}"
375-
object_path = temp_dir / f"main{self.output_suffix}"
374+
source_filename = f"main{self.source_suffix}"
375+
object_filename = f"main{self.output_suffix}"
376+
source_path = temp_dir / source_filename
377+
object_path = temp_dir / object_filename
376378
with source_path.open("w", encoding="utf-8") as file:
377379
file.write(self.source_code)
378380
_cc.create_shared(
379-
output=str(object_path),
380-
objects=[str(source_path)],
381+
output=object_filename,
382+
objects=[source_filename],
381383
options=self.compile_options,
382384
cc=self.compiler,
383385
cwd=temp_dir,
384-
ccache_env={"CCACHE_COMPILERCHECK": "content"} if shutil.which("ccache") else None,
386+
ccache_env={
387+
"CCACHE_COMPILERCHECK": "content",
388+
"CCACHE_NOHASHDIR": "1",
389+
}
390+
if shutil.which("ccache")
391+
else None,
385392
)
386393
shutil.move(str(object_path), str(output_path))
387394

0 commit comments

Comments
 (0)