So you work in mono-channel.
In this case, try using B.permute(1, 2, 0) to obtain the desired shape:
[batch_size, in_channels, sequence_length] (see docs 9).
Then your kernel of size [5] needs to be [out_channel, in_channels, kernel_size], so it needs a kernel.view(1, 1, -1).
And to keep the same size, you need a padding of ((kernel_size - 1) / 2) pixels.
So for example, torch.nn.functional.conv1d(B.permute(1, 2, 0), kernel.view(1, 1, -1), padding=2)