Commit ad465a72 authored by Lei Wang's avatar Lei Wang Committed by LeiWang1999
Browse files

[Refactor] Remove debug message in pass legalize_safe_memory_access (#381)

* Update legalize_safe_memory_access.cc

* Add cache path handling and file locking in Cython adapter

- Introduced a new cache path based on the code hash for the Cython JIT adapter, enhancing cache management.
- Added a lock file mechanism to ensure safe access during cache operations, improving concurrency handling.
- These changes aim to optimize the compilation process and prevent race conditions during library loading.

* lint fix
parent aa85ddc7
...@@ -170,15 +170,11 @@ private: ...@@ -170,15 +170,11 @@ private:
if (IsGlobalBuffer(store->buffer)) { if (IsGlobalBuffer(store->buffer)) {
Stmt store_with_conditions = store; Stmt store_with_conditions = store;
for (auto cond : conditions) { for (auto cond : conditions) {
LOG(INFO) << "condition: " << cond;
LOG(INFO) << "store: " << store;
store_with_conditions = IfThenElse(cond, store_with_conditions); store_with_conditions = IfThenElse(cond, store_with_conditions);
} }
return store_with_conditions; return store_with_conditions;
} else if (isSharedBuffer(store->buffer)) { } else if (isSharedBuffer(store->buffer)) {
PrimExpr value = store->value; PrimExpr value = store->value;
LOG(INFO) << "value: " << value;
LOG(INFO) << "conditions: " << conditions;
for (auto cond : conditions) { for (auto cond : conditions) {
ICHECK(cond.dtype() == DataType::Bool(1)) ICHECK(cond.dtype() == DataType::Bool(1))
<< "condition is not a boolean: " << cond; << "condition is not a boolean: " << cond;
......
...@@ -90,6 +90,7 @@ with open(cython_wrapper_path, "r") as f: ...@@ -90,6 +90,7 @@ with open(cython_wrapper_path, "r") as f:
library_path = cache_dir / "cython_wrapper.so" library_path = cache_dir / "cython_wrapper.so"
md5_path = cache_dir / "md5.txt" md5_path = cache_dir / "md5.txt"
code_hash = hashlib.sha256(cython_wrapper_code.encode()).hexdigest() code_hash = hashlib.sha256(cython_wrapper_code.encode()).hexdigest()
cache_path = cache_dir / f"{code_hash}.so"
# Check if cached version exists and is valid # Check if cached version exists and is valid
need_compile = True need_compile = True
...@@ -128,6 +129,7 @@ with open(cython_wrapper_path, "r") as f: ...@@ -128,6 +129,7 @@ with open(cython_wrapper_path, "r") as f:
temp_path.unlink() temp_path.unlink()
raise Exception(f"Failed to compile cython jit adapter: {e}") from e raise Exception(f"Failed to compile cython jit adapter: {e}") from e
finally: finally:
lock_file = cache_path.with_suffix('.lock')
if lock_file.exists(): if lock_file.exists():
lock_file.unlink() lock_file.unlink()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment