forked from triton-lang/triton
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute a scalar pointer for vector load instead of extracting it fro…
…m a tensor (#92) * Compute a scalar pointer for vector load instead of extracting it from a tensor. Signed-off-by: Ilya Enkovich <[email protected]> * Add lit test for scalar ptr usage. Signed-off-by: Ilya Enkovich <[email protected]> --------- Signed-off-by: Ilya Enkovich <[email protected]>
- Loading branch information
Showing
4 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import torch | ||
|
||
import triton | ||
import triton.language as tl | ||
|
||
|
||
def is_interpreter(): | ||
return os.environ.get('TRITON_INTERPRET', '0') == '1' | ||
|
||
|
||
def is_cpu(): | ||
return not is_interpreter() and \ | ||
triton.runtime.driver.active.get_current_target().backend == "cpu" | ||
|
||
|
||
def is_x86(): | ||
return is_cpu() and \ | ||
triton.runtime.driver.active.get_current_target().arch == "x86_64" | ||
|
||
|
||
def test_scalar_pointer_arith(device): | ||
|
||
@triton.jit | ||
def kernel(src, dst, BLOCK_SIZE: tl.constexpr): | ||
offs = tl.arange(0, BLOCK_SIZE) | ||
x = tl.load(src + offs) | ||
tl.store(dst + offs, x) | ||
|
||
src = torch.rand((128, ), dtype=torch.float32, device=device) | ||
res = torch.empty_like(src) | ||
meta = kernel[(1, )](src, res, BLOCK_SIZE=128) | ||
assert (src == res).all() | ||
|
||
# Check TTCIR doesn't have pointer extraction from a tensor. | ||
ttcir = meta.asm["ttcir"] | ||
assert ttcir.count("extract") == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters