Rewrite misc.diff to use pycuda's ElementwiseKernel and memoization.