You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/11 03:39:07 UTC

[GitHub] piiswrong closed pull request #11182: fix propagation of cpu shared context, issue #11160

piiswrong closed pull request #11182: fix propagation of cpu shared context, issue #11160
URL: https://github.com/apache/incubator-mxnet/pull/11182
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/imperative/imperative_utils.h b/src/imperative/imperative_utils.h
index 8e99b995a14..726531d0299 100644
--- a/src/imperative/imperative_utils.h
+++ b/src/imperative/imperative_utils.h
@@ -82,7 +82,7 @@ inline Context GetContext(const nnvm::NodeAttrs& attrs,
     ctx = default_ctx;
   }
   // Non-default context (pinned, shared) does not propagate
-  if (ctx.dev_mask() != ctx.dev_type) {
+  if (ctx.dev_mask() != ctx.dev_type && inputs.size() != 0U) {
     ctx = Context::Create(ctx.dev_mask(), ctx.dev_id);
   }
 #if !MXNET_USE_CUDA
diff --git a/tests/python/unittest/test_ndarray.py b/tests/python/unittest/test_ndarray.py
index a0604658ee1..92cdb2ced9d 100644
--- a/tests/python/unittest/test_ndarray.py
+++ b/tests/python/unittest/test_ndarray.py
@@ -1304,6 +1304,13 @@ def test_norm(ctx=default_context()):
             assert arr1.shape == arr2.shape
             mx.test_utils.assert_almost_equal(arr1, arr2.asnumpy())
 
+@with_seed()
+def test_ndarray_cpu_shared_ctx():
+    ctx = mx.Context('cpu_shared', 0)
+    res = mx.nd.zeros((1, 2, 3), ctx=ctx)
+    assert(res.context == ctx)
+
+
 if __name__ == '__main__':
     import nose
     nose.runmodule()


 

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


With regards,
Apache Git Services