You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ju...@apache.org on 2023/12/18 21:01:02 UTC

(tvm) 03/03: [Unity] Fix ccache env for `nn.SourceModule` (#16257)

This is an automated email from the ASF dual-hosted git repository.

junrushao pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 45eeb8c83857b1ff01bcc3930fe7d83e94626c10
Author: Yaxing Cai <ca...@gmail.com>
AuthorDate: Mon Dec 18 12:44:45 2023 -0800

    [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.
---
 python/tvm/relax/frontend/nn/extern.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/python/tvm/relax/frontend/nn/extern.py b/python/tvm/relax/frontend/nn/extern.py
index 2d20809d23..8c0491eaec 100644
--- a/python/tvm/relax/frontend/nn/extern.py
+++ b/python/tvm/relax/frontend/nn/extern.py
@@ -371,17 +371,24 @@ class SourceModule(ExternModule):  # pylint: disable=too-few-public-methods
         """Compiles the source code in a provided directory and returns the compiled artifact."""
         with tempfile.TemporaryDirectory() as temp_dir_str:
             temp_dir = Path(temp_dir_str)
-            source_path = temp_dir / f"main{self.source_suffix}"
-            object_path = temp_dir / f"main{self.output_suffix}"
+            source_filename = f"main{self.source_suffix}"
+            object_filename = f"main{self.output_suffix}"
+            source_path = temp_dir / source_filename
+            object_path = temp_dir / object_filename
             with source_path.open("w", encoding="utf-8") as file:
                 file.write(self.source_code)
             _cc.create_shared(
-                output=str(object_path),
-                objects=[str(source_path)],
+                output=object_filename,
+                objects=[source_filename],
                 options=self.compile_options,
                 cc=self.compiler,
                 cwd=temp_dir,
-                ccache_env={"CCACHE_COMPILERCHECK": "content"} if shutil.which("ccache") else None,
+                ccache_env={
+                    "CCACHE_COMPILERCHECK": "content",
+                    "CCACHE_NOHASHDIR": "1",
+                }
+                if shutil.which("ccache")
+                else None,
             )
             shutil.move(str(object_path), str(output_path))