To ensure that libtorch recognized CUDA, I added /INCLUDE:"?warp_size@cuda@at@@YAHXZ" to the linker command line in Visual Studio 2022, following https://github.com/pytorch/pytorch/issues/31611 .
libtorch
/INCLUDE:"?warp_size@cuda@at@@YAHXZ"