Let a program choose the stack or the heap for a tensor

Open
#3,546 5 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start with promoteOwnedBuffers in src/dialect/VxLowering.cpp and read docs/language_rules_for_a_parallel_compiler.md for the function signature contract. Review the stack promotion rules and the linked context in #3542 to understand the current size limit and escape checks. The issue is done when the language and compiler support a defined way to choose stack or heap storage, including the listed size, return, call, and task cases.

Written by the indexing model from the issue text.

Description

core-lang design enhancement

Vx has no syntax to choose where a tensor's buffer goes. The compiler chooses:

  • A local tensor starts on the heap. promoteOwnedBuffers in src/dialect/VxLowering.cpp moves it to the stack when its shape is fixed, it is at most 4096 bytes, and no call, return or branch takes it.
  • After #3542, the caller of a function that returns a tensor uses the same 4096-byte limit for the result.

So a program cannot ask for the stack for a larger buffer. An example is a 64 KB scratch tile in a hot loop, where a malloc in each iteration costs too much. A program also cannot ask for the heap for a small buffer. Rust gives this choice through the type ([f32; N] or Box/Vec). Vx has one Tensor type for both.

To decide:

  • The syntax, for example an annotation on the let.
  • What happens when a buffer is too large for the stack. Each task has its own stack, and the compiler does not know its size.
  • Whether a function can ask for the stack for its result. The caller makes that buffer, so the choice must be in the signature ("A signature is the whole contract" in docs/language_rules_for_a_parallel_compiler.md).
  • Whether a stack tensor can leave its function: a return, a call that takes it by value, or a task that takes it. Stack promotion refuses all of these now.

Found while reviewing #3542, which fixes #3496.

Dominant language
Rust
Stars
35
Forks
5
Avg merge
12h 26m
Merged PRs (30d)
799

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vx-lang/Vx

All issues in vx-lang/Vx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.