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

[Opperf] Add array rearrange operators to opperf #15606

Merged
merged 5 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions benchmark/opperf/nd_operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@
46. linalg_extractdiag
47. sgd_mom_update
48. SequenceLast
50. flip
51. SequenceReverse
52. swapaxes
53. SVMOutput
54. linalg_trsm
55. where
Expand All @@ -82,7 +80,6 @@
63. mp_sgd_mom_update
64. choose_element_0index
65. tile
66. space_to_depth
67. gather_nd
69. SequenceMask
70. reshape_like
Expand Down Expand Up @@ -110,14 +107,12 @@
94. broadcast_like
95. Embedding
96. linalg_makediag
97. transpose
98. linalg_syrk
99. squeeze
101. ROIPooling
102. ftrl_update
103. SliceChannel
104. slice_like
105. depth_to_space
106. linalg_maketrian
108. pad
109. LayerNorm
Expand Down
57 changes: 57 additions & 0 deletions benchmark/opperf/nd_operations/array_rearrange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import mxnet as mx
from benchmark.opperf.utils.benchmark_utils import run_op_benchmarks
from benchmark.opperf.utils.op_registry_utils import get_all_rearrange_operators

"""Performance benchmark tests for MXNet NDArray Rearrange Operators.

1. transpose
2. swapaxes
3. flip
4. depth_to_space
5. space_to_depth
"""


def run_rearrange_operators_benchmarks(ctx=mx.cpu(), dtype='float32', warmup=25, runs=100):
"""Runs benchmarks with the given context and precision (dtype) for all the
rearrange 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 optimizer operators
mx_rearrange_ops = get_all_rearrange_operators()

# Run benchmarks
mx_rearrange_op_results = run_op_benchmarks(mx_rearrange_ops, dtype, ctx, warmup, runs)
return mx_rearrange_op_results
4 changes: 2 additions & 2 deletions benchmark/opperf/nd_operations/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


def run_mx_binary_broadcast_operators_benchmarks(ctx=mx.cpu(), dtype='float32', warmup=25, runs=100):
"""Runs benchmarks with the given context and precision (dtype)for all the binary
"""Runs benchmarks with the given context and precision (dtype) for all the binary
broadcast operators in MXNet.

Parameters
Expand All @@ -66,7 +66,7 @@ def run_mx_binary_broadcast_operators_benchmarks(ctx=mx.cpu(), dtype='float32',


def run_mx_binary_element_wise_operators_benchmarks(ctx=mx.cpu(), dtype='float32', warmup=25, runs=100):
"""Runs benchmarks with the given context and precision (dtype)for all the binary
"""Runs benchmarks with the given context and precision (dtype) for all the binary
element_wise operators in MXNet.

Parameters
Expand Down
4 changes: 4 additions & 0 deletions benchmark/opperf/opperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from benchmark.opperf.nd_operations.nn_conv_operators import run_pooling_operators_benchmarks, \
run_convolution_operators_benchmarks, run_transpose_convolution_operators_benchmarks
from benchmark.opperf.nd_operations.nn_basic_operators import run_nn_basic_operators_benchmarks
from benchmark.opperf.nd_operations.array_rearrange import run_rearrange_operators_benchmarks

from benchmark.opperf.utils.common_utils import merge_map_list, save_to_file
from benchmark.opperf.utils.op_registry_utils import get_operators_with_no_benchmark, \
Expand Down Expand Up @@ -78,6 +79,9 @@ def run_all_mxnet_operator_benchmarks(ctx=mx.cpu(), dtype='float32'):
# Run all Sorting and Searching operations benchmarks with default input values
mxnet_operator_benchmark_results.append(run_sorting_searching_operators_benchmarks(ctx=ctx, dtype=dtype))

# Run all Array Rearrange operations benchmarks with default input values
mxnet_operator_benchmark_results.append(run_rearrange_operators_benchmarks(ctx=ctx, dtype=dtype))

# ************************ MXNET NN OPERATOR BENCHMARKS ****************************

# Run all basic NN operations benchmarks with default input values
Expand Down
10 changes: 9 additions & 1 deletion benchmark/opperf/rules/default_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
# NOTE: Data used is DEFAULT_DATA
DEFAULT_AXIS = [0]

# For rearrange operators
sandeep-krishnamurthy marked this conversation as resolved.
Show resolved Hide resolved
DEFAULT_DIM_1 = [[0, 1, 5]]
DEFAULT_DIM_2 = [[0, 1, 5]]
DEFAULT_BLOCK_SIZE = [[1, 2, 5]]

# Default Inputs. MXNet Op Param Name to Default Input mapping
DEFAULTS_INPUTS = {"data": DEFAULT_DATA,
"lhs": DEFAULT_LHS,
Expand All @@ -81,7 +86,10 @@
"k_nd": DEFAULT_K_ND,
"p_nd": DEFAULT_P_ND,
"axis_shape": DEFAULT_AXIS_SHAPE,
"axis": DEFAULT_AXIS}
"axis": DEFAULT_AXIS,
"dim1": DEFAULT_DIM_1,
"dim2": DEFAULT_DIM_2,
"block_size": DEFAULT_BLOCK_SIZE}

# These are names of MXNet operator parameters that is of type NDArray.
# We maintain this list to automatically recognize these parameters are to be
Expand Down
20 changes: 20 additions & 0 deletions benchmark/opperf/utils/op_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,26 @@ def get_all_sorting_searching_operators():
return sort_search_mx_operators


def get_all_rearrange_operators():
"""Gets all array rearrange operators registered with MXNet.

Returns
-------
{"operator_name": {"has_backward", "nd_op_handle", "params"}}
"""
rearrange_ops = ['transpose','swapaxes','flip','depth_to_space','space_to_depth']
ChaiBapchya marked this conversation as resolved.
Show resolved Hide resolved

# Get all mxnet operators
mx_operators = _get_all_mxnet_operators()

# Filter for Array Rearrange operators
rearrange_mx_operators = {}
for op_name, op_params in mx_operators.items():
if op_name in rearrange_ops and op_name not in unique_ops:
rearrange_mx_operators[op_name] = mx_operators[op_name]
return rearrange_mx_operators


def get_operators_with_no_benchmark(operators_with_benchmark):
"""Gets all MXNet operators with not benchmark.

Expand Down