Skip to content

Commit acc295c

Browse files
authored
Split benchmark suite for generic pointwise operators (#2683)
1 parent 68e1059 commit acc295c

12 files changed

Lines changed: 299 additions & 219 deletions

benchmark/test_addcdiv.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
import torch
3+
4+
from . import attri_util as attrs
5+
from . import performance_utils as base
6+
7+
8+
def _input_fn(shape, cur_dtype, device):
9+
inp1 = base.generate_tensor_input(shape, cur_dtype, device)
10+
inp2 = base.generate_tensor_input(shape, cur_dtype, device)
11+
inp3 = base.generate_tensor_input(shape, cur_dtype, device)
12+
13+
yield inp1, inp2, inp3, {"value": 0.5}
14+
15+
16+
@pytest.mark.addcdiv
17+
def test_addcdiv():
18+
bench = base.GenericBenchmark(
19+
op_name="addcdiv",
20+
input_fn=_input_fn,
21+
torch_op=torch.addcdiv,
22+
dtypes=attrs.FLOAT_DTYPES,
23+
)
24+
bench.run()

benchmark/test_addcmul.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
import torch
3+
4+
from . import attri_util as attrs
5+
from . import performance_utils as base
6+
7+
8+
def _input_fn(shape, cur_dtype, device):
9+
inp1 = base.generate_tensor_input(shape, cur_dtype, device)
10+
inp2 = base.generate_tensor_input(shape, cur_dtype, device)
11+
inp3 = base.generate_tensor_input(shape, cur_dtype, device)
12+
13+
yield inp1, inp2, inp3, {"value": 0.5}
14+
15+
16+
@pytest.mark.addcmul
17+
def test_addcmul():
18+
bench = base.GenericBenchmark(
19+
op_name="addcmul",
20+
input_fn=_input_fn,
21+
torch_op=torch.addcmul,
22+
dtypes=attrs.FLOAT_DTYPES,
23+
)
24+
bench.run()

benchmark/test_clamp.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
import torch
3+
4+
from . import attri_util as attrs
5+
from . import performance_utils as base
6+
7+
8+
def _input_fn(shape, cur_dtype, device):
9+
inp1 = base.generate_tensor_input(shape, cur_dtype, device)
10+
inp2 = base.generate_tensor_input(shape, cur_dtype, device)
11+
inp3 = base.generate_tensor_input(shape, cur_dtype, device)
12+
13+
yield inp1, inp2, inp3
14+
15+
if base.Config.bench_level == base.BenchLevel.COMPREHENSIVE:
16+
# scalar or None situation
17+
yield inp1, inp2, None
18+
yield inp1, None, 3.14
19+
20+
21+
@pytest.mark.clamp
22+
def test_clamp():
23+
bench = base.GenericBenchmark(
24+
op_name="clamp",
25+
input_fn=_input_fn,
26+
torch_op=torch.clamp,
27+
dtypes=attrs.FLOAT_DTYPES,
28+
)
29+
bench.run()
30+
31+
32+
@pytest.mark.clamp_
33+
def test_clamp_inplace():
34+
bench = base.GenericBenchmark(
35+
input_fn=_input_fn,
36+
op_name="clamp_",
37+
torch_op=torch.clamp_,
38+
dtypes=attrs.FLOAT_DTYPES,
39+
is_inplace=True,
40+
)
41+
bench.run()

benchmark/test_clamp_min.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
import torch
3+
4+
from . import attri_util as attrs
5+
from . import performance_utils as base
6+
7+
8+
def _input_fn(shape, cur_dtype, device):
9+
inp1 = base.generate_tensor_input(shape, cur_dtype, device)
10+
inp2 = base.generate_tensor_input(shape, cur_dtype, device)
11+
12+
yield inp1, inp2
13+
14+
if base.Config.bench_level == attrs.BenchLevel.COMPREHENSIVE:
15+
# scalar situation
16+
yield inp1, 3.14
17+
18+
19+
@pytest.mark.clamp_min
20+
def test_clamp_min():
21+
bench = base.GenericBenchmark(
22+
op_name="clamp_min",
23+
input_fn=_input_fn,
24+
torch_op=torch.clamp_min,
25+
dtypes=attrs.FLOAT_DTYPES,
26+
)
27+
bench.run()
28+
29+
30+
@pytest.mark.clamp_min_
31+
def test_clamp_min_inplace():
32+
bench = base.GenericBenchmark(
33+
input_fn=_input_fn,
34+
op_name="clamp_min_",
35+
torch_op=torch.clamp_min_,
36+
dtypes=attrs.FLOAT_DTYPES,
37+
is_inplace=True,
38+
)
39+
bench.run()

benchmark/test_flip.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
import torch
3+
4+
from . import attri_util as attrs
5+
from . import performance_utils as base
6+
7+
8+
def _input_fn(shape, cur_dtype, device):
9+
inp = base.generate_tensor_input(shape, cur_dtype, device)
10+
if len(shape) > 1:
11+
yield inp, {"dims": (0, 1)}
12+
else:
13+
yield inp, {"dims": (0,)}
14+
15+
16+
@pytest.mark.flip
17+
def test_flip():
18+
bench = base.GenericBenchmark(
19+
op_name="flip",
20+
input_fn=_input_fn,
21+
torch_op=torch.flip,
22+
dtypes=attrs.FLOAT_DTYPES + attrs.INT_DTYPES,
23+
)
24+
bench.run()

benchmark/test_generic_pointwise_perf.py

Lines changed: 0 additions & 219 deletions
This file was deleted.

0 commit comments

Comments
 (0)