Skip to content

Make reduction bound temporaries use PRIVATE address space#649

Merged
inducer merged 1 commit intomainfrom
copilot/fix-global-temporaries-bounds
Mar 17, 2026
Merged

Make reduction bound temporaries use PRIVATE address space#649
inducer merged 1 commit intomainfrom
copilot/fix-global-temporaries-bounds

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Scalar temporaries generated to store non-affine reduction bounds were allocated in GLOBAL address space, causing race conditions when parallel threads share those locations.

Changes

  • get_loopy_temporary: Add address_space parameter (default lp.AddressSpace.GLOBAL preserves existing behavior).
  • add_store: Add address_space parameter, forwarded to get_loopy_temporary when output_to_temporary=True.
  • Reduction bounds call site: Pass address_space=lp.AddressSpace.PRIVATE when storing non-affine reduction bound scalars, giving each thread its own copy.
# Before: bound temps were GLOBAL — shared across threads
bound_result = StoredResult(bound_name, 0, frozenset([
    add_store(..., output_to_temporary=True, ...)]))

# After: bound temps are PRIVATE — thread-local
bound_result = StoredResult(bound_name, 0, frozenset([
    add_store(..., output_to_temporary=True, ...,
              address_space=lp.AddressSpace.PRIVATE)]))
  • Test: test_reduction_bound_temps_are_private uses a CSR matrix multiply (which triggers non-affine bounds) and asserts all generated *_lbound/*_ubound temporaries have PRIVATE address space.
Original prompt

This section details on the original issue you should resolve

<issue_title>Temporaries for bounds should not be global</issue_title>
<issue_description>In loopy code generation for reduction bounds (see pytato/target/loopy/codegen.py around line 570), bounds get stored in what turn out to be global temporaries. That's likely to create race conditions; those temporaries should be private.

cc @majosm

x-ref: inducer/arraycontext#349 (comment)</issue_description>

<agent_instructions>Please create a plan for how this could be fixed. Likely, add_store will need an argument indicating the address space.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Fix global temporaries for reduction bounds Make reduction bound temporaries use PRIVATE address space Mar 17, 2026
Copilot AI requested a review from inducer March 17, 2026 19:08
@inducer inducer force-pushed the copilot/fix-global-temporaries-bounds branch from b8d690a to cf59861 Compare March 17, 2026 19:32
@inducer inducer marked this pull request as ready for review March 17, 2026 19:41
Copilot AI review requested due to automatic review settings March 17, 2026 19:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts Pytato’s Loopy code generation so that scalar temporaries created for non-affine reduction bounds are placed in PRIVATE address space (instead of GLOBAL), preventing races in parallel kernels. It also adds a regression test and updates Sphinx reference aliasing for the new Loopy symbol.

Changes:

  • Generate reduction-bound temporaries with lp.AddressSpace.PRIVATE to avoid cross-thread races.
  • Extend add_store/get_loopy_temporary to accept an address_space parameter (defaulting to GLOBAL for existing behavior).
  • Add a regression test asserting reduction-bound temps use PRIVATE address space; add a Sphinx missing-reference alias for lp.AddressSpace.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pytato/target/loopy/codegen.py Adds address_space plumbing and uses PRIVATE for reduction bound temporaries.
test/test_codegen.py Adds regression test checking address space of reduction-bound temporaries.
doc/conf.py Adds Sphinx missing-reference alias for lp.AddressSpace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@inducer inducer force-pushed the copilot/fix-global-temporaries-bounds branch from 7d0c686 to fdaee05 Compare March 17, 2026 19:47
@inducer inducer enabled auto-merge (rebase) March 17, 2026 19:47
…ess space

Co-authored-by: inducer <352067+inducer@users.noreply.github.com>

Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@inducer inducer force-pushed the copilot/fix-global-temporaries-bounds branch from fdaee05 to 8dc6267 Compare March 17, 2026 19:50
@inducer inducer merged commit 27a9383 into main Mar 17, 2026
10 checks passed
@inducer inducer deleted the copilot/fix-global-temporaries-bounds branch March 17, 2026 20:09
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.

Temporaries for bounds should not be global

3 participants