barry-jin commented on a change in pull request #19685:
URL: https://github.com/apache/incubator-mxnet/pull/19685#discussion_r558602478



##########
File path: python/mxnet/_ctypes/cached_op.py
##########
@@ -0,0 +1,159 @@
+# 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.
+
+# coding: utf-8
+# pylint: disable=invalid-name, protected-access, too-many-arguments
+# pylint: disable=global-statement, unused-import
+"""CachedOp API."""
+
+import ctypes
+
+from ..base import _LIB
+from ..base import c_str_array, c_handle_array
+from ..base import NDArrayHandle, CachedOpHandle, SymbolHandle
+from ..base import check_call
+from .. import _global_var
+from ..ndarray._internal import NDArrayBase
+from . import _api_internal
+
+def _monitor_callback_wrapper(callback):
+    """A wrapper for the user-defined handle."""
+    def callback_handle(name, opr_name, array, _):
+        """ ctypes function """
+        callback(name, opr_name, array)
+    return callback_handle
+
+class CachedOp(object):
+    """Cached operator handle."""
+    __slots__ = ["handle", "is_np_sym", "_monitor_callback"]
+
+    def __init__(self, sym, flags=(), thread_safe=False):
+        self._monitor_callback = None
+
+        from ..symbol.numpy._symbol import _Symbol
+        self.is_np_sym = bool(isinstance(sym, _Symbol))
+        
+        flags = {key: str(value) for key, value in flags}
+        self.handle = CachedOpHandle(_api_internal.create(
+            sym.handle,
+            len(flags),
+            flags,
+            thread_safe
+        ))
+
+    def __del__(self):
+        _api_internal.free(self.handle)
+
+    def get_optimized_symbol(self):
+        """Get an optimized version of the symbol from the cached op.
+
+        Returns
+        -------
+        symbol : Symbol
+            Optimized symbol from the executor.
+        """
+        from ..symbol import Symbol
+        sym_handle = 
SymbolHandle(_api_internal.get_optimized_symbol(self.handle))
+        ret = Symbol(sym_handle)
+        return ret
+
+    def __call__(self, *args, **kwargs):
+        """ctypes implementation of imperative invoke wrapper"""
+        # New FFI only supports numpy ndarray

Review comment:
       We don't need to remove legacy array currently. In this implementation, 
CachedOp can support both legacy array and numpy array. 




----------------------------------------------------------------
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]


Reply via email to