Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions .github/ci_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ platforms:
BASE_IMAGE: nvcr.io/nvidia/pytorch:24.10-py3
SKIP_APT: "1"
PIP_INDEX_URL: https://pypi.tuna.tsinghua.edu.cn/simple
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_NVIDIA=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand Down Expand Up @@ -51,7 +51,7 @@ platforms:
- /lib/firmware:/lib/firmware
- /usr/src:/usr/src
- /lib/modules:/lib/modules
setup: python -m pip install packaging exceptiongroup typing-extensions pygments pybind11 libclang && python -m pip install . --no-build-isolation --no-deps --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: python -m pip install scikit-build-core packaging exceptiongroup typing-extensions pygments pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_ILUVATAR=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix -DCMAKE_CUDA_ARCHITECTURES=OFF -DCMAKE_CUDA_COMPILER=/usr/local/corex-4.3.0.20250624/bin/clang++ -DCUDAToolkit_ROOT=/usr/local/corex-4.3.0.20250624 && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && python -m pip install . --no-build-isolation --no-deps --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand Down Expand Up @@ -81,7 +81,7 @@ platforms:
- "--privileged"
- "--ulimit=memlock=-1"
- "--ulimit=stack=67108864"
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_METAX=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand Down Expand Up @@ -109,7 +109,7 @@ platforms:
PIP_INDEX_URL: https://pypi.org/simple
docker_args:
- "--privileged"
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_MOORE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand All @@ -136,7 +136,7 @@ platforms:
PIP_INDEX_URL: https://pypi.org/simple
docker_args:
- "--privileged"
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_CAMBRICON=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand Down Expand Up @@ -172,7 +172,7 @@ platforms:
- "--group-add=video"
volumes:
- /opt/hyhal:/opt/hyhal:ro
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_HYGON=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
gpu:
type: unittest
Expand Down Expand Up @@ -209,7 +209,7 @@ platforms:
- /usr/local/bin/npu-smi:/usr/local/bin/npu-smi:ro
env:
ASCEND_HOME_PATH: /usr/local/Ascend/ascend-toolkit/latest
setup: pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
setup: pip install scikit-build-core pybind11 libclang pyyaml && rm -rf /tmp/infinirt-src /tmp/infinirt-build /tmp/infinirt-prefix && git clone --depth 1 ${INFINI_RT_GIT_URL:-https://gh-proxy.com/https://github.com/InfiniTensor/InfiniRT.git} /tmp/infinirt-src && cmake -S /tmp/infinirt-src -B /tmp/infinirt-build -DWITH_CPU=ON -DWITH_ASCEND=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/infinirt-prefix && cmake --build /tmp/infinirt-build -j$(nproc) && cmake --install /tmp/infinirt-build && pip install .[dev] --no-build-isolation --config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON --config-settings=cmake.define.INFINI_RT_ROOT=/tmp/infinirt-prefix
jobs:
npu:
type: unittest
Expand Down
86 changes: 84 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ if(WITH_TORCH)
message(STATUS "Found PyTorch: ${TORCH_INCLUDE_DIRS}")
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

# Only one CUDA-like GPU backend can be enabled at a time.
set(_gpu_backend_count 0)
foreach(_gpu_backend WITH_NVIDIA WITH_ILUVATAR WITH_HYGON WITH_METAX WITH_MOORE WITH_ASCEND)
Expand Down Expand Up @@ -502,6 +500,90 @@ if(WITH_HYGON AND NOT EXISTS "${DTK_ROOT}/llvm/lib/LLVMgold.so")
set(PYBIND11_ENABLE_EXTRAS OFF)
endif()

set(INFINI_RT_ROOT "$ENV{INFINI_RT_ROOT}" CACHE PATH "Installed InfiniRT prefix")
set(INFINI_RT_SOURCE_DIR "" CACHE PATH "InfiniRT source directory for development builds")
set(INFINI_RT_INCLUDE_DIRS "" CACHE STRING "InfiniRT include directories")
set(INFINI_RT_LIBRARY "" CACHE FILEPATH "InfiniRT library")

function(_infiniops_configure_infinirt)
if(TARGET infinirt)
get_target_property(_infinirt_include_dirs infinirt INTERFACE_INCLUDE_DIRECTORIES)
if(_infinirt_include_dirs)
set(INFINI_RT_INCLUDE_DIRS "${_infinirt_include_dirs}" CACHE STRING "InfiniRT include directories" FORCE)
endif()
return()
endif()

if(INFINI_RT_SOURCE_DIR)
if(NOT EXISTS "${INFINI_RT_SOURCE_DIR}/CMakeLists.txt")
message(FATAL_ERROR
"InfiniRT source tree not found at `${INFINI_RT_SOURCE_DIR}`. "
"Unset `INFINI_RT_SOURCE_DIR` to use an installed InfiniRT package.")
endif()

add_subdirectory("${INFINI_RT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}/InfiniRT")
set(INFINI_RT_INCLUDE_DIRS
"${INFINI_RT_SOURCE_DIR}/include;${INFINI_RT_SOURCE_DIR}/generated/include"
CACHE STRING "InfiniRT include directories" FORCE)
return()
endif()

set(_infinirt_include_hints ${INFINI_RT_INCLUDE_DIRS})
if(INFINI_RT_ROOT)
list(APPEND _infinirt_include_hints "${INFINI_RT_ROOT}/include")
endif()

find_path(_INFINI_RT_INCLUDE_DIR
NAMES infini/rt.h
HINTS ${_infinirt_include_hints}
PATH_SUFFIXES include
)

if(INFINI_RT_LIBRARY)
set(_INFINI_RT_LIBRARY "${INFINI_RT_LIBRARY}")
else()
set(_infinirt_library_hints "")
if(INFINI_RT_ROOT)
list(APPEND _infinirt_library_hints
"${INFINI_RT_ROOT}/lib"
"${INFINI_RT_ROOT}/lib64")
endif()
find_library(_INFINI_RT_LIBRARY
NAMES infinirt
HINTS ${_infinirt_library_hints}
)
endif()

if(NOT _INFINI_RT_INCLUDE_DIR OR NOT _INFINI_RT_LIBRARY)
message(FATAL_ERROR
"InfiniRT installed headers/library were not found. "
"Set `INFINI_RT_ROOT` to an installed InfiniRT prefix, or set "
"`INFINI_RT_INCLUDE_DIRS` and `INFINI_RT_LIBRARY` explicitly. "
"For development builds from source, set `INFINI_RT_SOURCE_DIR`.")
endif()

set(_infinirt_resolved_include_dirs "")
foreach(_infinirt_include_dir IN LISTS _infinirt_include_hints)
if(_infinirt_include_dir AND EXISTS "${_infinirt_include_dir}")
list(APPEND _infinirt_resolved_include_dirs "${_infinirt_include_dir}")
endif()
endforeach()
list(APPEND _infinirt_resolved_include_dirs "${_INFINI_RT_INCLUDE_DIR}")
list(REMOVE_DUPLICATES _infinirt_resolved_include_dirs)

add_library(infinirt SHARED IMPORTED GLOBAL)
set_target_properties(infinirt PROPERTIES
IMPORTED_LOCATION "${_INFINI_RT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${_infinirt_resolved_include_dirs}"
)

set(INFINI_RT_INCLUDE_DIRS "${_infinirt_resolved_include_dirs}" CACHE STRING "InfiniRT include directories" FORCE)
set(INFINI_RT_LIBRARY "${_INFINI_RT_LIBRARY}" CACHE FILEPATH "InfiniRT library" FORCE)
message(STATUS "Using installed InfiniRT: ${_INFINI_RT_LIBRARY}")
endfunction()

_infiniops_configure_infinirt()

add_subdirectory(src)

if(NOT GENERATE_PYTHON_BINDINGS)
Expand Down
21 changes: 16 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ Branch names use the format `<type>/xxx-yyyy-zzzz`, where `<type>` matches the P
Using Nvidia as an example:

```bash
pip install .[dev] -C cmake.define.WITH_CPU=ON -C cmake.define.WITH_NVIDIA=ON
pip install .[dev] \
-C cmake.define.INFINI_RT_ROOT=/path/to/infinirt-prefix \
-C cmake.define.WITH_CPU=ON \
-C cmake.define.WITH_NVIDIA=ON
```

Auto-detection is supported for some platforms, so you can also simply run:
`/path/to/infinirt-prefix` is the InfiniRT install prefix, typically the value
used for InfiniRT's `CMAKE_INSTALL_PREFIX`. It should contain
`include/infini/rt.h` and `lib/libinfinirt.so`.

Auto-detection is supported for some platforms, so you can also let InfiniOps
detect the device backends while still pointing it at the installed InfiniRT:

```bash
pip install .[dev]
pip install .[dev] -C cmake.define.INFINI_RT_ROOT=/path/to/infinirt-prefix
```

> `[dev]` installs optional development dependencies (e.g. `pytest`) that are not needed for production but required for development and testing. After the first install, subsequent installs only need `pip install .`.
Expand All @@ -94,6 +102,7 @@ For routine development and pull requests, start with a smoke build plus the smo

```bash
python -m pip install .[dev] --no-build-isolation --no-deps \
--config-settings=cmake.define.INFINI_RT_ROOT=/path/to/infinirt-prefix \
--config-settings=cmake.define.INFINI_OPS_SMOKE_BUILD=ON
python -m pytest tests -m smoke -q
```
Expand Down Expand Up @@ -251,5 +260,7 @@ using T = TypeMapType<Device::Type::kCpu, ListGet<0>(list_tag)>;
2. **Segmentation fault during tests**: Run `pytest -n 1`.
3. **`Unknown CMake command "pybind11_add_module"`**: Install pybind11 with `pip install pybind11[global]`. See the [pybind11 installation guide](https://pybind11.readthedocs.io/en/stable/installing.html).
4. **Auto-detection (`AUTO_DETECT_DEVICES`) fails**: Some machines may not expose devices in expected paths (e.g. `/dev/nvidia*`). Use explicit CMake defines instead (e.g. `-C cmake.define.WITH_NVIDIA=ON`).
5. **`bash: pytest: command not found`**: Use `python -m pytest`.
6. **`CUBLAS_STATUS_INVALID_VALUE` in `cublasSgemmStridedBatched`**: PyTorch version issue. Downgrade to `torch<=2.9.1`.
5. **InfiniRT headers or library are not found**: Set `INFINI_RT_ROOT` to the InfiniRT install prefix, or set `INFINI_RT_INCLUDE_DIRS` and `INFINI_RT_LIBRARY` explicitly.
6. **`ImportError: libinfinirt.so: cannot open shared object file`**: Reinstall InfiniOps from a build that was configured with the InfiniRT install prefix so the Python wheel can bundle the runtime library.
7. **`bash: pytest: command not found`**: Use `python -m pytest`.
8. **`CUBLAS_STATUS_INVALID_VALUE` in `cublasSgemmStridedBatched`**: PyTorch version issue. Downgrade to `torch<=2.9.1`.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@ InfiniOps is a high-performance, cross-platform operator library supporting mult
- CMake 3.18+
- Python 3.10+
- Hardware-specific SDKs (e.g. CUDA Toolkit, MUSA Toolkit)
- Installed InfiniRT headers and library

## Installation

Install with pip (recommended):
Install InfiniRT first, then build InfiniOps with the InfiniRT install prefix:

```bash
pip install .
pip install . -C cmake.define.INFINI_RT_ROOT=/path/to/infinirt-prefix
```

This auto-detects available platforms on supported backends. To specify platforms explicitly:
`/path/to/infinirt-prefix` is the directory passed to InfiniRT as
`CMAKE_INSTALL_PREFIX`; it should contain `include/infini/rt.h` and
`lib/libinfinirt.so`.

InfiniOps auto-detects available platforms on supported backends. To specify
platforms explicitly:

```bash
pip install . -C cmake.define.WITH_CPU=ON -C cmake.define.WITH_NVIDIA=ON
pip install . \
-C cmake.define.INFINI_RT_ROOT=/path/to/infinirt-prefix \
-C cmake.define.WITH_CPU=ON \
-C cmake.define.WITH_NVIDIA=ON
```

The Python wheel installs the required InfiniRT shared library next to the
InfiniOps extension so `import infini.ops` can load its runtime dependency.

### CMake Options

| Option | Description | Default |
Expand All @@ -36,6 +48,10 @@ pip install . -C cmake.define.WITH_CPU=ON -C cmake.define.WITH_NVIDIA=ON
| `-DWITH_CAMBRICON=[ON\|OFF]` | Compile the Cambricon implementation | OFF |
| `-DWITH_ASCEND=[ON\|OFF]` | Compile the Ascend implementation | OFF |
| `-DAUTO_DETECT_DEVICES=[ON\|OFF]` | Auto-detect available platforms | ON |
| `-DINFINI_RT_ROOT=<path>` | InfiniRT install prefix containing `include/` and `lib/` | `$INFINI_RT_ROOT` |
| `-DINFINI_RT_INCLUDE_DIRS=<paths>` | Explicit InfiniRT include directories | empty |
| `-DINFINI_RT_LIBRARY=<path>` | Explicit path to `libinfinirt.so` | empty |
| `-DINFINI_RT_SOURCE_DIR=<path>` | InfiniRT source tree for development builds | empty |

If no accelerator options are provided and auto-detection finds nothing, `WITH_CPU` is enabled by default.

Expand Down
4 changes: 3 additions & 1 deletion examples/runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define INFINI_OPS_EXAMPLES_RUNTIME_API_H_

#include "device.h"
#include "runtime.h"

#ifdef WITH_NVIDIA
#include "native/cuda/nvidia/ops/gemm/cublas.h"
Expand All @@ -23,8 +24,9 @@
#include "native/ascend/ops/gemm/kernel.h"
#include "native/ascend/runtime_.h"
#elif WITH_CPU
#include <infini/rt/cpu/runtime_.h>

#include "native/cpu/ops/gemm/gemm.h"
#include "native/cpu/runtime_.h"
#else
#error "One `WITH_*` backend must be enabled for the examples."
#endif
Expand Down
Loading
Loading