# Help setting up convolution in NNLib.jl

**URL:** <https://discourse.julialang.org/t/help-setting-up-convolution-in-nnlib-jl/31769>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [December 2, 2019, 6:36pm UTC](https://discourse.julialang.org/t/help-setting-up-convolution-in-nnlib-jl/31769 "2019-12-02T18:36:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stormyweathers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stormyweathers/32/11644_2.png) [@stormyweathers](https://discourse.julialang.org/u/stormyweathers)\
**Post date:** [December 2, 2019, 6:36pm UTC](https://discourse.julialang.org/t/help-setting-up-convolution-in-nnlib-jl/31769/1 "2019-12-02T18:36:23Z")

</div>

Hey there, new Julia user here trying to get acclimated.

As a warm-up example, I want to build a GPU accelerated heat-equation explicit time-stepper. I am trying to implement the discrete laplacian using a convolution in NNLib. However, I don’t understand the documentation and can’t find any clear examples that I can understand.

As a concrete example, I want to compute in a 10x10 grid with ghost cells, the convolution with kernel:

```julia
0 1 0
1 -4 1
0 1 0

```

The first step in setting up the convolution is constructing a `DenseConvDims` object. There is a “convenience wrapper” with signature

```julia
function DenseConvDims(x_size::NTuple{M}, w_size::NTuple{M};
                   stride=1, padding=0, dilation=1, flipkernel::Bool=false) where M

```

I’m not sure, but I think x,w are the dimensions of the source and target spaces. For this case, I believe I want the default `stride`, `dilation` and `flipkernel`. but I probably need `padding=1` for the ghost cells. With this padding, I expect the target array to be smaller than the source space. So I try:

```julia
julia> DenseConvDims((11,11),(10,10),padding=1)
ERROR: DimensionMismatch("Input channels must match! (11 vs. 10)")

julia> DenseConvDims((11,11),(10,10),padding=0)
ERROR: DimensionMismatch("Input channels must match! (11 vs. 10)")

```

Ok, that didn’t work I’ll try to ignore the ghost cells for now.

```julia
julia> DenseConvDims((11,11),(11,11))
DenseConvDims: (11,) * () -> (11,), stride: () pad: (), dil: (), flip: false

```

This didn’t give any errors, but I don’t think this is correct. The stride, padding, dilation parameters appear unset, and the symbol `(11,) * () -> (11,)` doesn’t seem correct. I expect something like `(11,11)*(3,3) -> (11,11)` after I set the kernel, and before setting the kernel `(11,11)*()->(11,11)`.

I don’t even know how to set up the kernel after this step.

Could somebody please help me with this example?

Thanks!
