Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[OpPerf] Take care of 4d param #15736

Merged
merged 14 commits into from
Aug 19, 2019
5 changes: 3 additions & 2 deletions benchmark/opperf/rules/default_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@
# Hence below we append 4d to mark the difference.
# For depth_to_space, dimension 3 needs to be a multiple of 'block' and 1 should be a multiple of `block^2`
DEFAULT_DATA_4d = [(1, 4, 2, 4), (10,25,10,100)]
DEFAULT_DIM_1 = [0, 1, 2, 3]
DEFAULT_DIM_2 = [1, 2, 3, 0]
DEFAULT_BLOCK_SIZE = [2, 5]

# For swapaxis operator
DEFAULT_DIM_1 = [0]
DEFAULT_DIM_2 = [1]

# Default Inputs. MXNet Op Param Name to Default Input mapping
DEFAULTS_INPUTS = {"data": DEFAULT_DATA,
Expand Down
4 changes: 2 additions & 2 deletions benchmark/opperf/utils/benchmark_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def run_performance_test(ops, inputs, run_backward=True,
def run_op_benchmarks(ops, dtype, ctx, warmup, runs):
# For each operator, run benchmarks
mx_op_benchmark_results = []
for _, op_params in ops.items():
for op, op_params in ops.items():
# Prepare inputs for the operator
inputs = prepare_op_inputs(op_params)
inputs = prepare_op_inputs(op, op_params)
# Run benchmarks
cur_op_res = run_performance_test(op_params["nd_op_handle"],
run_backward=op_params["has_backward"],
Expand Down
7 changes: 5 additions & 2 deletions benchmark/opperf/utils/op_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,19 @@ def prepare_op_inputs(arg_params, arg_values):
return inputs


def prepare_op_inputs(arg_params):
def prepare_op_inputs(op, arg_params):
inputs = []

# 4d tensor is needed only by following two ops
ops_4d = ['depth_to_space','space_to_depth']

# Prepare op to default input mapping
arg_values = {}
for arg_name, arg_type in zip(arg_params["params"]["arg_names"],
arg_params["params"]["arg_types"]):
if "NDArray" in arg_type and arg_name + "_nd" in DEFAULTS_INPUTS:
arg_values[arg_name] = DEFAULTS_INPUTS[arg_name + "_nd"]
elif "NDArray" in arg_type and arg_name + "_4d" in DEFAULTS_INPUTS:
elif "NDArray" in arg_type and op in ops_4d and arg_name + "_4d" in DEFAULTS_INPUTS:
arg_values[arg_name] = DEFAULTS_INPUTS[arg_name + "_4d"]
elif arg_name in DEFAULTS_INPUTS:
arg_values[arg_name] = DEFAULTS_INPUTS[arg_name]
Expand Down