Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions projects/hipblaslt/tensilelite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,36 @@ invoke build-client \
Tensile/bin/Tensile Tensile/Tests/common/exception/<test>.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 <build_dir> --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 <build_dir> --target _rocisa
```

Expand Down
8 changes: 8 additions & 0 deletions projects/hipblaslt/tensilelite/rocisa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
28 changes: 27 additions & 1 deletion projects/hipblaslt/tensilelite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@
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)
Expand Down Expand Up @@ -50,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(
Expand Down
4 changes: 2 additions & 2 deletions shared/stinkytofu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
2 changes: 1 addition & 1 deletion shared/stinkytofu/src/conversion/rocisa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Loading