Skip to content

Commit

Permalink
migrate add operator to the new interface (#21152)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch/pytorch#21152

Migrate existing add benchmark to use the new op front-end

Reviewed By: zheng-xq

Differential Revision: D15325524

fbshipit-source-id: 34e969e1bd289913d881c476711bce9f8ac18a29
  • Loading branch information
mingzhe09088 authored and facebook-github-bot committed May 31, 2019
1 parent fd19d06 commit c62d476
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 60 deletions.
60 changes: 0 additions & 60 deletions benchmarks/operator_benchmark/ops/add_test.py

This file was deleted.

49 changes: 49 additions & 0 deletions benchmarks/operator_benchmark/ops/c2/add_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import operator_benchmark as op_bench
from caffe2.python import core


"""Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch."""

# Configs for C2 add operator
add_long_configs = op_bench.cross_product_configs(
M=[8, 64, 128],
N=range(2, 10, 3),
K=[2 ** x for x in range(0, 3)],
tags=["long"]
)


add_short_configs = op_bench.config_list(
attrs=[
[8, 16, 32],
[16, 16, 64],
[64, 64, 128],
],
attr_names=["M", "N", "K"],
tags=["short"],
)

class AddBenchmark(op_bench.Caffe2BenchmarkBase):
def init(self, M, N, K):
self.input_one = self.tensor(M, N, K)
self.input_two = self.tensor(M, N, K)
self.output = self.tensor(M, N, K)
self.set_module_name("add")

def forward(self):
op = core.CreateOperator(
"Add", [self.input_one, self.input_two], self.output, **self.args
)
return op


op_bench.generate_c2_test(add_long_configs + add_short_configs, AddBenchmark)


if __name__ == "__main__":
op_bench.benchmark_runner.main()
45 changes: 45 additions & 0 deletions benchmarks/operator_benchmark/ops/pt/add_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import operator_benchmark as op_bench
import torch

"""Microbenchmarks for element-wise Add operator. Supports both Caffe2/PyTorch."""

# Configs for PT add operator
add_long_configs = op_bench.cross_product_configs(
M=[8, 64, 128],
N=range(2, 10, 3),
K=[2 ** x for x in range(0, 3)],
tags=["long"]
)


add_short_configs = op_bench.config_list(
attrs=[
[8, 16, 32],
[16, 16, 64],
[64, 64, 128],
],
attr_names=["M", "N", "K"],
tags=["short"],
)


class AddBenchmark(op_bench.TorchBenchmarkBase):
def init(self, M, N, K):
self.input_one = torch.rand(M, N, K)
self.input_two = torch.rand(M, N, K)
self.set_module_name("add")

def forward(self):
return torch.add(self.input_one, self.input_two)


op_bench.generate_pt_test(add_long_configs + add_short_configs, AddBenchmark)


if __name__ == "__main__":
op_bench.benchmark_runner.main()

0 comments on commit c62d476

Please sign in to comment.