forked from snuspl/nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate add operator to the new interface (#21152)
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
1 parent
fd19d06
commit c62d476
Showing
3 changed files
with
94 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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() |
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,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() |