reminisce commented on a change in pull request #17530: Add deferred compute 
support
URL: https://github.com/apache/incubator-mxnet/pull/17530#discussion_r378666617
 
 

 ##########
 File path: python/mxnet/_deferred_compute.py
 ##########
 @@ -0,0 +1,95 @@
+# 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.
+"""Deferred Compute for NDArray."""
+
+import ctypes
+import contextlib
+
+from .base import _LIB, check_call, SymbolHandle, _as_list
+from .symbol import Symbol
+
+__all__ = []
+
+def is_deferred_compute():
+    """Get status of deferred compute mode."""
+    curr = ctypes.c_bool()
+    check_call(_LIB.MXNDArrayIsDeferredComputeEnabled(ctypes.byref(curr)))
+    return curr.value
+
+def set_deferred_compute(is_deferred_compute):
+    """Enable / Disable deferred compute mode.
+
+    Parameters
+    ----------
+    is_deferred_compute: bool
+
+    Returns
+    -------
+    Previous deferred compute state.
+    """
+    prev = ctypes.c_int()
+    check_call(_LIB.MXNDArraySetDeferredComputeEnabled(
+        ctypes.c_int(is_deferred_compute), ctypes.byref(prev)))
+    return bool(prev.value)
+
+
[email protected]
+def context():
+    # Like other MXNet context manager, this bleeds state across concurrent
+    # code: "Context managers that have state should use Context Variables
+    # instead of threading.local() to prevent their state from bleeding to
+    # other code unexpectedly, when used in concurrent code."
+    val = set_deferred_compute(True)
+    yield
+    set_deferred_compute(val)
+
+
+def get_symbol(input_arrays, output_arrays, input_names=None):
 
 Review comment:
   Can we have a parameter taking in symbol class since we will need to support 
the symbols compatible with numpy ops.
   ```python
   def get_symbol(input_arrays, output_arrays, input_names=None, 
sym_cls=Symbol):
   ```

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