﻿# IREE hal.tensor.alias: destination storage is a semantic promise, actual aliasing is a hint

Read IREE hal.tensor.alias as an output-storage contract that permits copy-equivalent behavior, and distinguish supplied buffer capacity from buffer-view metadata and guaranteed aliasing.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-iree-hal-tensor-alias-output-storage-not-guarantee/
Language: en

## A destination annotation is mistaken for a zero-copy guarantee

An application supplies output storage and assumes the compiler must produce every intermediate directly into that allocation. The result is correct, but profiling still shows a copy. This need not violate the contract. A destination-facing semantic guarantee can allow different physical implementations. Identify what the operation guarantees about the destination’s contents before turning an optimization opportunity into an advertised zero-copy promise. Correct output placement and guaranteed identity of every backing allocation are different claims.

## The alias operation explicitly allows copy-equivalent behavior

The [HAL dialect specification](https://iree.dev/reference/mlir-dialects/HAL/) describes `hal.tensor.alias` as a hint for shared backing storage while preserving behavior as if a copy occurred. A producer may use the target directly when possible, but other cases remain valid. Review the exact operation rather than extrapolating from the word alias. Also distinguish the supplied storage capacity from the logical amount occupied by a dynamic tensor; the destination can be larger than the encoded result.

## A buffer view does not override the operation’s storage rules

The same specification explains how this operation treats a supplied buffer view’s metadata. Review the actual backing storage and required encoded size instead of assuming the view’s visible shape establishes the result type. The [C API guide](https://iree.dev/reference/bindings/c-api/) supplies background on runtime buffers and views. The [tensor descriptor guide](/journal/learn-tensor-memory-descriptor/) helps distinguish metadata from storage, but the compiler operation’s explicit contract determines what information is used at this boundary.

## Compilation decides whether the ideal placement is achievable

The [HAL passes reference](https://iree.dev/reference/mlir-passes/HAL/) documents transformations in this part of the pipeline. Inspect the lowered program and a representative execution when evaluating copies. A changed producer, encoding or target can alter physical placement while preserving observable results. Do not remove a transfer solely because an upstream alias hint exists. First establish whether the producer can legally satisfy the requested placement directly under the actual lowering and device constraints.

## Measure the optimization separately from correctness

Validate destination contents and supported dynamic extents, then assess whether the implementation achieves the desired transfer reduction. The [allocation lifetime guide](/journal/learn-stream-ordered-allocation-lifetime/) provides context for retaining destination storage until its work completes. Report semantic correctness and observed physical reuse separately. This keeps a useful compiler hint honest: it can enable direct placement without guaranteeing that every future model, target or compiler revision will realize the same zero-copy execution strategy.
