Optimize kernels in_perm_2d_k and out_perm_2d_k.