Device-to-device differentiable FDTD method