Skip to content

Add unsafe aliased memory checking system#1079

Merged
cliffburdick merged 1 commit intomainfrom
aliased_input_output
Oct 30, 2025
Merged

Add unsafe aliased memory checking system#1079
cliffburdick merged 1 commit intomainfrom
aliased_input_output

Conversation

@cliffburdick
Copy link
Collaborator

Closes #1025

Implement detection for unsafe memory aliasing between input and output tensors in transform operations. Enabled via MATX_EN_UNSAFE_ALIAS_DETECTION flag. Includes can_alias() trait function and matmul aliasing unit test.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 29, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cliffburdick
Copy link
Collaborator Author

/build

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR introduces an opt-in compile-time system to detect unsafe memory aliasing between input and output tensors in MatX transform operations. When MATX_EN_UNSAFE_ALIAS_DETECTION is enabled, the framework checks whether operations that permute indices (like fftshift, transpose, reverse, matmul) write to the same memory they read from, throwing exceptions to prevent race conditions. The implementation adds a can_alias() trait that allows inherently safe operations (FFT, element-wise ops) to bypass checks, while dangerous patterns like (a = fftshift1D(a)).run() now throw matxInvalidParameter. The detection system propagates aliasing metadata through the operator tree via the new ALIASED_MEMORY capability, checking pointer ranges at runtime only when the flag is set. Core changes include: adding AliasedMemoryQueryInput to track memory ranges and permutation flags; implementing get_capability<ALIASED_MEMORY> across 25+ operator files to mark which operations permute indices; injecting aliasing checks in BaseOp::run() before transform execution; and adding comprehensive documentation in docs_input/basics/debug.rst.

Important Files Changed

Filename Score Overview
include/matx/core/capabilities.h /5 Content not provided in context; likely defines OperatorCapability::ALIASED_MEMORY enum and related infrastructure
include/matx/core/operator_options.h 5/5 Adds AliasedMemoryQueryInput struct to track aliasing metadata (permutation flag, prerun phase, memory range pointers)
include/matx/core/type_utils_both.h 2/5 Implements can_alias() trait detection but has inverted logic: docstring says "without trait" while code checks FOR trait presence
include/matx/core/tensor_impl.h 3/5 Implements ALIASED_MEMORY capability in tensor_impl_t but has potential underflow bug when Size(dim) == 0, and partial-overlap logic may be too aggressive
include/matx/operators/base_operator.h 3/5 Injects aliasing checks into BaseOp::run() but has size-0 underflow risk in get_memory_range() and complex branching that needs careful validation
include/matx/generators/logspace.h 1/5 Duplicate function definition for operator()(index_t idx) will cause compilation failure
include/matx/operators/fftshift.h 1/5 Only FFTShift1DOp received ALIASED_MEMORY handling; FFTShift2DOp, IFFTShift1DOp, IFFTShift2DOp missing implementation
test/00_operators/aliased_memory_test.cu 2/5 Test has inverted assertions: OverlappingSlices and NestedTransformAliasing comments contradict EXPECT_THROW/EXPECT_NO_THROW
include/matx/operators/transpose.h 4/5 License header typo ('COpBRIGHT'); otherwise correctly implements ALIASED_MEMORY capability
include/matx/operators/find_peaks.h 3/5 Multiple license header corruptions ('sum', 'COpBRIGHT', 'SHsum') alongside correct capability implementation
include/matx/operators/conv.h 4/5 License typo ('COpBRIGHT'); removes duplicate get_capability_proc() correctly
include/matx/operators/fft.h 5/5 Adds can_alias trait and ALIASED_MEMORY handler that returns false to allow safe in-place FFT operations
include/matx/operators/chol.h 4/5 License typo ('COpBRIGHT'); correctly adds can_alias trait for cuSOLVER in-place support
include/matx/operators/matmul.h 3.5/5 Sets permutes_input_output=true but matmul doesn't actually permute indices in the transpose sense—may be overly conservative
CMakeLists.txt 5/5 Cleanly adds MATX_EN_UNSAFE_ALIAS_DETECTION build option following existing patterns
docs_input/basics/debug.rst 4/5 Comprehensive documentation with typos ('unitialized'); correctly explains imperfect detection and false positive scenarios
include/matx/operators/{reverse,hermitian,planar,interleaved,r2c,shift,stack,toeplitz}.h 5/5 All correctly implement ALIASED_MEMORY by setting permutes_input_output=true
include/matx/operators/{argmax,argminmax,set}.h 4/5 Properly propagate capability checks; set.h has significant refactoring alongside aliasing additions
include/matx/generators/{linspace,diag,alternate}.h & include/matx/operators/{index,interp}.h 5/5 Clean refactoring from get_capability_proc() to unified get_capability(InType&) signature
include/matx/transforms/svd/svd_cuda.h 5/5 Defensive initialization of i_dspace to prevent undefined behavior
include/matx/operators/binary_operators.h 5/5 Removes trailing whitespace—pure formatting cleanup
test/00_operators/CMakeLists.txt 5/5 Adds aliased_memory_test.cu to build in correct alphabetical position

Confidence score: 2/5

  • This PR requires very careful review before merging due to multiple correctness issues that will cause immediate failures and potential runtime bugs
  • Score reflects critical compilation errors (logspace.h duplicate function), incomplete operator coverage (fftshift variants), inverted test assertions (aliased_memory_test.cu), semantic confusion in trait detection (can_alias() docstring vs implementation mismatch), potential underflow bugs in memory range calculation (base_operator.h, tensor_impl.h when size=0), and widespread license header corruption across multiple files
  • Pay close attention to include/matx/generators/logspace.h (will not compile), include/matx/operators/fftshift.h (missing ALIASED_MEMORY for 3 of 4 operators), test/00_operators/aliased_memory_test.cu (assertions contradicting comments at lines 129-133 and 230-235), include/matx/core/type_utils_both.h (clarify intended trait semantics), and all files with license header typos (transpose.h, conv.h, chol.h, find_peaks.h)

Sequence Diagram

sequenceDiagram
    participant User
    participant Executor
    participant SetOp
    participant AliasChecker
    participant Operator
    participant CUDADevice

    User->>Executor: call run(set_op)
    Executor->>SetOp: Exec()
    
    alt MATX_EN_UNSAFE_ALIAS_DETECTION enabled
        SetOp->>AliasChecker: check_aliased_memory(lhs, rhs)
        AliasChecker->>SetOp: get_memory_range(lhs)
        Note over AliasChecker: Get first & last element pointers
        AliasChecker->>Operator: get_capability<ALIASED_MEMORY>(rhs, mem_range)
        Operator->>Operator: Check if memory overlaps
        
        alt Memory overlaps detected
            Operator-->>AliasChecker: true (aliased)
            AliasChecker-->>SetOp: throw matxInvalidParameter
            SetOp-->>User: Error: Aliased memory detected
        else No overlap or safe aliasing
            Operator-->>AliasChecker: false (not aliased)
            AliasChecker-->>SetOp: continue
        end
    end
    
    SetOp->>Operator: PreRun()
    SetOp->>CUDADevice: Execute kernel
    SetOp->>Operator: PostRun()
    SetOp-->>User: Operation complete
Loading

Additional Comments (9)

  1. include/matx/operators/transpose.h, line 21-24 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  2. include/matx/generators/logspace.h, line 102-105 (link)

    logic: duplicate operator() method - this exact signature already exists at lines 73-88 with the same implementation

  3. include/matx/operators/find_peaks.h, line 5 (link)

    syntax: typo: 'sum rights reserved' should be 'All rights reserved'

  4. include/matx/operators/find_peaks.h, line 21 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  5. include/matx/operators/find_peaks.h, line 24 (link)

    syntax: typo: 'SHsum' should be 'SHALL', and 'COpBRIGHT' should be 'COPYRIGHT'

  6. include/matx/operators/conv.h, line 21 (link)

    syntax: Typo: COpBRIGHT should be COPYRIGHT

  7. include/matx/operators/chol.h, line 21-24 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  8. include/matx/operators/fftshift.h, line 251 (link)

    syntax: Parameter t should be passed by const reference, not by value

  9. include/matx/operators/fftshift.h, line 343 (link)

    syntax: Parameter t should be passed by const reference

35 files reviewed, 23 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This review covers only the changes made since the last review, not the entire PR. The latest commit addresses a critical terminology error in the documentation. The text on line 67 of docs_input/basics/debug.rst incorrectly states the system has a "false negative rate of 0" when the surrounding context (lines 66, 79) and the system's actual behavior demonstrate it produces false positives, not false negatives. The unsafe aliasing detection system is explicitly described as "imperfect" (line 65) and line 79 provides an example labeled "False positive" where non-unity strides trigger incorrect warnings. The phrase "false negative rate of 0" contradicts this—it would mean the system never misses unsafe aliasing (which isn't claimed), when what's actually meant is the system avoids false negatives at the cost of false positives. This is a documentation-only change that corrects the technical description of the aliasing detection trade-offs to accurately reflect that the system errs on the side of over-reporting potential aliasing issues.

Important Files Changed

Filename Score Overview
docs_input/basics/debug.rst 3/5 Corrected uninitialized spelling errors and added aliasing detection documentation with terminology confusion

Confidence score: 3/5

  • This documentation-only change is low-risk but contains a critical terminology error that could confuse users about the system's behavior
  • Score reflects that line 67's "false negative rate of 0" statement directly contradicts the documented false positive behavior in the examples and system design philosophy
  • The terminology error in docs_input/basics/debug.rst line 67 needs immediate correction before merge to avoid user confusion about detection trade-offs

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@cliffburdick
Copy link
Collaborator Author

/build

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR implements a comprehensive unsafe aliased memory detection system for MatX to catch race conditions when transform operations write to the same tensor they read from while permuting indices. The system introduces a new ALIASED_MEMORY capability that propagates through the operator tree using an AliasedMemoryQueryInput structure containing memory range and permutation flags. Operators that reorder elements (fftshift, reverse, transpose, matmul, etc.) set permutes_input_output=true to signal unsafe aliasing when input/output memory overlaps. Element-wise operations and operators like FFT that support in-place execution can define a can_alias trait to opt out. The detection is opt-in via the MATX_EN_UNSAFE_ALIAS_DETECTION CMake flag to avoid performance overhead. The tensor_impl class computes memory footprints and checks for overlaps, distinguishing between complete overlaps (safe for contiguous non-permuting operations) and partial overlaps (always unsafe). Comprehensive unit tests validate the system catches unsafe patterns like (a = fftshift1D(a)).run() while allowing safe operations like (a = a + a).run().

Important Files Changed

Filename Score Overview
include/matx/core/capabilities.h 4/5 Adds ALIASED_MEMORY and ELEMENT_WISE enum values to OperatorCapability with capability_attributes specialization and OR_QUERY mapping
include/matx/core/operator_options.h 5/5 Defines AliasedMemoryQueryInput struct with permutes_input_output flag and memory range pointers for aliasing checks
include/matx/core/type_utils_both.h 4.5/5 Adds can_alias() trait detection function to identify operators that explicitly allow input/output memory aliasing
include/matx/core/tensor_impl.h 4/5 Implements ALIASED_MEMORY capability check in tensor_impl by computing memory footprint and detecting overlaps
include/matx/operators/base_operator.h 0/5 File included in PR but no meaningful changes detected in the diff provided
include/matx/operators/matmul.h 4/5 Adds ALIASED_MEMORY capability handling marking both matrix operands as permuting input/output indices
include/matx/operators/transpose.h 4/5 Implements ALIASED_MEMORY check marking transpose operations as index-permuting
include/matx/operators/reverse.h 5/5 Adds aliasing detection by setting permutes_input_output=true for reverse operations
include/matx/operators/fftshift.h 0/5 File included in PR but no detailed changes provided in diff
include/matx/operators/shift.h 4/5 Adds ALIASED_MEMORY capability marking shift operations as index-permuting
include/matx/operators/hermitian.h 3/5 Implements aliasing detection for hermitian operator which swaps and conjugates dimensions
include/matx/operators/stack.h 4/5 Adds ALIASED_MEMORY handling marking stack operations as permuting via dimension insertion
include/matx/operators/interleaved.h 4/5 Marks interleaved layout conversion as index-permuting for aliasing detection
include/matx/operators/planar.h 3/5 Adds aliasing detection to planar layout conversion though classification as permuting may need validation
include/matx/operators/r2c.h 4/5 Marks R2C reconstruction operations as index-permuting for unsafe aliasing detection
include/matx/operators/fft.h 2/5 Adds can_alias trait to FFT operations and returns false for ALIASED_MEMORY but has incomplete implementation (only non-cuFFTDx branch, FFT2Op missing trait)
include/matx/operators/chol.h 3/5 Adds can_alias trait to Cholesky decomposition but uses type-alias instead of function pattern
include/matx/operators/argmax.h 4/5 Adds get_capability method to propagate capability queries through input operator chain
include/matx/operators/argminmax.h 4/5 Implements capability propagation for argminmax reduction operator
include/matx/operators/find_peaks.h 2/5 Updates capability signature but contains critical license header corruption typos
include/matx/operators/set.h 0/5 File included in PR but no meaningful changes detected
include/matx/operators/conv.h 0/5 File included in PR but no meaningful changes detected
include/matx/operators/toeplitz.h 0/5 File included in PR but no meaningful changes detected
include/matx/operators/interp.h 0/5 File included in PR but no meaningful changes detected
include/matx/operators/binary_operators.h 5/5 Trivial whitespace cleanup removing trailing spaces
include/matx/generators/diag.h 5/5 Updates get_capability signature to accept InType parameter for aliasing infrastructure
include/matx/generators/logspace.h 0/5 Refactoring appears incomplete with conflicting operator() definitions causing compilation ambiguity
include/matx/generators/linspace.h 4.5/5 Removes duplicate get_capability_proc method retaining standardized get_capability interface
include/matx/generators/alternate.h 4/5 Renames get_capability_proc to get_capability with InType parameter for aliasing system
include/matx/generators/index.h 5/5 Removes redundant get_capability_proc method leaving unified get_capability interface
include/matx/transforms/svd/svd_cuda.h 5/5 Defensive initialization of i_dspace variable to prevent undefined behavior
CMakeLists.txt 5/5 Adds MATX_EN_UNSAFE_ALIAS_DETECTION CMake option defaulting to OFF with corresponding compile definition
test/00_operators/CMakeLists.txt 5/5 Registers new aliased_memory_test.cu test file in alphabetical order
test/00_operators/aliased_memory_test.cu 3/5 Comprehensive aliasing detection tests with contradictory comments and test naming issues
docs_input/basics/debug.rst 4.5/5 Adds documentation for unsafe aliased memory checking system with examples and limitations

Confidence score: 2/5

  • This PR requires careful review before merging due to incomplete implementations, conflicting code patterns, and critical bugs that will prevent compilation
  • Score reduced due to: 1) logspace.h has duplicate conflicting operator() definitions causing compilation failure, 2) FFT aliasing support incomplete (only non-cuFFTDx branch, FFT2Op missing can_alias trait), 3) find_peaks.h has corrupted license header, 4) test file has contradictory comments/expectations suggesting unclear specification, 5) multiple operators missing from aliasing detection (fftshift 2D variants per previous review), 6) tensor_impl overlap logic may be incorrect for non-contiguous tensors (previous review concern unresolved)
  • Pay close attention to include/matx/generators/logspace.h (compilation failure), include/matx/operators/fft.h (incomplete implementation), include/matx/operators/find_peaks.h (license corruption), test/00_operators/aliased_memory_test.cu (spec ambiguity), and include/matx/core/tensor_impl.h (overlap logic validation needed)

Sequence Diagram

sequenceDiagram
    participant User
    participant BaseOp
    participant SetOp
    participant get_memory_range
    participant check_aliased_memory
    participant Operator
    participant get_capability

    User->>BaseOp: (a = op).run(exec)
    BaseOp->>SetOp: Exec()
    
    alt is_matx_set_op with transform and tensor_view
        SetOp->>check_aliased_memory: check_aliased_memory(lhs, rhs, false)
        check_aliased_memory->>get_memory_range: get_memory_range(lhs, is_prerun)
        get_memory_range->>get_memory_range: Get first element address
        get_memory_range->>get_memory_range: Get last element address
        get_memory_range-->>check_aliased_memory: AliasedMemoryQueryInput
        check_aliased_memory->>Operator: get_operator_capability<ALIASED_MEMORY>(rhs, mem_range)
        Operator->>get_capability: get_capability<ALIASED_MEMORY>(in)
        get_capability->>get_capability: Check if memory overlaps
        alt Memory overlaps
            get_capability-->>Operator: true
            Operator-->>check_aliased_memory: true
            check_aliased_memory->>BaseOp: MATX_THROW(matxInvalidParameter)
            BaseOp-->>User: Exception
        else No overlap
            get_capability-->>Operator: false
            Operator-->>check_aliased_memory: false
            check_aliased_memory-->>SetOp: continue
            SetOp->>SetOp: TransformExec()
            SetOp-->>BaseOp: Success
            BaseOp-->>User: Success
        end
    else Other set operations
        SetOp->>check_aliased_memory: check_aliased_memory(lhs, rhs, true)
        check_aliased_memory->>get_memory_range: get_memory_range(lhs, is_prerun)
        get_memory_range-->>check_aliased_memory: AliasedMemoryQueryInput
        check_aliased_memory->>Operator: get_operator_capability<ALIASED_MEMORY>(rhs, mem_range)
        Operator->>get_capability: get_capability<ALIASED_MEMORY>(in)
        get_capability-->>Operator: result
        Operator-->>check_aliased_memory: result
        alt Memory aliases
            check_aliased_memory->>BaseOp: MATX_THROW(matxInvalidParameter)
            BaseOp-->>User: Exception
        else No aliasing
            check_aliased_memory-->>SetOp: continue
            SetOp->>SetOp: PreRun()
            SetOp->>SetOp: ex.Exec()
            SetOp->>SetOp: PostRun()
            SetOp-->>BaseOp: Success
            BaseOp-->>User: Success
        end
    end
Loading

Additional Comments (9)

  1. include/matx/generators/logspace.h, line 73-88 (link)

    logic: This templated operator() is never invoked - line 104 non-templated operator() calls itself with DefaultCapabilities, but the templated version at line 74 expects a CapType parameter that is never used from the calling site. Should the non-templated operator() at line 102-105 call the templated version at line 74, or should the templated version be removed if it's not part of the capability system API?

  2. include/matx/generators/logspace.h, line 102-105 (link)

    logic: Duplicate operator() function - both line 74 and line 102 define operator()(index_t idx) with different signatures. This will cause compilation ambiguity

  3. include/matx/operators/fft.h, line 688 (link)

    logic: FFT2Op is missing the can_alias trait that FFTOp has on line 85. This inconsistency means FFT2 operations won't participate in the aliasing detection system properly.

  4. include/matx/operators/conv.h, line 21 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  5. include/matx/operators/conv.h, line 24 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  6. include/matx/generators/linspace.h, line 71-80 (link)

    style: get_capability removed get_capability_proc template parameter, but still takes unused InType parameter. This parameter isn't used anywhere in the function body.

  7. include/matx/operators/find_peaks.h, line 5 (link)

    syntax: typo: 'sum' should be 'All'

  8. include/matx/operators/find_peaks.h, line 21 (link)

    syntax: typo: 'COpBRIGHT' should be 'COPYRIGHT'

  9. include/matx/operators/find_peaks.h, line 24 (link)

    syntax: typo: 'SHsum' should be 'SHALL', and 'COpBRIGHT' should be 'COPYRIGHT'

35 files reviewed, 20 comments

Edit Code Review Agent Settings | Greptile

Implement detection for unsafe memory aliasing between input and output tensors
in transform operations. Enabled via MATX_EN_UNSAFE_ALIAS_DETECTION flag.
Includes can_alias() trait function and matmul aliasing unit test.
@cliffburdick
Copy link
Collaborator Author

/build

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR implements unsafe memory aliasing detection for MatX transform operations, addressing issue #1025. The system detects when input and output tensors share memory and the operation permutes indices (creating race conditions).

Key Implementation Details:

  • Capability System Integration: Adds ALIASED_MEMORY capability to the existing operator capability framework with OR_QUERY aggregation
  • Trait-Based Detection: Introduces can_alias() trait function to identify transform operators that support aliasing checks
  • Memory Range Comparison: Computes first/last element addresses to detect overlapping memory regions between LHS and RHS
  • Operator Marking: Transform operators that permute indices (fftshift, shift, reverse, transpose, matmul) set permutes_input_output=true flag
  • Compile-Time Flag: Feature is opt-in via MATX_EN_UNSAFE_ALIAS_DETECTION CMake flag

Major Changes:

  • Core infrastructure: type_utils_both.h, capabilities.h, tensor_impl.h, base_operator.h
  • Operator implementations: 20+ operators updated with aliasing capability checks
  • Comprehensive test suite: 11 test cases covering safe/unsafe aliasing scenarios
  • Documentation: User guide explaining the feature and its trade-offs

Issues Found:

Most issues have already been identified in previous comments. The implementation is sound overall, with a few areas needing attention around edge cases and consistency.

Confidence Score: 4/5

  • This PR is safe to merge with minor fixes needed for test comments and documentation typos
  • The core implementation is architecturally sound and well-integrated into the existing capability system. The feature is opt-in via compile flag, minimizing risk. However, several issues prevent a score of 5: (1) test comments contradict actual expectations in aliased_memory_test.cu:129-130 and :230-232, (2) multiple documentation typos, (3) inconsistent aliasing capability implementation across similar operators (e.g., FFTShift1D has it but IFFTShift variants don't), and (4) some edge case logic needs verification (non-contiguous tensor aliasing, zero-size dimensions). These are quality-of-life issues rather than critical bugs, but should be addressed before merge.
  • test/00_operators/aliased_memory_test.cu (fix contradictory comments), docs_input/basics/debug.rst (fix typos and terminology), include/matx/operators/fftshift.h (add aliasing to IFFT variants for consistency)

Important Files Changed

File Analysis

Filename Score Overview
include/matx/core/type_utils_both.h 4/5 Adds can_alias() trait function to detect transform ops with aliasing capability. Implementation correctly checks for both transform op type and can_alias trait presence.
include/matx/core/capabilities.h 5/5 Adds ALIASED_MEMORY capability enum and associated query infrastructure. Clean implementation with proper OR_QUERY aggregation logic.
include/matx/core/tensor_impl.h 4/5 Implements memory range detection for tensors using first/last element addresses. Logic handles complete vs partial overlaps, though complete overlap logic for non-contiguous tensors needs verification.
include/matx/operators/base_operator.h 4/5 Core aliasing detection logic with check_aliased_memory() and check_mtie_aliased_memory() functions. Properly queries operator tree for aliasing using capability system.
test/00_operators/aliased_memory_test.cu 3/5 Comprehensive test suite with positive and negative test cases. However, comments on lines 129-130 and 230-232 contradict the actual test expectations (already reported).
docs_input/basics/debug.rst 3/5 Adds documentation for aliasing detection feature. Contains typos ('unitialized' instead of 'uninitialized') and some terminology issues around false positives/negatives (already reported).

Sequence Diagram

sequenceDiagram
    participant User
    participant SetOp as SetOp/Transform
    participant BaseOp as BaseOp::check_aliased_memory
    participant LHS as LHS Tensor
    participant RHS as RHS Operator Tree
    participant TensorImpl as TensorImpl::get_capability

    User->>SetOp: (a = fftshift1D(a)).run()
    SetOp->>BaseOp: check_aliased_memory(a, fftshift1D(a))
    
    Note over BaseOp: If MATX_EN_UNSAFE_ALIAS_DETECTION enabled
    
    BaseOp->>LHS: get_memory_range(a)
    LHS-->>BaseOp: {start_ptr, end_ptr}
    
    BaseOp->>RHS: get_operator_capability<ALIASED_MEMORY>(fftshift1D(a), mem_range)
    
    RHS->>RHS: FFTShift1DOp::get_capability()
    Note over RHS: Sets permutes_input_output=true
    
    RHS->>TensorImpl: Recurse to child op (tensor a)
    TensorImpl->>TensorImpl: Check if tensor memory overlaps
    Note over TensorImpl: Compare start/end pointers<br/>Check complete vs partial overlap
    
    TensorImpl-->>RHS: true (aliasing detected)
    RHS-->>BaseOp: true (propagated via OR_QUERY)
    
    alt Aliasing Detected
        BaseOp->>BaseOp: throw matxInvalidParameter
        BaseOp-->>User: Exception: "Aliased memory detected"
    else No Aliasing
        BaseOp-->>SetOp: Continue execution
        SetOp->>SetOp: Execute transform
        SetOp-->>User: Success
    end
Loading

35 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@cliffburdick cliffburdick merged commit 758d3e8 into main Oct 30, 2025
1 check passed
@cliffburdick cliffburdick deleted the aliased_input_output branch October 30, 2025 22:19
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.

[BUG] Prevent assignment from element-wise ops on same input

1 participant