-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force well ordered changing of
TT_METAL_HOME
(#1582)
This change robustly fixes potential out of order changes to `TT_METAL_HOME` dependent on import orders. Since `__init__.py` here will be executed before any of the import below it in the module tree, the changes to `TT_METAL_HOME` happen as early as possible w.r.t. this module
- Loading branch information
Showing
3 changed files
with
49 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
""" | ||
Simple library tweaks module used to move `TT_METAL_HOME` to point to the | ||
mirrored TTMetal tree within the `ttrt` wheel. It is important that | ||
`set_tt_metal_home()` is the _FIRST_ bit of code run in this `ttrt` module. | ||
Thus, this file should only be included in `ttrt/__init__.py` and only run | ||
there. This is a temporary fix, and will need to be cleaned up once TTMetal | ||
drops `TT_METAL_HOME` functionality | ||
""" | ||
import importlib.util | ||
import os | ||
|
||
|
||
def get_ttrt_metal_home_path() -> str: | ||
"""Finds the root of the mirrored TTMetal tree within the `ttrt` wheel""" | ||
package_name = "ttrt" | ||
spec = importlib.util.find_spec(package_name) | ||
package_path = os.path.dirname(spec.origin) | ||
tt_metal_home = f"{package_path}/runtime" | ||
return tt_metal_home | ||
|
||
|
||
def set_tt_metal_home(): | ||
"""Sets the environment variable `TT_METAL_HOME` to point into the root | ||
mirrored TTMetal tree within the `ttrt` wheel. | ||
""" | ||
os.environ["TT_METAL_HOME"] = get_ttrt_metal_home_path() | ||
|
||
new_linker_path = f"{get_ttrt_metal_home_path()}/tests" | ||
current_ld_library_path = os.environ.get("LD_LIBRARY_PATH", "") | ||
if current_ld_library_path: | ||
updated_ld_library_path = f"{new_linker_path}:{current_ld_library_path}" | ||
else: | ||
updated_ld_library_path = new_linker_path | ||
os.environ["LD_LIBRARY_PATH"] = updated_ld_library_path |