Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7d58db3
build: add PyYAML build dependency
voltjia May 9, 2026
15da799
refactor(swiglu): move `Sigmoid` helper to `detail::`
voltjia May 9, 2026
a5e9ce2
feat(operator): graceful handling of unknown device types
voltjia May 9, 2026
c0c35ff
feat: add YAML-driven torch op codegen
voltjia May 9, 2026
60a2696
build: integrate torch op codegen into CMake
voltjia May 9, 2026
023c414
feat(scripts): generate pybind bindings for generated torch ops
voltjia May 9, 2026
df18dc1
fix(scripts): order pybind overloads from specific to permissive
voltjia May 9, 2026
b868821
test: add data-driven coverage for generated torch ops
voltjia May 9, 2026
527b3e4
feat(scripts): drop overload-name suffix from generated class names
voltjia May 9, 2026
786b90d
feat(scripts): store visible non-tensor params as base members
voltjia May 9, 2026
d918f21
feat(scripts): expose default-valued non-optional params
voltjia May 9, 2026
156e83f
fix(scripts): preserve `std::vector<int64_t>` params in pybind genera…
voltjia May 9, 2026
ea64161
fix(scripts): gate generated-base scan on `--with-torch`
voltjia May 9, 2026
832e048
fix(scripts): rename ATen `self` parameter to `input`
voltjia May 9, 2026
78424f7
perf(scripts): gate torch op instantiations by active device
voltjia May 9, 2026
8bd1b87
chore(scripts): drop `AUTO-GENERATED` header from emitted files
voltjia May 9, 2026
fdfb295
fix(scripts): pipe generated headers through clang-format
voltjia May 9, 2026
800619d
style(scripts): apply `ruff format` from latest
voltjia May 9, 2026
cfea02e
build: throttle torch source compilation via Ninja job pool
voltjia May 9, 2026
dc2991c
build: add `clang-format` to build-system requires
voltjia May 9, 2026
0f00407
fix(scripts): pip-install `clang-format` if missing at codegen time
voltjia May 9, 2026
c739b19
fix(scripts): make `clang-format` optional at codegen time
voltjia May 9, 2026
ea3888b
fix(build): break cyclic dep between `infiniops` and torch object lib
voltjia May 9, 2026
49c3a25
build: skip PyTorch auto-detection on Cambricon
voltjia May 9, 2026
e734ded
test: skip overloads that the harness cannot drive cleanly
voltjia May 9, 2026
bb86ccd
test: resolve dtype attributes lazily for older torch forks
voltjia May 9, 2026
a2f1bf5
style(tests): apply ruff format
voltjia May 9, 2026
8c9c384
test: skip `mode` op (`torch_musa` kernel hangs on MUSA)
voltjia May 9, 2026
079fff0
build: probe system Python for `torch` when build-isolated env lacks it
voltjia May 10, 2026
20bd6b3
feat: pin codegen schema to the locally installed torch version
voltjia May 10, 2026
9cb7b73
fix(scripts): fall back to latest stable when torch version tag is un…
voltjia May 10, 2026
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
56 changes: 48 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,71 @@ endif()
if(AUTO_DETECT_BACKENDS)
message(STATUS "Auto-detecting available backends...")

# The Python that scikit-build's build-isolated environment hands
# us does not have `torch` (only `[build-system].requires` is
# installed). Fall back to a list of common system interpreters so
# the auto-detection finds `torch` when it is in the install env
# but not the build env. The first interpreter that successfully
# imports `torch` wins and is reused by the `WITH_TORCH` block
# below for include / library lookups.
find_package(Python COMPONENTS Interpreter QUIET)

if(Python_FOUND)
set(_torch_python_candidates "${Python_EXECUTABLE}")
foreach(_candidate
python3
python
/usr/bin/python3
/usr/local/bin/python3
/opt/conda/bin/python
/opt/conda/bin/python3)
find_program(_resolved_${_candidate} ${_candidate})
if(_resolved_${_candidate} AND
NOT _resolved_${_candidate} STREQUAL "${Python_EXECUTABLE}")
list(APPEND _torch_python_candidates "${_resolved_${_candidate}}")
endif()
endforeach()

foreach(_py ${_torch_python_candidates})
if(NOT _py)
continue()
endif()

execute_process(
COMMAND ${Python_EXECUTABLE} -c "import torch"
COMMAND "${_py}" -c "import torch"
RESULT_VARIABLE _torch_import_result
OUTPUT_QUIET
ERROR_QUIET
)

if(_torch_import_result EQUAL 0)
set(WITH_TORCH ON)
message(STATUS "Auto-detected PyTorch.")
set(_TORCH_PYTHON "${_py}")
break()
endif()
endforeach()

if(_TORCH_PYTHON)
set(WITH_TORCH ON)
message(STATUS "Auto-detected PyTorch (via ${_TORCH_PYTHON}).")
endif()
endif()

if(WITH_TORCH)
find_package(Python COMPONENTS Interpreter REQUIRED)

# Prefer the interpreter that the auto-detect block already
# confirmed has `torch` (this is the system Python on hosts that
# use scikit-build's build-isolation, where the build interpreter
# does not have `torch`). Fall back to `Python_EXECUTABLE` for
# explicit `-DWITH_TORCH=ON` invocations.
if(NOT _TORCH_PYTHON)
set(_TORCH_PYTHON "${Python_EXECUTABLE}")
endif()

# Query `torch` paths directly instead of using `find_package(Torch)`,
# which pulls in Caffe2's CMake config and may fail on platforms with
# non-standard CUDA toolchains.
execute_process(
COMMAND ${Python_EXECUTABLE} -c "from torch.utils.cpp_extension import include_paths; print(';'.join(include_paths()))"
COMMAND ${_TORCH_PYTHON} -c "from torch.utils.cpp_extension import include_paths; print(';'.join(include_paths()))"
OUTPUT_VARIABLE TORCH_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _torch_result
Expand All @@ -127,7 +167,7 @@ if(WITH_TORCH)
endif()

execute_process(
COMMAND ${Python_EXECUTABLE} -c "from torch.utils.cpp_extension import library_paths; print(';'.join(library_paths()))"
COMMAND ${_TORCH_PYTHON} -c "from torch.utils.cpp_extension import library_paths; print(';'.join(library_paths()))"
OUTPUT_VARIABLE _torch_lib_dirs
OUTPUT_STRIP_TRAILING_WHITESPACE
)
Expand All @@ -144,7 +184,7 @@ if(WITH_TORCH)
# the bundled `NEEDED` entries (otherwise: `undefined reference to
# _gfortran_etime@GFORTRAN_8` etc.).
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import os, torch; d = os.path.dirname(torch.__file__); p = os.path.join(os.path.dirname(d), 'torch.libs'); print(p if os.path.isdir(p) else '')"
COMMAND ${_TORCH_PYTHON} -c "import os, torch; d = os.path.dirname(torch.__file__); p = os.path.join(os.path.dirname(d), 'torch.libs'); print(p if os.path.isdir(p) else '')"
OUTPUT_VARIABLE TORCH_BUNDLED_LIBS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
Expand All @@ -163,7 +203,7 @@ if(WITH_TORCH)
# A mismatch causes linker errors (e.g. undefined reference to
# `c10::Device::Device(std::string const&)`).
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import torch; print(int(torch.compiled_with_cxx11_abi()))"
COMMAND ${_TORCH_PYTHON} -c "import torch; print(int(torch.compiled_with_cxx11_abi()))"
OUTPUT_VARIABLE TORCH_CXX11_ABI
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _torch_abi_result
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["scikit-build-core", "pybind11", "libclang"]
requires = ["scikit-build-core", "pybind11", "libclang", "pyyaml", "clang-format"]
build-backend = "scikit_build_core.build"

[project]
Expand Down
Loading
Loading