18 from __future__
import absolute_import
19 from __future__
import division
20 from __future__
import print_function
21 from __future__
import unicode_literals
28 from six
import add_metaclass
35 logger = logging.getLogger(os.path.basename(__file__))
36 logger.setLevel(logging.INFO)
42 def __new__(metacls, name, bases, class_dict):
43 cls = type.__new__(metacls, name, bases, class_dict)
44 if name !=
'Benchmark':
45 ALL_BENCHMARKS[name] = cls
49 @add_metaclass(BenchmarkMeta)
56 print(
'Results ({}):'.format(type(self).__name__))
57 print(
'input size ms/iter')
58 print(
'------------------------------ -----------')
60 print(
'{!s:<30} {:.4f}'.format(size, ms))
65 op = core.CreateOperator(
71 for n
in itertools.imap(pow, itertools.cycle([10]), range(10)):
72 X = np.random.rand(n).astype(np.float32)
73 logger.info(
'Running benchmark for n = {}'.format(n))
74 ret = runOpBenchmark(gpu_do, op, inputs=[X])
75 self.results.append((n, ret[1]))
80 op = core.CreateOperator(
86 for n
in itertools.imap(pow, itertools.cycle([10]), range(10)):
87 X = np.random.rand(n).astype(np.float32)
88 logger.info(
'Running benchmark for n = {}'.format(n))
89 ret = runOpBenchmark(gpu_do, op, inputs=[X])
90 self.results.append((n, ret[1]))
95 op = core.CreateOperator(
101 for n
in itertools.imap(pow, itertools.cycle([10]), range(8)):
102 for D
in itertools.imap(pow, itertools.cycle([10]), range(3)):
103 X = np.random.rand(n, D).astype(np.float32)
104 label = (np.random.rand(n) * D).astype(np.int32)
105 logger.info(
'Running benchmark for n = {}, D= {}'.format(n, D))
106 ret = runOpBenchmark(gpu_do, op, inputs=[X, label])
107 self.results.append(((n, D), ret[1]))
111 parser = argparse.ArgumentParser(os.path.basename(__file__))
112 parser.add_argument(
'-b',
'--benchmarks', nargs=
'+',
113 default=ALL_BENCHMARKS.keys(),
114 help=
'benchmarks to run (default: %(default)s))')
115 return parser.parse_args()
121 benchmarks = [ALL_BENCHMARKS[name]()
for name
in args.benchmarks]
122 for bench
in benchmarks:
124 for bench
in benchmarks:
128 if __name__ ==
'__main__':
129 workspace.GlobalInit([
'caffe2',
'--caffe2_log_level=2'])