Expand description
§BHC Tensor IR
This crate defines the Tensor Intermediate Representation for the Basel Haskell Compiler. Tensor IR is specifically designed for numeric optimization and provides the foundation for guaranteed fusion and vectorization.
§Overview
Tensor IR is the key to BHC’s numeric performance. It captures:
- Shape and stride information: For layout-aware optimization
- Element types (dtypes): For unboxed numeric computation
- Operation structure: For fusion analysis
- Aliasing information: For safe in-place updates
§H26-SPEC Section 7 Compliance
Per the H26 specification, every tensor operation in Tensor IR must track:
| Property | Description |
|---|---|
dtype | Element type (Float32, Float64, Int32, etc.) |
shape | Dimension sizes |
strides | Byte strides per dimension |
layout | Memory layout (contiguous, strided, tiled) |
alias | Aliasing/ownership information |
§IR Pipeline Position
Source Code
|
v
[Parse/AST]
|
v
[HIR]
|
v
[Core IR] <- General purpose optimizations
|
| (Numeric Profile only)
v
[Tensor IR] <- This crate: shape-aware, fusion-ready
|
v
[Loop IR] <- Explicit iteration§Guaranteed Fusion Patterns
Per H26-SPEC Section 8, these patterns MUST fuse:
map f (map g x)-> single traversalzipWith f (map g a) (map h b)-> single traversalsum (map f x)-> single traversalfoldl' op z (map f x)-> single traversal
§Main Types
TensorOp: Tensor operationsTensorMeta: Metadata (shape, stride, dtype)Kernel: A fused computation unitShape: Tensor dimensionsDType: Element types
§See Also
bhc-core: Core IR that lowers to Tensor IRbhc-loop-ir: Loop IR for explicit iteration- H26-SPEC Section 7: Tensor Model
- H26-SPEC Section 8: Fusion Laws
Modules§
Structs§
- Alloc
Info - Allocation information for a kernel.
- Axis
- An axis specification.
- Buffer
Id - A unique identifier for buffers (memory allocations).
- Conv
Spec - Convolution specification.
- FoldFn
- A fold function.
- Fusion
Info - Fusion information for debugging and reporting.
- Kernel
- A fused computation kernel.
- Kernel
Id - A unique identifier for kernels.
- Loop
Info - Information about a single loop.
- Loop
Nest - A simple loop nest representation.
- MapFn
- A map function (element-wise transformation).
- Permutation
- A permutation for transpose.
- Shape
- Tensor shape (list of dimensions).
- Slice
Range - A range within a slice.
- Slice
Spec - A slice specification.
- Strides
- Memory strides for each dimension.
- Tensor
Id - A unique identifier for tensor operations.
- Tensor
Meta - Tensor metadata per H26-SPEC Section 7.3.
- Tensor
Ref - A reference to a tensor value.
- Tile
Info - Tiling information for cache-friendly layouts.
- ZipFn
- A zip function (combining two elements).
Enums§
- Alloc
Region - Memory regions for allocation.
- Binary
Op - Binary operations.
- Constant
Op - A constant tensor operation.
- DType
- Tensor element types (data types).
- Device
Target - Target device for GPU memory allocation.
- Dim
- A dimension size (may be static or dynamic).
- Fusion
Block Reason - Why fusion was blocked.
- Fusion
Decision - A fusion decision made by the compiler.
- Kernel
Body - The body of a kernel.
- Layout
- Memory layout of a tensor.
- Materialize
Reason - Why a tensor was materialized.
- Reduce
Op - Reduction operations.
- Scalar
Value - A scalar value.
- Tensor
IrError - Errors in Tensor IR operations.
- Tensor
Op - Tensor operations in the IR.
- UnaryOp
- Unary operations.