Skip to content

Commit 94d73aa

Browse files
authored
[Docs] Add eviction policy (#839)
1 parent ae7473d commit 94d73aa

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ Changing these options results in often significantly different
263263
output Triton code, allowing the autotuner to explore a wide range of
264264
implementations from a single Helion kernel.
265265

266+
* **load_eviction_policies** (`list[str]`):
267+
Controls eviction policy used for loads discovered in device loops. Each entry
268+
corresponds to a load site; allowed values are `""` (no policy), `"first"`
269+
(maps to Triton `evict_first`), and `"last"` (maps to Triton `evict_last`).
270+
Explicit `eviction_policy=...` on `hl.load` overrides this config.
271+
266272
## Settings for Development and Debugging
267273

268274
When developing kernels with Helion, you might prefer skipping autotuning for faster iteration. To

docs/api/config.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ Configs are typically discovered automatically through autotuning, but can also
116116
- ``"block_ptr"``: Block pointer indexing
117117
```
118118

119+
### Memory and Caching
120+
121+
```{eval-rst}
122+
.. autoattribute:: Config.load_eviction_policies
123+
124+
Eviction policies for load operations issued from device loops. Provide one policy
125+
per ``hl.load`` site discovered in the kernel. Allowed values:
126+
127+
- ``""``: No eviction policy (omitted)
128+
- ``"first"``: Maps to Triton ``eviction_policy='evict_first'``
129+
- ``"last"``: Maps to Triton ``eviction_policy='evict_last'``
130+
131+
Notes:
132+
133+
- The number of entries must match the number of load sites considered tunable by the kernel.
134+
- An explicit ``eviction_policy=...`` argument passed to ``hl.load`` overrides this config.
135+
```
136+
119137
## Usage Examples
120138

121139
### Manual Config Creation
@@ -142,6 +160,31 @@ def my_kernel(x: torch.Tensor) -> torch.Tensor:
142160
return result
143161
```
144162

163+
### Eviction Policy Example
164+
165+
```python
166+
import torch
167+
import helion
168+
import helion.language as hl
169+
170+
@helion.kernel(
171+
config={
172+
"block_size": 16,
173+
"load_eviction_policies": ["", "last"], # second load uses evict_last
174+
}
175+
)
176+
def kernel_with_eviction(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
177+
out = torch.empty_like(x)
178+
for tile in hl.tile(x.size(0)):
179+
a = hl.load(x, [tile]) # No eviction policy
180+
b = hl.load(y, [tile]) # Will use evict_last from config
181+
out[tile] = a + b
182+
return out
183+
184+
# Explicit policy on hl.load overrides config:
185+
# hl.load(x, [tile], eviction_policy="evict_first")
186+
```
187+
145188
### Config Serialization
146189

147190
```python

0 commit comments

Comments
 (0)