Move needs_dynamic_casting to a non-CUDA specific file. (#38813)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38813
We are going to apply this check to CPU (with some changes), so just moving this in preparation.
The code is just cut-pasted here, no behavioral change.
Test Plan: Imported from OSS
Differential Revision: D21670554
Pulled By: gchanan
fbshipit-source-id: c7e07f67bb4c6524fde12237e35892e42557103e