This is an automated email from the ASF dual-hosted git repository.

skm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new b00bb81  [Opperf] Add array rearrange operators to opperf (#15606)
b00bb81 is described below

commit b00bb81fd4346196d7e059e3b051d1c74ba6e572
Author: Chaitanya Prakash Bapat <[email protected]>
AuthorDate: Thu Jul 25 15:12:42 2019 -0700

    [Opperf] Add array rearrange operators to opperf (#15606)
    
    * add array rearrange operators to opperf
    
    * Trigger notification
    
    * 4d tensor, param support
    
    * new line
    
    * add alias logic
---
 benchmark/opperf/nd_operations/README.md           |  5 --
 benchmark/opperf/nd_operations/array_rearrange.py  | 57 ++++++++++++++++++++++
 benchmark/opperf/nd_operations/binary_operators.py |  4 +-
 benchmark/opperf/opperf.py                         |  4 ++
 benchmark/opperf/rules/default_params.py           | 15 +++++-
 benchmark/opperf/utils/op_registry_utils.py        | 22 +++++++++
 benchmark/opperf/utils/profiler_utils.py           | 20 ++++++--
 7 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/benchmark/opperf/nd_operations/README.md 
b/benchmark/opperf/nd_operations/README.md
index b98a0d3..321158c 100644
--- a/benchmark/opperf/nd_operations/README.md
+++ b/benchmark/opperf/nd_operations/README.md
@@ -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
@@ -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
@@ -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
diff --git a/benchmark/opperf/nd_operations/array_rearrange.py 
b/benchmark/opperf/nd_operations/array_rearrange.py
new file mode 100644
index 0000000..151127c
--- /dev/null
+++ b/benchmark/opperf/nd_operations/array_rearrange.py
@@ -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
diff --git a/benchmark/opperf/nd_operations/binary_operators.py 
b/benchmark/opperf/nd_operations/binary_operators.py
index cca8f9d..1898f5d 100644
--- a/benchmark/opperf/nd_operations/binary_operators.py
+++ b/benchmark/opperf/nd_operations/binary_operators.py
@@ -39,7 +39,7 @@ from benchmark.opperf.utils.op_registry_utils import 
get_all_broadcast_binary_op
 
 
 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
@@ -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
diff --git a/benchmark/opperf/opperf.py b/benchmark/opperf/opperf.py
index b2258af..77b1667 100755
--- a/benchmark/opperf/opperf.py
+++ b/benchmark/opperf/opperf.py
@@ -39,6 +39,7 @@ from benchmark.opperf.nd_operations.nn_activation_operators 
import run_activatio
 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, \
@@ -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
diff --git a/benchmark/opperf/rules/default_params.py 
b/benchmark/opperf/rules/default_params.py
index 2c8f3d4..b16cd54 100644
--- a/benchmark/opperf/rules/default_params.py
+++ b/benchmark/opperf/rules/default_params.py
@@ -62,6 +62,15 @@ DEFAULT_AXIS_SHAPE = [(), 0, (0, 1)]
 # NOTE: Data used is DEFAULT_DATA
 DEFAULT_AXIS = [0]
 
+# For rearrange operators
+# NOTE: Data needs to be a 4D tensor for  operators like space_to_depth and 
depth_to_space
+# 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]
+
 # Default Inputs. MXNet Op Param Name to Default Input mapping
 DEFAULTS_INPUTS = {"data": DEFAULT_DATA,
                    "lhs": DEFAULT_LHS,
@@ -81,7 +90,11 @@ DEFAULTS_INPUTS = {"data": DEFAULT_DATA,
                    "k_nd": DEFAULT_K_ND,
                    "p_nd": DEFAULT_P_ND,
                    "axis_shape": DEFAULT_AXIS_SHAPE,
-                   "axis": DEFAULT_AXIS}
+                   "axis": DEFAULT_AXIS,
+                   "data_4d": DEFAULT_DATA_4d,
+                   "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
diff --git a/benchmark/opperf/utils/op_registry_utils.py 
b/benchmark/opperf/utils/op_registry_utils.py
index 88ea7a1..f5e7506 100644
--- a/benchmark/opperf/utils/op_registry_utils.py
+++ b/benchmark/opperf/utils/op_registry_utils.py
@@ -115,6 +115,8 @@ def prepare_op_inputs(arg_params):
                                   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:
+            arg_values[arg_name] = DEFAULTS_INPUTS[arg_name + "_4d"]
         elif arg_name in DEFAULTS_INPUTS:
             arg_values[arg_name] = DEFAULTS_INPUTS[arg_name]
         elif "float" in arg_type and arg_name + "_float" in DEFAULTS_INPUTS:
@@ -262,6 +264,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']
+
+    # 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.
 
diff --git a/benchmark/opperf/utils/profiler_utils.py 
b/benchmark/opperf/utils/profiler_utils.py
index a434d3b..0df67a0 100644
--- a/benchmark/opperf/utils/profiler_utils.py
+++ b/benchmark/opperf/utils/profiler_utils.py
@@ -42,14 +42,28 @@ def _get_memory_profile(memory_profile_results):
 
 def _get_operator_profile(operator_name, operator_profile_results):
     operator_profile = {}
+
+    # alias map : dictionary of the form {"alias" : "registered_name"}
+    # allows to retrieve alias operator profile from the profiler results
+    # TODO handling - "identity" : "_copy"
+    alias_map = {"broadcast_plus" : "broadcast_add", "broadcast_minus" : 
"broadcast_sub", "flatten" : "Flatten", "max_axis" : "max",
+                 "swapaxes" : "SwapAxis", "flip" : "reverse", "reshape" : 
"Reshape", "crop" : "slice", "sum_axis" : "sum", "min_axis" : "min"}
+
+    op_name = None
+
+    if operator_name in alias_map:
+        op_name = alias_map[operator_name]
+    else:
+        op_name = operator_name
+
     for line in operator_profile_results:
-        if operator_name in line or operator_name[:3] + " " in line:
+        if op_name in line or op_name[:3] + " " in line:
             operation = line.split()[0]
             operation_avg_time = float(line.split()[-1])
             if "_backward" in operation:
-                operator_profile["avg_time" + operation] = operation_avg_time
+                operator_profile["avg_time_backward_" + operator_name] = 
operation_avg_time
             else:
-                operator_profile["avg_time_forward_" + operation] = 
operation_avg_time
+                operator_profile["avg_time_forward_" + operator_name] = 
operation_avg_time
 
     return operator_profile
 

Reply via email to