piiswrong commented on a change in pull request #10536: [MXNET-317] Add Data 
Parallel
URL: https://github.com/apache/incubator-mxnet/pull/10536#discussion_r189053366
 
 

 ##########
 File path: python/mxnet/gluon/contrib/parallel.py
 ##########
 @@ -0,0 +1,343 @@
+# 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.
+
+# pylint: disable=broad-except, redefined-builtin
+"""Synchronized DataParallel"""
+import threading
+from ... import autograd
+from ...ndarray import NDArray
+from ..utils import split_and_load
+
+__all__ = ['DataParallelModel', 'DataParallelCriterion', 'Barrier']
+
+
+class Barrier(object):
+    """Shared NDArray for cross device operation.
+
+    A cross device operation that allows synchronized push and pull. It can be 
used in
+    Cross-gpu Sycnhronized Batch Normalization and Sparse Blocks.
+
+    Parameters
+    ----------
+    counter : int
+        Number of deivces.
+    operation : callable
+        The cross device operation is applying (e.g. AllReduce).
+    """
+    def __init__(self, counter, operation):
+        self.mutex = threading.Lock()
+        self.all_tasks_done = threading.Condition(self.mutex)
+        self.counter = counter
+        self.op = operation
+        self._clear()
+
+    def push(self, x):
+        """Push a NDArray from one of the device.
+        Input:
+            x (NDArray)
+
+        Output:
+            idx (int), the output index
+        """
+        with self.mutex:
+            if self.push_tasks == 0:
+                self._clear()
+            self.list.append(x)
+            idx = len(self.list) - 1
+            self.push_tasks -= 1
+
+        with self.all_tasks_done:
+            if self.push_tasks == 0:
+                self.all_tasks_done.notify_all()
+            while self.push_tasks:
 
 Review comment:
   why busy wait here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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