Skip to content

Commit

Permalink
Implemented final two binary ops, added default params for functional…
Browse files Browse the repository at this point in the history
…ity (apache#17407)

* Implemented final two binary ops, added default params for functionality

* Removed extraneous param checks

* Added support for ElementWiseSum

* Moved ElementWiseSum to binary_element_wise_operators
  • Loading branch information
connorgoggins authored and Ubuntu committed Feb 19, 2020
1 parent 8ac452c commit 0af9e71
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
29 changes: 28 additions & 1 deletion benchmark/opperf/nd_operations/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,34 @@

from benchmark.opperf.utils.benchmark_utils import run_op_benchmarks
from benchmark.opperf.utils.op_registry_utils import get_all_broadcast_binary_operators, \
get_all_elemen_wise_binary_operators
get_all_elemen_wise_binary_operators, get_all_misc_binary_operators


def run_mx_binary_misc_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100):
"""Runs benchmarks with the given context and precision (dtype) for all the miscellaneous
binary operators in MXNet.
Parameters
----------
ctx: mx.ctx
Context to run benchmarks
dtype: str, default 'float32'
Precision to use for benchmarks
warmup: int, default 25
Number of times to run for warmup
runs: int, default 100
Number of runs to capture benchmark results
Returns
-------
Dictionary of results. Key -> Name of the operator, Value -> Benchmark results.
"""
# Fetch all Miscellaneous Binary Operators
mx_binary_misc_ops = get_all_misc_binary_operators()
# Run benchmarks
mx_binary_op_results = run_op_benchmarks(mx_binary_misc_ops, dtype, ctx, profiler, warmup, runs)
return mx_binary_op_results


def run_mx_binary_broadcast_operators_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='native', warmup=25, runs=100):
Expand Down
7 changes: 5 additions & 2 deletions benchmark/opperf/opperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from benchmark.opperf.nd_operations.unary_operators import run_mx_unary_operators_benchmarks
from benchmark.opperf.nd_operations.binary_operators import run_mx_binary_broadcast_operators_benchmarks, \
run_mx_binary_element_wise_operators_benchmarks
run_mx_binary_element_wise_operators_benchmarks, run_mx_binary_misc_operators_benchmarks
from benchmark.opperf.nd_operations.gemm_operators import run_gemm_operators_benchmarks
from benchmark.opperf.nd_operations.random_sampling_operators import run_mx_random_sampling_operators_benchmarks
from benchmark.opperf.nd_operations.reduction_operators import run_mx_reduction_operators_benchmarks
Expand Down Expand Up @@ -63,12 +63,15 @@ def run_all_mxnet_operator_benchmarks(ctx=mx.cpu(), dtype='float32', profiler='n
# Run all Unary operations benchmarks with default input values
mxnet_operator_benchmark_results.append(run_mx_unary_operators_benchmarks(ctx=ctx, dtype=dtype, profiler=profiler))

# Run all Binary Broadcast, element_wise operations benchmarks with default input values
# Run all Binary Broadcast, element_wise, and miscellaneous operations benchmarks with default input values
mxnet_operator_benchmark_results.append(run_mx_binary_broadcast_operators_benchmarks(ctx=ctx,
dtype=dtype, profiler=profiler))
mxnet_operator_benchmark_results.append(run_mx_binary_element_wise_operators_benchmarks(ctx=ctx,
dtype=dtype, profiler=profiler))

mxnet_operator_benchmark_results.append(run_mx_binary_misc_operators_benchmarks(ctx=ctx,
dtype=dtype, profiler=profiler))

# Run all GEMM operations benchmarks with default input values
mxnet_operator_benchmark_results.append(run_gemm_operators_benchmarks(ctx=ctx,
dtype=dtype, profiler=profiler))
Expand Down
8 changes: 7 additions & 1 deletion benchmark/opperf/rules/default_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
# For Unary operators like abs, arccos, arcsin etc..
DEFAULT_DATA = [(1024, 1024), (10000, 1), (10000, 100)]

# For Binary miscellaneous operators like choose_element0_index
# argument data must be indexed via an NDArray.
# NOTE: Data used is DEFAULT_DATA
DEFAULT_INDEX = [(1, 1024), (1, 1), (1, 100)]

# For Binary broadcast operators like - broadcast_add/sub/mod/logical_and etc..
DEFAULT_LHS = [(1024, 1024), (10000, 10), (10000, 1)]
DEFAULT_RHS = [(1024, 1024), (10000, 10), (10000, 1)]
Expand Down Expand Up @@ -188,7 +193,8 @@
"data_smce": DEFAULT_DATA_SMCE,
"data_3d": DEFAULT_DATA_3d,
"label_smce": DEFAULT_LABEL_SMCE,
"label": DEFAULT_LABEL}
"label": DEFAULT_LABEL,
"index": DEFAULT_INDEX}


# These are names of MXNet operator parameters that is of type NDArray.
Expand Down
22 changes: 22 additions & 0 deletions benchmark/opperf/utils/op_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ def get_all_broadcast_binary_operators():
return binary_broadcast_mx_operators


def get_all_misc_binary_operators():
"""Gets all miscellaneous binary operators registered with MXNet.
Returns
-------
{"operator_name": {"has_backward", "nd_op_handle", "params"}}
"""
# Get all mxnet operators
mx_operators = _get_all_mxnet_operators()

# Filter for miscellaneous binary operators
binary_misc_mx_operators = {}
for op_name, op_params in mx_operators.items():
if "choose_element_0index" == op_name:
binary_misc_mx_operators[op_name] = mx_operators[op_name]
elif "reshape_like" == op_name:
binary_misc_mx_operators[op_name] = mx_operators[op_name]
return binary_misc_mx_operators


def get_all_elemen_wise_binary_operators():
"""Gets all binary elemen_wise operators registered with MXNet.
Expand All @@ -222,6 +242,8 @@ def get_all_elemen_wise_binary_operators():
"lhs" in op_params["params"]["arg_names"] and \
"rhs" in op_params["params"]["arg_names"]:
binary_elemen_wise_mx_operators[op_name] = mx_operators[op_name]
elif "ElementWiseSum" == op_name:
binary_elemen_wise_mx_operators[op_name] = mx_operators[op_name]
return binary_elemen_wise_mx_operators


Expand Down

0 comments on commit 0af9e71

Please sign in to comment.