diff --git a/projects/hipblaslt/tensilelite/README.md b/projects/hipblaslt/tensilelite/README.md index a72ea6397fbe..8b6505326bb3 100644 --- a/projects/hipblaslt/tensilelite/README.md +++ b/projects/hipblaslt/tensilelite/README.md @@ -70,35 +70,36 @@ invoke build-client \ Tensile/bin/Tensile Tensile/Tests/common/exception/.yaml tensile-out ``` -### Rebuilding rocisa after C++ changes +### Rebuilding after C++ changes -The rebuild command depends on how rocisa was installed: +`invoke build-client` builds the tensilelite-client executable only — it does +**not** rebuild the rocisa Python module (`_rocisa.so`). If you edit rocisa or +stinkytofu C++ sources you must re-run `invoke rocisa` for those changes to +take effect in Python: -**If installed via `invoke rocisa`** (scikit-build-core build dir is `rocisa/build`): +| What you changed | Command to rebuild | +|---|---| +| rocisa C++ sources | `invoke rocisa` | +| stinkytofu C++ sources | `invoke rocisa` | +| tensilelite-client C++ sources | `invoke build-client` | +| rocisa `pyproject.toml` or `CMakeLists.txt` | `invoke rocisa` | -```bash -invoke rocisa # re-runs pip install -e; scikit-build-core does an incremental rebuild -# or directly: -cmake --build rocisa/build --target _rocisa -``` - -**If installed via `invoke build-client`** (cmake build dir is `build_tmp`): +Example workflow after editing stinkytofu or rocisa code: ```bash -cmake --build build_tmp --target _rocisa -``` - -**If using a custom cmake build directory:** +# 1. Rebuild the rocisa Python module (includes stinkytofu) +invoke rocisa -```bash -cmake --build --target _rocisa +# 2. Rebuild the C++ client (if needed) +invoke build-client ``` -If you forget to rebuild, importing rocisa will raise an `ImportError` listing the stale files: +If you forget to rebuild, importing rocisa will raise an `ImportError` listing +the stale source files: ``` ImportError: rocisa C++ sources are newer than the built _rocisa.so — bindings are stale. - Modified: .../rocisa/src/main.cpp + Modified: .../shared/stinkytofu/src/ir/asm/Function.cpp Rebuild: cmake --build --target _rocisa ``` diff --git a/projects/hipblaslt/tensilelite/rocisa/CMakeLists.txt b/projects/hipblaslt/tensilelite/rocisa/CMakeLists.txt index 1d6d826261ff..6da5c74e8f22 100644 --- a/projects/hipblaslt/tensilelite/rocisa/CMakeLists.txt +++ b/projects/hipblaslt/tensilelite/rocisa/CMakeLists.txt @@ -48,6 +48,9 @@ if(HIPBLASLT_BUNDLE_PYTHON_DEPS OR ROCISA_STANDALONE) # HIP is required to build _rocisa (via hip::host). Set the search prefix # so find_package works both in developer environments and in the temporary # build sandbox created by scikit-build-core / uv. + if(ROCM_PATH) + list(APPEND CMAKE_PREFIX_PATH "${ROCM_PATH}") + endif() list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm) find_package(hip REQUIRED) @@ -146,6 +149,11 @@ if(HIPBLASLT_BUNDLE_PYTHON_DEPS OR ROCISA_STANDALONE) ) # _build_info.py is intentionally NOT in install() rules so it is absent # from wheels and pre-built packages, acting as the source-build sentinel. + # For editable/dev installs, pass -DROCISA_INCLUDE_BUILD_INFO=ON to include it. + option(ROCISA_INCLUDE_BUILD_INFO "Install _build_info.py for staleness detection" OFF) + if(ROCISA_INCLUDE_BUILD_INFO) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rocisa/_build_info.py" DESTINATION rocisa) + endif() if(ROCISA_STANDALONE) # Install rules for scikit-build-core: place _rocisa.so, libstinkytofu.so, diff --git a/projects/hipblaslt/tensilelite/rocisa/rocisa/_build_info.py.in b/projects/hipblaslt/tensilelite/rocisa/rocisa/_build_info.py.in index bd45a136de29..4759ae833b6b 100644 --- a/projects/hipblaslt/tensilelite/rocisa/rocisa/_build_info.py.in +++ b/projects/hipblaslt/tensilelite/rocisa/rocisa/_build_info.py.in @@ -4,5 +4,5 @@ # Auto-generated by CMake at configure time. Not installed into wheels. # Presence of this file indicates a source build (vs a pre-built package). SOURCE_ROOT = "@CMAKE_CURRENT_SOURCE_DIR@/rocisa" -STINKYTOFU_SOURCE_ROOT = "@STINKYTOFU_DIR@" +STINKYTOFU_SOURCE_ROOT = "@STINKYTOFU_ROOT_DIR@" BUILD_DIR = "@CMAKE_CURRENT_BINARY_DIR@" diff --git a/projects/hipblaslt/tensilelite/tasks.py b/projects/hipblaslt/tensilelite/tasks.py index 85665910b153..df5b5a1a8a6a 100644 --- a/projects/hipblaslt/tensilelite/tasks.py +++ b/projects/hipblaslt/tensilelite/tasks.py @@ -12,6 +12,28 @@ def _cmake_bool(value): return "ON" if value else "OFF" +def _detect_rocm(): + """Detect ROCm installation path. + + Priority: ROCM_PATH env > rocm-sdk path --root > /opt/rocm. + """ + env_path = os.environ.get("ROCM_PATH") + if env_path: + return env_path + + import shutil + if shutil.which("rocm-sdk"): + try: + result = subprocess.check_output( + ["rocm-sdk", "path", "--root"], stderr=subprocess.DEVNULL + ).decode().strip() + if result: + return result + except subprocess.CalledProcessError: + pass + + return "/opt/rocm" + def detect_gpu_arch(): try: result = subprocess.run(["rocm_agent_enumerator", "-v"], capture_output=True, text=True, timeout=5, check=True) @@ -51,7 +73,10 @@ def rocisa(c, rocisa_dir=None): import pathlib src = pathlib.Path(rocisa_dir).resolve() if rocisa_dir else pathlib.Path(__file__).parent / "rocisa" - c.run(f"pip install -e {shlex.quote(str(src))}") + rocm = _detect_rocm() + cmake_args = f"-DROCM_PATH={rocm} -DROCISA_INCLUDE_BUILD_INFO=ON" + env = dict(os.environ, CMAKE_ARGS=cmake_args) + c.run(f"pip install -e {shlex.quote(str(src))}", env=env) @task( diff --git a/shared/stinkytofu/CMakeLists.txt b/shared/stinkytofu/CMakeLists.txt index ad225ee30b81..0c1526277b48 100644 --- a/shared/stinkytofu/CMakeLists.txt +++ b/shared/stinkytofu/CMakeLists.txt @@ -54,8 +54,8 @@ if(WIN32) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") endif() -# set variable of the top level source directory to STINKYTOFU_TOP_DIR -set(STINKYTOFU_TOP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(STINKYTOFU_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(STINKYTOFU_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) ##===----------------------------------------------------------------------===## # Architectures diff --git a/shared/stinkytofu/python_module/stinkytofu/_build_info.py.in b/shared/stinkytofu/python_module/stinkytofu/_build_info.py.in index 1743c32918bb..86dffa6e55d8 100644 --- a/shared/stinkytofu/python_module/stinkytofu/_build_info.py.in +++ b/shared/stinkytofu/python_module/stinkytofu/_build_info.py.in @@ -3,5 +3,5 @@ # # Auto-generated by CMake at configure time. Not installed into wheels. # Presence of this file indicates a source build (vs a pre-built package). -SOURCE_ROOT = "@STINKYTOFU_TOP_DIR@" +SOURCE_ROOT = "@STINKYTOFU_ROOT_DIR@" BUILD_DIR = "@CMAKE_BINARY_DIR@" diff --git a/shared/stinkytofu/src/conversion/rocisa/CMakeLists.txt b/shared/stinkytofu/src/conversion/rocisa/CMakeLists.txt index 4f460f617c59..a8ba7c3de441 100644 --- a/shared/stinkytofu/src/conversion/rocisa/CMakeLists.txt +++ b/shared/stinkytofu/src/conversion/rocisa/CMakeLists.txt @@ -5,7 +5,7 @@ target_sources(_rocisa PRIVATE AllHwMappings.cpp ToStinkyTofuUtils.cpp) target_include_directories(_rocisa PRIVATE - "${STINKYTOFU_TOP_DIR}/include" + "${STINKYTOFU_ROOT_DIR}/include" "${CMAKE_BINARY_DIR}/tensilelite/rocisa/stinkytofu" )