Thank you very much for your response. Let me share a code snippet of the forward function.
#def mymult(num1,num2):
      #return num1 somebooleanoperations num2    #returns num1 * num2


def convcheck():
        torch.manual_seed(1)
        batch_size = 2
        channels = 1
        
        h, w = 4,4
        image = torch.randn(batch_size, channels, h, w) # input image

        
        out_channels = 2
        kh, kw = 2, 2# kernel size
        dh, dw = 1, 1 # stride
        size = int((h-kh+2*0)/dh+1)    
 
        conv = nn.Conv2d(in_channels=channels, out_channels=out_channels, kernel_size=kw, padding=0,stride=dh )
        
        out = conv (image)
        filt = conv.weight.data 
        bias = conv.bias.data
        imageunfold = F.unfold(image,kernel_size=kh,padding=0,stride=dh)
        
        kernels_flat = filt.view(out_channels,-1)
   
        res =  torch.matmul(kernels_flat,imageunfold) # == imageunfoldkernels_flat @ imageunfold



       
        result1 = torch.zeros(batch_size,kernels_flat.size(0),imageunfold.size(2))


        for m_batch in range(len(imageunfold)):
                #iterate through rows of X  
            for i in range(kernels_flat.size(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ):
                # iterate through columns of Y
                for j in range(imageunfold.size(2)):                   
                    # iterate through rows of Y
                    for k in range(imageunfold.size(1)):              
                      
                        result1[m_batch][i][j]  +=   mymult(float(kernels_flat[i][k]),float(imageunfold[m_batch][k][j])))  # kernels_flat[i][k] * imageunfold[m_batch][k][j]
                        
     
# Upper three loops can they be vectorized or made fast
      
#out , res and result all three are equivalent


        res = res.view(-1, out_channels, size, size)
    
        result1 = result1.view(-1, out_channels, size, size)



        bias = bias.unsqueeze(1).unsqueeze(2)


        if bias is not None:
            result1 += bias.unsqueeze(0)                  
            res += bias.unsqueeze(0)

I would like the above loops to act parallel or fast not sure what term to use here. I really appreciate your time and effort you put into the forums.