def _gather(link, target):
    (size, num) = size_num_grads(link)
    ptrs = numpy.empty(num, dtype=numpy.uint64)
    dtypes = numpy.empty(num, dtype=numpy.int8)
    info = numpy.empty((num + 1), dtype=numpy.int32)
    info[0] = 0
    i = 0
    for (_, param) in sorted(link.namedparams()):
        if (param.size == 0):
            continue
        ptrs[i] = 0
        d = getattr(param, target)
        if (d is not None):
            ptrs[i] = d.data.ptr
        dtypes[i] = 0
        if (param.dtype == numpy.float16):
            dtypes[i] = 1
        info[(i + 1)] = (info[i] + param.size)
        i += 1
    info[0] = num
    ptrs = cuda.to_gpu(ptrs)
    dtypes = cuda.to_gpu(dtypes)
    info = cuda.to_gpu(info)
    return _memcpy_gather()(ptrs, dtypes, info, size=size)
def _gather(link, target):
    (size, num) = size_num_grads(link)
    ptrs = numpy.empty(num, dtype=numpy.uint64)
    dtypes = numpy.empty(num, dtype=numpy.int8)
    info = numpy.empty((num + 1), dtype=numpy.int32)
    info[0] = 0
    i = 0
    for (_, param) in sorted(link.namedparams()):
        if (param.size == 0):
            continue
        ptrs[i] = 0
        d = getattr(param, target)
        if (d is not None):
            ptrs[i] = d.data.ptr
        dtypes[i] = 0
        if (param.dtype == numpy.float16):
            dtypes[i] = 1
        info[(i + 1)] = (info[i] + param.size)
        i += 1
    info[0] = num
    ptrs = cuda.to_gpu(ptrs)
    dtypes = cuda.to_gpu(dtypes)
    info = cuda.to_gpu(info)
    return _memcpy_gather()(ptrs, dtypes, info, size=size)