You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2019/07/22 04:58:19 UTC

[incubator-singa] branch master updated: used shared module to manage device creation to avoid singleton error

This is an automated email from the ASF dual-hosted git repository.

wangwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-singa.git


The following commit(s) were added to refs/heads/master by this push:
     new 91fcfb8  used shared module to manage device creation to avoid singleton error
     new b4d3ef9  Merge pull request #477 from dcslin/singleton-error
91fcfb8 is described below

commit 91fcfb8bec9860b5000d1af1925be75b03554e5d
Author: slin004 <13...@users.noreply.github.com>
AuthorDate: Fri Jul 19 16:11:38 2019 +0800

    used shared module to manage device creation to avoid singleton error
---
 test/python/cuda_helper.py    | 5 +++++
 test/python/test_operation.py | 6 ++----
 test/python/test_optimizer.py | 4 +---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/test/python/cuda_helper.py b/test/python/cuda_helper.py
new file mode 100644
index 0000000..516b9a3
--- /dev/null
+++ b/test/python/cuda_helper.py
@@ -0,0 +1,5 @@
+from singa import device
+
+# avoid singleton error
+gpu_dev = device.create_cuda_gpu()
+cpu_dev = device.get_default_device()
diff --git a/test/python/test_operation.py b/test/python/test_operation.py
index bec0373..d5aa0b4 100755
--- a/test/python/test_operation.py
+++ b/test/python/test_operation.py
@@ -20,18 +20,16 @@ from builtins import str
 
 from singa import tensor
 from singa import singa_wrap as singa
-from singa import device
 from singa import autograd
 
+from cuda_helper import gpu_dev, cpu_dev
+
 import numpy as np
 
 autograd.training = True
 
 CTensor = singa.Tensor
 
-gpu_dev = device.create_cuda_gpu()
-cpu_dev = device.get_default_device()
-
 dy = CTensor([2, 1, 2, 2])
 singa.Gaussian(0.0, 1.0, dy)
 
diff --git a/test/python/test_optimizer.py b/test/python/test_optimizer.py
index 84da11c..c2e478f 100644
--- a/test/python/test_optimizer.py
+++ b/test/python/test_optimizer.py
@@ -26,11 +26,9 @@ import numpy as np
 
 import singa.tensor as tensor
 import singa.optimizer as opt
-import singa.device as device
 from singa import singa_wrap
 
-if singa_wrap.USE_CUDA:
-    cuda = device.create_cuda_gpu()
+from cuda_helper import gpu_dev as cuda
 
 
 def np_adam(plist, glist, mlist, vlist, lr, t, b1=0.9, b2=0.999):