Solved by InnovArul in post #2 
              
              
                I am not sure about this paper. 
Typically, you can consider the parameters as an 1D array (vectorize the conv and fully connected layer parameters) and correspondingly the gradients will also be an 1D array. 
Further, you can do p^T.g as normal inner product. 
Would this work?