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 2017/01/23 10:01:57 UTC
[2/3] incubator-singa git commit: Enabled python API for Singa-OpenCL.
Enabled python API for Singa-OpenCL.
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/5d3da920
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/5d3da920
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/5d3da920
Branch: refs/heads/master
Commit: 5d3da920b4e03cccdb98129525afda5080e318d2
Parents: 6b70dfc
Author: Tan Li Boon <ta...@u.nus.edu>
Authored: Mon Jan 23 00:25:07 2017 +0800
Committer: root <wangwei>
Committed: Mon Jan 23 09:43:24 2017 +0000
----------------------------------------------------------------------
python/singa/device.py | 36 ++++++++++++++++++++++++++++--------
python/singa/layer.py | 6 +++---
2 files changed, 31 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5d3da920/python/singa/device.py
----------------------------------------------------------------------
diff --git a/python/singa/device.py b/python/singa/device.py
index f250f9e..1df4c84 100644
--- a/python/singa/device.py
+++ b/python/singa/device.py
@@ -52,22 +52,32 @@ class Device(object):
def get_num_gpus():
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.GetNumGPUs()
def get_gpu_ids():
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.GetGPUIDs()
def get_gpu_mem_size(id):
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.GetGPUMemSize(id)
+def get_num_opencl_platforms():
+ assert singa.USE_OPENCL, 'SINGA has not been compiled with OpenCL enabled.'
+ return singa.Platform.GetNumOpenclPlatforms()
+
+
+def get_num_opencl_devices():
+ assert singa.USE_OPENCL, 'SINGA has not been compiled with OpenCL enabled.'
+ return singa.Platform.GetNumOpenclDevices()
+
+
def device_query(id, verbose=False):
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.DeviceQuery(id, verbose)
@@ -79,7 +89,7 @@ def create_cuda_gpus(num):
Returns:
a list of swig converted CudaGPU devices.
'''
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.CreateCudaGPUs(num)
@@ -89,7 +99,7 @@ def create_cuda_gpu():
Returns:
a swig converted CudaGPU device.
'''
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.CreateCudaGPUs(1)[0]
@@ -102,7 +112,7 @@ def create_cuda_gpus_on(device_ids):
Returns:
a list of swig converted CudaGPU devices.
'''
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
return singa.Platform.CreateCudaGPUsOn(device_ids)
@@ -115,11 +125,21 @@ def create_cuda_gpu_on(device_id):
Returns:
a swig converted CudaGPU device.
'''
- assert singa.USE_CUDA, 'SINGA is not compiled with CDUA/GPU'
+ assert singa.USE_CUDA, 'SINGA has not been compiled with CUDA enabled.'
devices = create_cuda_gpus_on([device_id])
return devices[0]
+def create_opencl_device():
+ '''Create the default OpenCL device.
+
+ Returns:
+ a swig converted OpenCL device.
+ '''
+ assert singa.USE_OPENCL, 'SINGA has not been compiled with OpenCL enabled.'
+ return singa.Platform.GetDefaultDevice()
+
+
default_device = singa.Platform.GetDefaultDevice()
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/5d3da920/python/singa/layer.py
----------------------------------------------------------------------
diff --git a/python/singa/layer.py b/python/singa/layer.py
index 583126a..0bea2d2 100644
--- a/python/singa/layer.py
+++ b/python/singa/layer.py
@@ -138,7 +138,7 @@ class Layer(object):
'''
Create a singa layer based on caffe layer configuration.
'''
- _check_engine(engine, ['cudnn', 'singacpp', 'singacuda'])
+ _check_engine(engine, ['cudnn', 'singacpp', 'singacuda', 'singacl'])
if self.conf.type == 'InnerProduct' or self.conf.type == 14:
self.layer = _create_layer(engine, 'Dense')
else:
@@ -350,7 +350,7 @@ class Conv2D(Layer):
self.conf.param.extend([bspecs])
self.param_specs.append(bspecs)
- _check_engine(engine, ['cudnn', 'singacpp'])
+ _check_engine(engine, ['cudnn', 'singacpp', 'singacl'])
self.layer = _create_layer(engine, 'Convolution')
if input_sample_shape is not None:
self.setup(input_sample_shape)
@@ -407,7 +407,7 @@ class Pooling2D(Layer):
conf = self.conf.pooling_conf
conf = _set_kernel_stride_pad(conf, kernel, stride, border_mode, pad)
conf.pool = mode
- _check_engine(engine, ['cudnn', 'singacpp'])
+ _check_engine(engine, ['cudnn', 'singacpp', 'singacl'])
self.layer = _create_layer(engine, 'Pooling')
if input_sample_shape is not None:
self.setup(input_sample_shape)