Skip to content

Support: configurable ring buffer sizes via environment variables - #141

Merged
ChaoWao merged 1 commit into
mainfrom
refactor/ring-buffer-env-config
Feb 28, 2026
Merged

ChaoWao merged 1 commit into
mainfrom
refactor/ring-buffer-env-config

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

Add PTO2_RING_TASK_WINDOW, PTO2_RING_HEAP, PTO2_RING_DEP_POOL env vars to override compile-time ring buffer defaults at runtime.

  • runtime.h/cpp: add pto2_task_window_size, pto2_heap_size, pto2_dep_list_pool_size fields (0 = use compile-time defaults)
  • runtime_maker.cpp: parse and validate env vars
  • aicpu_executor.cpp: apply overrides in Thread 3 before SM init

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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 enhances the system's flexibility by allowing critical ring buffer sizes to be adjusted at runtime through environment variables. This change moves away from hardcoded compile-time defaults, enabling dynamic performance tuning and adaptation to different operational environments without requiring recompilation. The new mechanism includes robust parsing and validation of environment variable inputs.

Highlights

  • Configurable Ring Buffer Sizes: Introduced the ability to configure ring buffer sizes (task window, heap, and dependency pool) at runtime using environment variables, overriding compile-time defaults.
  • Environment Variable Parsing: Implemented a utility function parse_env_uint64 to safely read and validate unsigned 64-bit integer values from environment variables, including checks for minimum values and power-of-2 constraints.
  • Runtime Integration: Integrated the parsing of PTO2_RING_TASK_WINDOW, PTO2_RING_HEAP, and PTO2_RING_DEP_POOL environment variables into the Runtime initialization process, and applied these overrides within the AicpuExecutor before SM initialization.

🧠 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.

Changelog
  • src/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp
    • Applied ring buffer size overrides from the Runtime object, which are populated by host environment variables, before SM initialization.
  • src/runtime/tensormap_and_ringbuffer/host/runtime_maker.cpp
    • Added a static helper function parse_env_uint64 to parse and validate unsigned 64-bit integers from environment variables.
    • Integrated logic to read PTO2_RING_TASK_WINDOW, PTO2_RING_HEAP, and PTO2_RING_DEP_POOL environment variables and store their validated values in the Runtime object.
  • src/runtime/tensormap_and_ringbuffer/runtime/runtime.cpp
    • Initialized the new pto2_task_window_size, pto2_heap_size, and pto2_dep_list_pool_size members to zero in the Runtime class constructor.
  • src/runtime/tensormap_and_ringbuffer/runtime/runtime.h
    • Added pto2_task_window_size, pto2_heap_size, and pto2_dep_list_pool_size as uint64_t members to the Runtime class to hold ring buffer size overrides.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 enhances runtime tuning by adding the ability to configure ring buffer sizes via environment variables. However, it introduces several critical security vulnerabilities. Specifically, environment variable overrides for task window size, heap size, and dependency list pool size can lead to buffer overflows as they are applied after buffers are already allocated with default sizes. Additionally, the creation of temporary SO files in world-writable directories with predictable filenames and without proper symlink protection poses a significant risk of symlink attacks and arbitrary code execution. Beyond these critical security concerns, further improvements are needed to handle potential overflows when parsing environment variables and to correct a minor log message format specifier for accurate logging.

Comment thread src/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp
Comment thread src/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp
Comment thread src/runtime/tensormap_and_ringbuffer/host/runtime_maker.cpp
Comment thread src/runtime/tensormap_and_ringbuffer/aicpu/aicpu_executor.cpp Outdated
Fix buffer overflow: allocate SM and heap using effective sizes
(env override or compile-time default) instead of always using
compile-time constants. Add errno/ERANGE check to strtoull parsing.
Fix DEV_INFO format specifiers for uint64_t values.
@ChaoWao
ChaoWao force-pushed the refactor/ring-buffer-env-config branch from 505d577 to 143aa58 Compare February 28, 2026 11:12
@ChaoWao
ChaoWao merged commit 7bc040d into main Feb 28, 2026
3 checks passed
@ChaoWao
ChaoWao deleted the refactor/ring-buffer-env-config branch February 28, 2026 11:24
PKUZHOU pushed a commit to PKUZHOU/simpler that referenced this pull request Mar 31, 2026
…-native-sys#141)

Fix buffer overflow: allocate SM and heap using effective sizes
(env override or compile-time default) instead of always using
compile-time constants. Add errno/ERANGE check to strtoull parsing.
Fix DEV_INFO format specifiers for uint64_t values.
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.

1 participant