singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] chrishkchris commented on a change in pull request #728: Fix create_cuda_gpu
Date Wed, 10 Jun 2020 14:29:31 GMT

chrishkchris commented on a change in pull request #728:
URL: https://github.com/apache/singa/pull/728#discussion_r438166926



##########
File path: python/singa/device.py
##########
@@ -106,17 +106,21 @@ def create_cuda_gpus(num):
     return singa.Platform.CreateCudaGPUs(num)
 
 
-def create_cuda_gpu(set_default=False):
+Device.default_gpu_device = None

Review comment:
       When I change from `Device.default_gpu_device` to `default_gpu_device`
   
   ```
   default_gpu_device = None
   
   
   def create_cuda_gpu():
       '''Create a single CudaGPU device.
   
       Returns:
           a swig converted CudaGPU device.
       '''
       assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
   
       if default_gpu_device is None:
           default_gpu_device = create_cuda_gpu_on(0)
   
       return default_gpu_device
   ```
   
   When I run the script `simple_test_device.py` to create device
   
   ```
   from singa import device
   
   if __name__ == '__main__':
       dev=device.create_cuda_gpu()
   ```
   
   It returns:
   ```
   root@d05828f767ee:~/dcsysh/singa/examples/cnn# python3 simple_test_device.py
   Traceback (most recent call last):
     File "test_device.py", line 4, in <module>
       dev=device.create_cuda_gpu()
     File "/root/dcsysh/singa/build/python/singa/device.py", line 120, in create_cuda_gpu
       if default_gpu_device is None:
   UnboundLocalError: local variable 'default_gpu_device' referenced before assignment
   ```
   
   Seems if I don't store the variable `default_gpu_device` in a class, the variable `default_gpu_device`
is lost




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



Mime
View raw message