fix xpu build failure (#120315)
# Motivation
fix build failure introduced by [[DeviceIndex][6/N] Use DeviceIndex in more places](https://github.com/pytorch/pytorch/pull/120133), parameter `total` is undefined in line 100. see https://github.com/pytorch/pytorch/pull/120133/files#diff-00eb8a6f5dfbc341ee9ab9aff0e3dbece8ad73483d4f41a005b1f453cb78221cR91-L102
[PR120133](https://github.com/pytorch/pytorch/pull/120133) forgot to add the label `ciflow/xpu`, so the XPU CI flow was not triggered.
# Solution
refer to [Why is std::cout not printing the correct value for my int8_t number?](https://stackoverflow.com/questions/7587782) , static cast int8_t to int16_t and the condition `device >= 0 && device < total` is enough.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120315
Approved by: https://github.com/Skylion007, https://github.com/cyyever, https://github.com/malfet, https://github.com/EikanWang, https://github.com/gujinghui