示例#1
0
文件: cudnn.py 项目: nicedi/chainer
def create_pooling_descriptor(ksize, stride, pad, mode):
    desc = Descriptor(cudnn.createPoolingDescriptor(), cudnn.destroyPoolingDescriptor)
    ndim = len(ksize)
    if ndim != len(stride) or ndim != len(pad):
        raise ValueError("ksize, stride, and pad must be of same length")

    if ndim == 2:
        cudnn.setPooling2dDescriptor(desc.value, mode, ksize[0], ksize[1], pad[0], pad[1], stride[0], stride[1])
    else:
        c_ksize = _to_ctypes_array(ksize)
        c_pad = _to_ctypes_array(pad)
        c_stride = _to_ctypes_array(stride)
        cudnn.setPoolingNdDescriptor(desc.value, mode, ndim, c_ksize.data, c_pad.data, c_stride.data)

    return desc
示例#2
0
def create_pooling_descriptor(ksize, stride, pad, mode):
    desc = Descriptor(cudnn.createPoolingDescriptor(),
                      cudnn.destroyPoolingDescriptor)
    ndim = len(ksize)
    if ndim != len(stride) or ndim != len(pad):
        raise ValueError('ksize, stride, and pad must be of same length')

    if ndim == 2:
        cudnn.setPooling2dDescriptor(
            desc.value, mode, ksize[0], ksize[1], pad[0], pad[1],
            stride[0], stride[1])
    else:
        cudnn.setPoolingNdDescriptor(
            desc.value, mode, ndim, _to_ctypes_array(ksize),
            _to_ctypes_array(pad), _to_ctypes_array(stride))

    return desc