@Aniruddh honestly I see nothing wrong in ur code have u tried running this code on the cpu instead or try running on a another cuda gpu pc
This might be from the configuration of ur gpu on the nnvidia panel (this is just a speculation)