Beispiel #1
0
    def run_conv_valid(
            self,
            inputs_shape,
            filters_shape,
            border_mode="valid",
            filter_dilation=(1, 1, 1),
            subsample=(1, 1, 1),
            verify_grad=False,
    ):
        inputs_shape = [inputs_shape[i] for i in (0, 4, 1, 2, 3)]
        filters_shape = [filters_shape[i] for i in (0, 4, 1, 2, 3)]

        inputs_val = np.random.random(inputs_shape).astype(config.floatX)
        filters_val = np.random.random(filters_shape).astype(config.floatX)

        inputs = gpuarray_shared_constructor(inputs_val)
        filters = gpuarray_shared_constructor(filters_val)

        conv_ref = Corr3dMM(
            border_mode=border_mode,
            filter_dilation=filter_dilation,
            subsample=subsample,
        )(ref_cast(inputs), ref_cast(filters))
        f_ref = aesara.function([], conv_ref, mode=mode_without_gpu)

        conv = GpuCorr3dMM(
            border_mode=border_mode,
            filter_dilation=filter_dilation,
            subsample=subsample,
        )(inputs, filters)
        f = aesara.function([], conv, mode=mode_with_gpu)

        res_ref = f_ref()
        res = f()
        utt.assert_allclose(res_ref, res)

        if verify_grad:
            utt.verify_grad(
                GpuCorr3dMM(
                    border_mode=border_mode,
                    filter_dilation=filter_dilation,
                    subsample=subsample,
                ),
                [inputs_val, filters_val],
                mode=mode_with_gpu,
            )
Beispiel #2
0
def local_abstractconv3d_gemm(fgraph, node):
    # If config.blas__ldflags is empty, Aesara will use
    # a NumPy C implementation of [sd]gemm_.
    if config.cxx == "" or node.inputs[0].dtype == "float16":
        return
    if not isinstance(node.op, AbstractConv3d):
        return None
    img, kern = node.inputs
    if not isinstance(img.type, TensorType) or not isinstance(kern.type, TensorType):
        return None

    # need to flip the kernel if necessary
    if node.op.filter_flip:
        kern = kern[:, :, ::-1, ::-1, ::-1]
    rval = Corr3dMM(
        border_mode=node.op.border_mode,
        subsample=node.op.subsample,
        filter_dilation=node.op.filter_dilation,
        num_groups=node.op.num_groups,
    )(img, kern)
    copy_stack_trace(node.outputs[0], rval)

    return [rval]