Skip to content

Commit ad1f5dc

Browse files
authored
fix sort: remove calls to _unwrap_if_constexpr to be compatible with triton 3.1 (#738)
* fix sort: remove calls to _unwrap_if_constexpr to be compatible with triton 3.1 * remove constexpr type annotation for arguments in functions decorated with tl.constexpr * backport unwrap_if_constexpr
1 parent 77b1f38 commit ad1f5dc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/flag_gems/ops/sort.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import torch
44
import triton
55
import triton.language as tl
6-
from triton.language.core import _unwrap_if_constexpr
76

87
from ..runtime import torch_device_fn
98
from ..utils import libentry
@@ -12,22 +11,26 @@
1211
logger = logging.getLogger(__name__)
1312

1413

14+
def unwrap_if_constexpr(o):
15+
return o.value if isinstance(o, tl.constexpr) else o
16+
17+
1518
@tl.constexpr
1619
def get_int_t(num_bits: tl.constexpr, signed: tl.constexpr) -> tl.dtype:
17-
num_bits = _unwrap_if_constexpr(num_bits)
18-
signed = _unwrap_if_constexpr(signed)
20+
num_bits = unwrap_if_constexpr(num_bits)
21+
signed = unwrap_if_constexpr(signed)
1922
return tl.core.get_int_dtype(num_bits, signed)
2023

2124

2225
@tl.constexpr
2326
def one_zeros(num_bits: tl.constexpr) -> int:
24-
num_bits = _unwrap_if_constexpr(num_bits)
27+
num_bits = unwrap_if_constexpr(num_bits)
2528
return 1 << (num_bits - 1)
2629

2730

2831
@tl.constexpr
2932
def zero_ones(num_bits: tl.constexpr) -> int:
30-
num_bits = _unwrap_if_constexpr(num_bits)
33+
num_bits = unwrap_if_constexpr(num_bits)
3134
return (1 << (num_bits - 1)) - 1
3235

3336

0 commit comments

Comments
 (0)