nll_loss (cpu): Simplify index checking: rely on exception propagation in parallel_for (#29454)
Summary:
Replace the custom thread-safe invalid index checking and instead rely on the internal exception propagation of parallel_for. Use the `TORCH_CHECK_INDEX` macro when checking indices.
Align index check in `nll_loss` implementation with `nll_loss2d`, see https://github.com/pytorch/pytorch/issues/28304.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29454
Differential Revision: D18418169
Pulled By: ezyang
fbshipit-source-id: 273da5230dd4b66a51bf02386718b31d2dd41e66