nvidia gpus don't like too many branch divergence. flatten if conditions