-
Notifications
You must be signed in to change notification settings - Fork 15
feat(codegen): CCE codegen with orchestration and compile backend option #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @zhusy54, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant architectural enhancement to the PyPTO Intermediate Representation (IR) code generator. It transitions from a monolithic PTO assembly output to a more flexible multi-file generation system. This enables the clear separation of concerns between low-level computational kernels and high-level task orchestration. By compiling orchestration logic into C++ runtime code and kernels into distinct PTO assembly files, the framework gains the ability to define and manage complex execution flows, paving the way for more sophisticated hardware acceleration and task scheduling. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant and valuable feature by separating kernel and orchestration code generation. The implementation is extensive, touching the C++ core, Python bindings, high-level APIs, and tests. However, there are several critical issues in the current implementation, particularly regarding how intermediate tensor sizes are handled and how orchestration functions are identified and tested. These issues need to be addressed to ensure the feature is robust and correct. I've also included some suggestions for improving code quality and test coverage.
src/codegen/pto_codegen.cpp
Outdated
| oss << " std::cerr << \"Error: Expected at least " << expected_arg_count | ||
| << " args, got \" << arg_count << std::endl;\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error reporting is done using std::cerr, which writes directly to the standard error stream. This makes it difficult for the calling Python code to catch and handle errors gracefully. It would be better to throw a C++ exception, such as pypto::ValueError, which can be caught by the nanobind layer and translated into a proper Python exception.
throw ValueError("Error: Expected at least " + std::to_string(expected_arg_count) + " args, got " + std::to_string(arg_count));
python/pypto/ir/compile.py
Outdated
| # Save all generated files | ||
| for filepath, content in files.items(): | ||
| full_path = os.path.join(output_dir, filepath) | ||
|
|
||
| # Create subdirectories if needed (e.g., kernels/) | ||
| file_dir = os.path.dirname(full_path) | ||
| if file_dir: | ||
| os.makedirs(file_dir, exist_ok=True) | ||
|
|
||
| # Write file | ||
| with open(full_path, "w") as f: | ||
| f.write(content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e9776b2 to
bd52e03
Compare
8114c6e to
f76dd22
Compare
f0ef85e to
a23fcaf
Compare
16a4a91 to
7189eab
Compare
- Add orchestration code generation for task graph building (C++ runtime API) - Refactor CCECodegen.Generate() to accept Program and return multi-file dict - Kernel functions -> kernels/<func_name>.cpp - Orchestration -> orchestration/<func_name>.cpp - Move PTOCodegen from ir module to codegen module for unified API - Add CodegenBackend enum to ir.compile() for backend selection (PTO/CCE) - Improve DependencyAnalyzer to merge consecutive simple statements - Preserve func_type_ across optimization passes
7189eab to
8e6aa1e
Compare
Summary
CCECodegen, generate pto-isa C++ from PyPTO IR (kernels + control flow).orchestration_codegenmodule for host-side task-graph C++; kernel vs orchestration split byProgramandFunctionType.ir.compile()acceptscodegen=CodegenBackend.PTO|CCEand usesCCECodegen.generate(program)(snake_case) for CCE backend.Changes
Codegen
code_generator→cce_codegen(header/source and bindings).orchestration_codegen.h/cpp:GenerateOrchestration(program, func)used by both PTOCodegen and CCECodegen.CCECodegen::Generate(Program)returnsmap<path, content>:kernels/<name>.cppfor kernel functions,orchestration/<name>.cppfor orchestration.CCECodegen.generate(program)(snake_case) and updatecodegen.pyi.Compile
CodegenBackendenum (PTO,CCE) andcodegenparameter toir.compile().codegen=CodegenBackend.CCEusesCCECodegenand writes C++ artifacts.Other
docs/dev/11-cce_codegen.md.examples/ir_builder/orchestration_example.py.add_alloc_pass,dependency_analyzer,insert_sync_pass).Testing
cmake --build build && pytest tests/ut/ -v.Related