Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Operator] Add slice&select_scatter's benchmark #262

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions benchmark/test_reduction_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,68 @@ def gather_args(dtype, batch, size):
sizes=SIZES,
)
bench.run()


def test_slice_scatter_perf():
def slice_scatter_args(dtype, batch, size):
shape = [batch, size]
import random

dim = random.choice([0, 1])
start = 16
end = 1024
step = 2

inp = torch.randn(shape, dtype=dtype, device="cuda")

range = end - start
valid_shape = list(inp.shape)
if end < start:
range = 0
elif (end - start) > valid_shape[dim]:
range = valid_shape[dim]
start = 0
end = valid_shape[dim]

valid_shape[dim] = (range + (step - 1)) // step
src = torch.randn(valid_shape, dtype=dtype, device="cuda")
return (inp, src, dim, start, end, step)

bench = Benchmark(
op_name="slice_scatter",
torch_op=torch.slice_scatter,
arg_func=slice_scatter_args,
dtypes=FLOAT_DTYPES,
batch=REDUCTION_BATCH,
sizes=SIZES,
)
bench.run()


def test_select_scatter_perf():
def select_scatter_args(dtype, batch, size):
shape = [batch, size]
import random

dim = random.choice([0, 1])

import random

index = random.randint(0, shape[dim] - 1)
inp = torch.randn(shape, dtype=dtype, device="cuda")

src_shape = list(inp.shape)
del src_shape[dim]
src = torch.randn(src_shape, dtype=dtype, device="cuda")

return (inp, src, dim, index)

bench = Benchmark(
op_name="select_scatter",
torch_op=torch.select_scatter,
arg_func=select_scatter_args,
dtypes=FLOAT_DTYPES,
batch=REDUCTION_BATCH,
sizes=SIZES,
)
bench.run()