Skip to content

Early termination for any/all boolean reduction functions #365

Answered by danieldjohnson
dan-zheng asked this question in Q&A
Discussion options

You must be logged in to vote

In principle, I think this could be implemented fairly easily using a while loop instead of a for loop (and this would only work for short-circuit-able reductions, so any and all would no longer be special-cases of reduce).

I think early-termination is possibly less friendly to parallel hardware like GPUs, since it requires dynamic branching. (Although, that being said, if we really care about parallel hardware for any and all then we would eventually want to implement them using withAccum or similar instead of using withState.)

There's also a bigger question of "how early" we want to terminate. Using a while loop would avoid looping over the indices after the first False, but probably wo…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dan-zheng
Comment options

dan-zheng Dec 22, 2020
Collaborator Author

@apaszke
Comment options

@dan-zheng
Comment options

dan-zheng Dec 22, 2020
Collaborator Author

Answer selected by dan-zheng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants