added NaN/Inf checks to cuda kernels