I’m not sure I understand your question correctly…
Is it template matching?
h, w, kernel_size = 256, 256, 6
ks = kernel_size * kernel_size
tensor = torch.randn(3, h, w) > 0.5 
pattern = {
    tensor[0, 0:0+kernel_size, 4:4+kernel_size]: "A",
    tensor[1, 10:10+kernel_size, 3:3+kernel_size]: "B"
}

# Step 1, unfold the tensor
nh, nw = h - kernel_size + 1, w - kernel_size + 1
u_tensor = torch.nn.functional.unfold(tensor[None, ...].float(), kernel_size).clone()
u_tensor = u_tensor[0].bool().reshape(3, ks, -1)
u_tensor = u_tensor.permute(1, 0, 2).reshape(ks, -1)

# Step 2, search
for key, value in pattern.items():
    mask = u_tensor == key.view(-1, 1)
    indices = torch.where(mask.sum(dim=0) == ks)[0]
    
    # Step 3, parse indices
    indices_x = indices % nw 
    indices_y = (indices // nw) % nh 
    indices_c = indices // (nw * nh)
   
    # all works done.

    # Now Check the Result 
    for index_c, index_y, index_x in zip(indices_c, indices_y, indices_x):
        result = tensor[index_c, index_y:index_y+kernel_size, index_x:index+kernel_size]
        print((result == key).all())