Skip to content

Allows the caller to pass in argv to hl.main()#8937

Merged
alexreinking merged 12 commits into
mainfrom
jiawen-hl_main
Feb 14, 2026
Merged

Allows the caller to pass in argv to hl.main()#8937
alexreinking merged 12 commits into
mainfrom
jiawen-hl_main

Conversation

@jiawen
Copy link
Copy Markdown
Contributor

@jiawen jiawen commented Feb 7, 2026

Fixes #8903

@jiawen jiawen requested a review from abadams February 7, 2026 01:03
@jiawen jiawen assigned alexreinking and unassigned alexreinking Feb 7, 2026
@jiawen jiawen requested a review from alexreinking February 7, 2026 01:03
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 7, 2026

Any suggestions on how / where to put tests? A simple test would be to use something like SimplyPyGenerator and call it a few times with different values of -f. But then we'd need to verify what was written to disk.

Comment thread python_bindings/src/halide/halide_/PyGenerator.cpp Outdated
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 10, 2026

Hold off on merging - it occurs to me that one can implement hl.main() entirely in Python - there's even a place for it. Then the pybind11 code won't be nearly as messy, using embed().

@mcourteaux mcourteaux marked this pull request as draft February 11, 2026 15:19
@jiawen jiawen marked this pull request as ready for review February 12, 2026 20:42
@jiawen
Copy link
Copy Markdown
Contributor Author

jiawen commented Feb 12, 2026

@alexreinking PTAL. Much cleaner I think.

@jiawen jiawen requested a review from alexreinking February 12, 2026 20:42
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.

Looks good with one nitpick

Comment thread python_bindings/src/halide/halide_/PyGenerator.cpp Outdated
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.

Argv arrays are meant to be NULL-pointer terminated. I don't think we rely on this today, but a very reasonable refactor to generate_filter_main might rely on it later.

Comment thread python_bindings/src/halide/halide_/PyGenerator.cpp Outdated
mutable_argv.push_back(const_cast<char *>(s.c_str()));
}
int result = Halide::Internal::generate_filter_main((int)argv.size(), argv.data(), PyGeneratorFactoryProvider());
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size(), mutable_argv.data(), PyGeneratorFactoryProvider());
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.

Suggested change
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size(), mutable_argv.data(), PyGeneratorFactoryProvider());
int result = Halide::Internal::generate_filter_main((int)mutable_argv.size() - 1, mutable_argv.data(), PyGeneratorFactoryProvider());

Comment thread python_bindings/src/halide/halide_/PyGenerator.cpp Outdated
Comment thread python_bindings/src/halide/halide_/PyGenerator.cpp
Comment thread python_bindings/src/halide/__init__.py
Comment thread python_bindings/src/halide/_generator_helpers.py
@jiawen jiawen requested a review from alexreinking February 13, 2026 18:27
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 fixed up the formatting in _generator_filter_main and tweaked names to make it clear that a Python list of arguments is getting translated into a compliant argv array.

@alexreinking alexreinking merged commit b8c7457 into main Feb 14, 2026
17 checks passed
@alexreinking alexreinking deleted the jiawen-hl_main branch February 14, 2026 23:40
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.

[Python bindings] hl.main() does not accept arguments

2 participants