[PYTHON] Now providing triton.next_power_of_2 (#273)

This commit is contained in:
Philippe Tillet
2021-09-10 11:05:44 -07:00
committed by GitHub
parent 43723ccb95
commit ac10551d55
2 changed files with 11 additions and 15 deletions

View File

@@ -833,6 +833,16 @@ def jit(fn):
def cdiv(x, y):
return (x + y - 1) // y
def next_power_of_2(n):
"""Return the smallest power of 2 greater than or equal to n"""
n -= 1
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n += 1
return n
######