Skip to content

Makes PyCallable dimension reversing logic consistent with that of PythonExtensionGen#8931

Merged
alexreinking merged 6 commits into
mainfrom
jiawen-pycallable
Feb 14, 2026
Merged

Makes PyCallable dimension reversing logic consistent with that of PythonExtensionGen#8931
alexreinking merged 6 commits into
mainfrom
jiawen-pycallable

Conversation

@jiawen
Copy link
Copy Markdown
Contributor

@jiawen jiawen commented Feb 4, 2026

When a generator emits a Python extension, the pipeline only accepts buffers that are C or F contiguous (PythonExtensionGen.cpp), throwing an exception if it's neither.

In contrast, a callable constructed from generator.compile_to_callable() constructs a pipeline that always reverses the dimensions of input buffers. It also non-contiguous buffers.

This PR changes the latter to be consistent with the former. Callables constructed from generator.compile_to_callable() now:

  • Reverses the order of dimensions if a buffer is C-contiguous.
  • Does not reverse the order of dimensions if a buffer is F-contiguous.
  • Rejects other buffers.

brew install clang-format lld llvm flatbuffers wabt python pybind11 doxygen eigen libpng libjpeg-turbo openblas
```

The `llvm` package includes `clang`, `clang-format`, and `lld`, too. To ensure
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homebrew pulled these out long ago.

Comment thread doc/BuildingHalideWithCMake.md Outdated

```shell
$ pipx install cmake
pipx install cmake
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the drive-by. My vs code auto-formatted this entire file - but for the better I think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the changes we've made to CI and Python dependency management in #8942, we should revert this file and consider improvements in a separate PR.

Comment thread python_bindings/src/halide/halide_/PyBuffer.h
Comment thread python_bindings/src/halide/halide_/PyCallable.cpp
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 4, 2026

I'll work on how hl.Buffer wraps existing Buffers in a followup PR?

Comment thread python_bindings/test/correctness/callable.py
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 13, 2026

@alexreinking PTAL?

Copy link
Copy Markdown
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look good. Please drop the doc changes from this; we need a bigger update as a separate work item.

Comment thread README.md Outdated
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 13, 2026

@alexreinking Reverted doc changes.

@jiawen jiawen requested a review from alexreinking February 13, 2026 19:35
@alexreinking
Copy link
Copy Markdown
Member

@jiawen


C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\cl.exe  /nologo /TP -DHALIDE_ENABLE_RTTI -DHALIDE_VERSION_MAJOR=22 -DHALIDE_VERSION_MINOR=0 -DHALIDE_VERSION_PATCH=0 -DHALIDE_WITH_EXCEPTIONS -DHalide_Python_EXPORTS -DPy_NO_LINK_LIB -IC:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-build\include -IC:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\src\runtime -external:IC:\Python311\Include -external:IC:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-build\vcpkg_installed\x64-windows\include -external:W0 /DWIN32 /D_WINDOWS /EHsc /O2 /Ob2 /DNDEBUG -std:c++17 -MD /bigobj /MP /showIncludes /Fopython_bindings\src\halide\CMakeFiles\Halide_Python.dir\halide_\PyCallable.cpp.obj /Fdpython_bindings\src\halide\CMakeFiles\Halide_Python.dir\ /FS -c C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(51): error C2065: 'ssize_t': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(51): error C2146: syntax error: missing ';' before identifier 'c_stride'
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(51): error C2065: 'c_stride': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(52): error C2065: 'ssize_t': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(52): error C2146: syntax error: missing ';' before identifier 'f_stride'
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(52): error C2065: 'f_stride': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(58): error C2065: 'c_stride': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(61): error C2065: 'c_stride': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(63): error C2065: 'f_stride': undeclared identifier
C:\build_bot\worker\halide-llvm_main-x86-64-windows\halide-source\python_bindings\src\halide\halide_\PyCallable.cpp(66): error C2065: 'f_stride': undeclared identifier

Unfortunately, ssize_t isn't a thing on Windows.

Comment thread python_bindings/src/halide/halide_/PyCallable.cpp Outdated
Comment thread python_bindings/src/halide/halide_/PyCallable.cpp Outdated
@alexreinking alexreinking self-requested a review February 14, 2026 16:58
Copy link
Copy Markdown
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the tweaks I asked for. LGTM pending green (which is actually a possibility now!)

@alexreinking alexreinking merged commit ec8654a into main Feb 14, 2026
17 checks passed
@alexreinking alexreinking deleted the jiawen-pycallable branch February 14, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants