提交 1337e971 authored 作者: Frederic's avatar Frederic

Add and fix docstring.

上级 41103b5d
...@@ -34,6 +34,9 @@ def as_cuda_array(obj): ...@@ -34,6 +34,9 @@ def as_cuda_array(obj):
raise TypeError("Don't know how to cast to a CudaNdarray object") raise TypeError("Don't know how to cast to a CudaNdarray object")
class HostFromGpu(Op): class HostFromGpu(Op):
"""
Implement the transfer from gpu to the cpu.
"""
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) return type(self) == type(other)
def __hash__(self): def __hash__(self):
...@@ -63,6 +66,9 @@ class HostFromGpu(Op): ...@@ -63,6 +66,9 @@ class HostFromGpu(Op):
host_from_gpu = HostFromGpu() host_from_gpu = HostFromGpu()
class GpuFromHost(Op): class GpuFromHost(Op):
"""
Implement the transfer from cpu to the gpu.
"""
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) return type(self) == type(other)
def __hash__(self): def __hash__(self):
...@@ -93,6 +99,9 @@ class GpuFromHost(Op): ...@@ -93,6 +99,9 @@ class GpuFromHost(Op):
gpu_from_host = GpuFromHost() gpu_from_host = GpuFromHost()
class GpuElemwise(Op): class GpuElemwise(Op):
"""
Implement a generic elemwise on the gpu.
"""
nin = property(lambda self: self.scalar_op.nin) nin = property(lambda self: self.scalar_op.nin)
nout = property(lambda self: self.scalar_op.nout) nout = property(lambda self: self.scalar_op.nout)
...@@ -200,6 +209,9 @@ class GpuElemwise(Op): ...@@ -200,6 +209,9 @@ class GpuElemwise(Op):
return self.src_generator.cache_version return self.src_generator.cache_version
class GpuDimShuffle(Op): class GpuDimShuffle(Op):
"""
Implement DimShuffle on the gpu.
"""
def __init__(self, input_broadcastable, new_order): def __init__(self, input_broadcastable, new_order):
input_broadcastable = tuple(input_broadcastable) input_broadcastable = tuple(input_broadcastable)
self.input_broadcastable = input_broadcastable self.input_broadcastable = input_broadcastable
...@@ -403,7 +415,7 @@ class GpuSum(Op): ...@@ -403,7 +415,7 @@ class GpuSum(Op):
- reduce_mask == (1,1,1) computes the sum of all elements in a 3-tensor. - reduce_mask == (1,1,1) computes the sum of all elements in a 3-tensor.
:note: any reduce_mask of all zeros is a sort of 'copy', and may be removed during graph :note: any reduce_mask of all zeros is a sort of 'copy', and may be removed during graph
optimization optimization
""" """
def __init__(self, reduce_mask): def __init__(self, reduce_mask):
...@@ -1706,6 +1718,9 @@ class GpuSum(Op): ...@@ -1706,6 +1718,9 @@ class GpuSum(Op):
return sio.getvalue() return sio.getvalue()
class GpuReshape(tensor.Reshape): class GpuReshape(tensor.Reshape):
"""
Implement Reshape on the gpu.
"""
# __hash__, __eq__, __str__ come from tensor.Subtensor # __hash__, __eq__, __str__ come from tensor.Subtensor
def make_node(self, x, shp): def make_node(self, x, shp):
host_reshaped = host_from_gpu(x).reshape(shp,ndim=self.ndim) host_reshaped = host_from_gpu(x).reshape(shp,ndim=self.ndim)
...@@ -1719,6 +1734,9 @@ class GpuReshape(tensor.Reshape): ...@@ -1719,6 +1734,9 @@ class GpuReshape(tensor.Reshape):
out[0] = x.reshape(tuple(shp)) out[0] = x.reshape(tuple(shp))
class GpuSubtensor(tensor.Subtensor): class GpuSubtensor(tensor.Subtensor):
"""
Implement subtensor on the gpu.
"""
# __hash__, __eq__, __str__ come from tensor.Subtensor # __hash__, __eq__, __str__ come from tensor.Subtensor
def make_node(self, x, *inputs): def make_node(self, x, *inputs):
assert isinstance(x.type, CudaNdarrayType) assert isinstance(x.type, CudaNdarrayType)
...@@ -1747,6 +1765,9 @@ class GpuSubtensor(tensor.Subtensor): ...@@ -1747,6 +1765,9 @@ class GpuSubtensor(tensor.Subtensor):
out[0] = x.__getitem__(cdata) out[0] = x.__getitem__(cdata)
class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1): class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1):
"""
Implement AdvancedSubtensor1 on the gpu.
"""
def make_node(self, x, ilist): def make_node(self, x, ilist):
x_ = as_cuda_ndarray_variable(x) x_ = as_cuda_ndarray_variable(x)
ilist_ = tensor.as_tensor_variable(ilist) ilist_ = tensor.as_tensor_variable(ilist)
...@@ -1770,6 +1791,9 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1): ...@@ -1770,6 +1791,9 @@ class GpuAdvancedSubtensor1(tensor.AdvancedSubtensor1):
out[0] = o out[0] = o
class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1): class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1):
"""
Implement AdvancedIncSubtensor1 on the gpu.
"""
def make_node(self, x, y, ilist): def make_node(self, x, y, ilist):
x_ = as_cuda_ndarray_variable(x) x_ = as_cuda_ndarray_variable(x)
y_ = as_cuda_ndarray_variable(y) y_ = as_cuda_ndarray_variable(y)
...@@ -1795,6 +1819,9 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1): ...@@ -1795,6 +1819,9 @@ class GpuAdvancedIncSubtensor1(tensor.AdvancedIncSubtensor1):
# so we use the parent version that loop on each indices. # so we use the parent version that loop on each indices.
class GpuIncSubtensor(tensor.IncSubtensor): class GpuIncSubtensor(tensor.IncSubtensor):
"""
Implement IncSubtensor on the gpu.
"""
def make_node(self, x, y, *inputs): def make_node(self, x, y, *inputs):
assert isinstance(x.type, CudaNdarrayType) assert isinstance(x.type, CudaNdarrayType)
assert isinstance(y.type, CudaNdarrayType) assert isinstance(y.type, CudaNdarrayType)
...@@ -1802,6 +1829,9 @@ class GpuIncSubtensor(tensor.IncSubtensor): ...@@ -1802,6 +1829,9 @@ class GpuIncSubtensor(tensor.IncSubtensor):
return Apply(self, [x,y]+rval.inputs[2:], [x.type()]) return Apply(self, [x,y]+rval.inputs[2:], [x.type()])
class GpuFlatten(tensor.Flatten): class GpuFlatten(tensor.Flatten):
"""
Implement Flatten on the gpu.
"""
def make_node(self, x ): def make_node(self, x ):
assert isinstance(x.type, CudaNdarrayType) assert isinstance(x.type, CudaNdarrayType)
rval = tensor.Flatten.make_node(self, x) rval = tensor.Flatten.make_node(self, x)
...@@ -1810,11 +1840,17 @@ class GpuFlatten(tensor.Flatten): ...@@ -1810,11 +1840,17 @@ class GpuFlatten(tensor.Flatten):
return Apply(self, [x], [out_type()]) return Apply(self, [x], [out_type()])
class GpuShape(tensor.Shape): class GpuShape(tensor.Shape):
"""
Implement Shape on the gpu.
"""
def make_node(self, x): def make_node(self, x):
return Apply(self, [x], [tensor.lvector()]) return Apply(self, [x], [tensor.lvector()])
gpu_shape = GpuShape() gpu_shape = GpuShape()
class GpuJoin(tensor.Join): class GpuJoin(tensor.Join):
"""
Implement Join on the gpu.
"""
def make_node(self, *axis_and_tensors): def make_node(self, *axis_and_tensors):
axis, tensors = axis_and_tensors[0], axis_and_tensors[1:] axis, tensors = axis_and_tensors[0], axis_and_tensors[1:]
if not tensors: if not tensors:
...@@ -1889,6 +1925,9 @@ class GpuJoin(tensor.Join): ...@@ -1889,6 +1925,9 @@ class GpuJoin(tensor.Join):
gpu_join = GpuJoin() gpu_join = GpuJoin()
class GpuAlloc(Op): class GpuAlloc(Op):
"""
Implement Alloc on the gpu.
"""
def __init__(self): def __init__(self):
pass pass
...@@ -1967,7 +2006,12 @@ class GpuAlloc(Op): ...@@ -1967,7 +2006,12 @@ class GpuAlloc(Op):
gpu_alloc = GpuAlloc() gpu_alloc = GpuAlloc()
class GpuContiguous(Op): class GpuContiguous(Op):
"""
Always return a c contiguous output. Copy the input only if it is
not already c contiguous.
"""
view_map = {0: [0]} view_map = {0: [0]}
def __eq__(self, other): def __eq__(self, other):
......
...@@ -6,6 +6,9 @@ import cuda_ndarray.cuda_ndarray as cuda ...@@ -6,6 +6,9 @@ import cuda_ndarray.cuda_ndarray as cuda
from theano.sandbox.cuda.type import CudaNdarrayType from theano.sandbox.cuda.type import CudaNdarrayType
class GpuDot22(Op): class GpuDot22(Op):
"""
Implement dot(2d, 2d) on the gpu.
"""
def __str__(self): def __str__(self):
return 'GpuDot22' return 'GpuDot22'
def __eq__(self, other): def __eq__(self, other):
...@@ -74,6 +77,9 @@ class GpuDot22(Op): ...@@ -74,6 +77,9 @@ class GpuDot22(Op):
gpu_dot22 = GpuDot22() gpu_dot22 = GpuDot22()
class GpuDot22Scalar(Op): class GpuDot22Scalar(Op):
"""
Implement dot(2d, 2d) * scalar on the gpu.
"""
def __str__(self): def __str__(self):
return 'GpuDot22Scalar' return 'GpuDot22Scalar'
def __eq__(self, other): def __eq__(self, other):
...@@ -434,6 +440,7 @@ gpu_ger_no_inplace = GpuGer(inplace=False) ...@@ -434,6 +440,7 @@ gpu_ger_no_inplace = GpuGer(inplace=False)
gpu_ger_inplace = GpuGer(inplace=True) gpu_ger_inplace = GpuGer(inplace=True)
class GpuOuter(Op): class GpuOuter(Op):
""" Implement outer on the gpu."""
def make_node(self, x, y): def make_node(self, x, y):
# we suppose type checking has been done, but make sure. # we suppose type checking has been done, but make sure.
assert (x.type.ndim == 1 and y.type.ndim == 1 and assert (x.type.ndim == 1 and y.type.ndim == 1 and
...@@ -526,6 +533,9 @@ gpu_outer = GpuOuter() ...@@ -526,6 +533,9 @@ gpu_outer = GpuOuter()
# Not really a BLAS operation, but whatever. # Not really a BLAS operation, but whatever.
# #
class GpuConv(Op): class GpuConv(Op):
"""
Implement the batched and stacked 2d convolution on the gpu.
"""
@staticmethod @staticmethod
def logical_output_shape_2d(imshp, kshp, mode): def logical_output_shape_2d(imshp, kshp, mode):
if mode == 'valid': if mode == 'valid':
...@@ -689,6 +699,9 @@ class GpuConv(Op): ...@@ -689,6 +699,9 @@ class GpuConv(Op):
class GpuDownsampleFactorMax(Op): class GpuDownsampleFactorMax(Op):
"""
Implement downsample with max on the gpu.
"""
def __init__(self, ds, ignore_border=False): def __init__(self, ds, ignore_border=False):
self.ds = tuple(ds) self.ds = tuple(ds)
self.ignore_border = ignore_border self.ignore_border = ignore_border
...@@ -846,6 +859,9 @@ class GpuDownsampleFactorMax(Op): ...@@ -846,6 +859,9 @@ class GpuDownsampleFactorMax(Op):
""" % locals() """ % locals()
class GpuDownsampleFactorMaxGrad(Op): class GpuDownsampleFactorMaxGrad(Op):
"""
Implement the grad of downsample with max on the gpu.
"""
def __init__(self, ds, ignore_border): def __init__(self, ds, ignore_border):
self.ds = tuple(ds) self.ds = tuple(ds)
self.ignore_border = ignore_border self.ignore_border = ignore_border
......
...@@ -6,7 +6,11 @@ from theano.sandbox.cuda.type import CudaNdarrayType ...@@ -6,7 +6,11 @@ from theano.sandbox.cuda.type import CudaNdarrayType
from theano.sandbox.cuda.kernel_codegen import nvcc_kernel, inline_reduce_max, inline_reduce_sum, inline_softmax from theano.sandbox.cuda.kernel_codegen import nvcc_kernel, inline_reduce_max, inline_reduce_sum, inline_softmax
class GpuCrossentropySoftmaxArgmax1HotWithBias (Op): class GpuCrossentropySoftmaxArgmax1HotWithBias (Op):
"""
Implement CrossentropySoftmaxArgmax1HotWithBias on the gpu.
"""
nin=3 nin=3
nout=3 nout=3
def __eq__(self, other): def __eq__(self, other):
...@@ -177,6 +181,9 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias (Op): ...@@ -177,6 +181,9 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias (Op):
gpu_crossentropy_softmax_argmax_1hot_with_bias = GpuCrossentropySoftmaxArgmax1HotWithBias() gpu_crossentropy_softmax_argmax_1hot_with_bias = GpuCrossentropySoftmaxArgmax1HotWithBias()
class GpuCrossentropySoftmax1HotWithBiasDx (Op): class GpuCrossentropySoftmax1HotWithBiasDx (Op):
"""
Implement CrossentropySoftmax1HotWithBiasDx on the gpu.
"""
nin=3 nin=3
nout=1 nout=1
"""Gradient wrt x of the CrossentropySoftmax1Hot Op""" """Gradient wrt x of the CrossentropySoftmax1Hot Op"""
...@@ -296,7 +303,9 @@ class GpuCrossentropySoftmax1HotWithBiasDx (Op): ...@@ -296,7 +303,9 @@ class GpuCrossentropySoftmax1HotWithBiasDx (Op):
gpu_crossentropy_softmax_1hot_with_bias_dx = GpuCrossentropySoftmax1HotWithBiasDx() gpu_crossentropy_softmax_1hot_with_bias_dx = GpuCrossentropySoftmax1HotWithBiasDx()
class GpuSoftmax (Op): class GpuSoftmax (Op):
"""Writeme""" """
Implement Softmax on the gpu.
"""
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) return type(self) == type(other)
def __hash__(self): def __hash__(self):
...@@ -392,7 +401,9 @@ class GpuSoftmax (Op): ...@@ -392,7 +401,9 @@ class GpuSoftmax (Op):
gpu_softmax = GpuSoftmax() gpu_softmax = GpuSoftmax()
class GpuSoftmaxWithBias (Op): class GpuSoftmaxWithBias (Op):
"""Writeme""" """
Implement SoftmaxWithBias on the gpu.
"""
nin = 2 nin = 2
nout = 1 nout = 1
def __eq__(self, other): def __eq__(self, other):
......
...@@ -247,7 +247,8 @@ class CURAND_Uniform(CURAND_Base): ...@@ -247,7 +247,8 @@ class CURAND_Uniform(CURAND_Base):
class CURAND_RandomStreams(object): class CURAND_RandomStreams(object):
"""RandomStreams instance that creates CURAND-based random variables. """
RandomStreams instance that creates CURAND-based random variables.
One caveat is that generators are not serializable. One caveat is that generators are not serializable.
""" """
......
...@@ -535,7 +535,7 @@ class MatrixInverse(Op): ...@@ -535,7 +535,7 @@ class MatrixInverse(Op):
and :math:`A_{inv} \cdot A` equals the identity matrix :math:`I`. and :math:`A_{inv} \cdot A` equals the identity matrix :math:`I`.
:note: When possible, the call to this op will be optimized to the call :note: When possible, the call to this op will be optimized to the call
of ``solve``. of ``solve``.
""" """
def __init__(self): def __init__(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论