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

 ##########
 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:
   Does it make sense to expose this function in C API?
   
   If no, could we at least separate the concerns in two functions? Get the op 
names and then do the filtering by names? the logic would be clearer and easier 
to maintain and more testable than mixing all together. Ideally the op 
selection is a separate pure function that operates in this list of strings 
(and has no Ctypes dep)
   
   You can also have a third function that assembles the operator handles.
   
   I would simplify this line as:
   
   operator_names = [py_str(plist[i]) for i in range(size.value)]

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to