sandeep-krishnamurthy commented on a change in pull request #14977: Add an 
utility for operator benchmarks
URL: https://github.com/apache/incubator-mxnet/pull/14977#discussion_r289976891
 
 

 ##########
 File path: benchmark/opperf/utils/op_registry_utils.py
 ##########
 @@ -0,0 +1,193 @@
+# 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.
+
+"""Utilities to interact with MXNet operator registry."""
+import ctypes
+import sys
+from mxnet.base import _LIB, check_call, py_str, OpHandle, c_str, mx_uint
+
+# We will use all operators inside NDArray Module
+mx_nd_module = sys.modules["mxnet.ndarray.op"]
+
+
+def _get_all_registered_ops(filters=("_backward", "_contrib", "_")):
+    """Get all registered MXNet operators.
+
+    By default, filter out all backward operators that starts with  
'_backward',
+    Contrib operators that starts with '_contrib' and internal operators that
+    starts with '_'.
+
+    Parameters
+    ----------
+    filters: tuple(str)
+        List of operator name prefix to ignore from benchmarking.
+        Default - ("_backward", "_contrib", "_")
+
+    Returns
+    -------
+    {"operator_name": {"has_backward", "nd_op_handle"}}
+    """
+    plist = ctypes.POINTER(ctypes.c_char_p)()
+    size = ctypes.c_uint()
+
+    check_call(_LIB.MXListAllOpNames(ctypes.byref(size),
+                                     ctypes.byref(plist)))
+    mx_operators = {}
+    operators_with_backward = []
+
+    # Prepare master list of all operators.
+    for i in range(size.value):
 
 Review comment:
   1. This logic is very specific to this utility so C API at this time may not 
be necessary. Also, we have C APIs to get list of operator names, then a C API 
to get by operator name the details of the operator params etc. so that should 
helps majority of users.
   2. Refactored the helper code to split the responsibility. Thanks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to