| 340 | |
| 341 | |
| 342 | def runOpBenchmark( |
| 343 | device_option, |
| 344 | op, |
| 345 | inputs, |
| 346 | input_device_options=None, |
| 347 | iterations=10, |
| 348 | ): |
| 349 | op = copy.deepcopy(op) |
| 350 | op.device_option.CopyFrom(device_option) |
| 351 | net = caffe2_pb2.NetDef() |
| 352 | net.op.extend([op]) |
| 353 | net.name = op.name if op.name else "test" |
| 354 | |
| 355 | with temp_workspace(): |
| 356 | _input_device_options = input_device_options or \ |
| 357 | core.InferOpBlobDevicesAsDict(op)[0] |
| 358 | for (n, b) in zip(op.input, inputs): |
| 359 | workspace.FeedBlob( |
| 360 | n, |
| 361 | b, |
| 362 | device_option=_input_device_options.get(n, device_option) |
| 363 | ) |
| 364 | workspace.CreateNet(net) |
| 365 | ret = workspace.BenchmarkNet(net.name, 1, iterations, True) |
| 366 | return ret |
| 367 | |
| 368 | |
| 369 | def runOpOnInput( |