forked from ROCm/aiter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_aiter_sigmoid.py
More file actions
77 lines (66 loc) · 2.21 KB
/
Copy pathtest_aiter_sigmoid.py
File metadata and controls
77 lines (66 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# SPDX-License-Identifier: MIT
# Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved.
import torch
import aiter
from aiter import dtypes
from aiter.test_common import checkAllclose
import argparse
# from ater.test_common import checkAllclose, perftest
from torch.profiler import profile, ProfilerActivity
# input shape: torch.Size([4096, 64, 160]) (20480, 1, 128)
# other shape: torch.Size([4096, 64, 160]) (10240, 160, 1)
# input shape: torch.Size([4096, 64, 160]) (47360, 1, 296)
# other shape: torch.Size([4096, 64, 160]) (10240, 160, 1)
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
description="config input of test",
)
parser.add_argument(
"-s",
"--shape",
type=dtypes.str2tuple,
default=(4096, 880),
help="""Input shape.
e.g.: -s 4096,880""",
)
parser.add_argument(
"-st",
"--stride",
type=dtypes.str2tuple,
default=(880, 1),
help="""Input stride.
e.g.: -st 880,1""",
)
args = parser.parse_args()
tensor0 = torch.empty_strided(args.shape, args.stride, dtype=dtypes.fp16, device="cuda")
random_data0 = torch.rand(args.shape)
tensor0.copy_(random_data0)
# tensor0.fill_(1)
print("Shape", args.shape)
print("Stride:", args.stride)
with profile(
activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
profile_memory=True,
with_stack=True,
with_modules=True,
record_shapes=True,
) as prof:
for j in range(100):
# cache_flush1 = torch.randn(10000, 10000, requires_grad=True, device="cuda", dtype=dtypes.fp32).to(dtypes.i32)
result = torch.sigmoid(tensor0)
print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10))
with profile(
activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
profile_memory=True,
with_stack=True,
with_modules=True,
record_shapes=True,
) as prof:
for j in range(100):
# cache_flush1 = torch.randn(10000, 10000, requires_grad=True, device="cuda", dtype=dtypes.fp32).to(dtypes.i32)
output = aiter.sigmoid(tensor0)
print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10))
print(torch.equal(result, output))
checkAllclose(result, output, msg="sigmoid")
print("result:", result)
print("output:", output)