Only commutative reductions can be parallelized#6609
Merged
steven-johnson merged 1 commit intohalide:masterfrom Feb 14, 2022
Merged
Only commutative reductions can be parallelized#6609steven-johnson merged 1 commit intohalide:masterfrom
steven-johnson merged 1 commit intohalide:masterfrom
Conversation
Because parallelization changes the order of computation within the reduction, parallelizing associative but non-commutative reductions can result in (non-deterministically) incorrect results in the same way `reorder`ing them can.
For instance Halide currently accepts the following code, but generates non-deterministic outputs on GPU. On CPU with `.parallel(r.x)`, OpenMP rejects the generated code (correctly) stating that the `#pragma omp atomic` is invalid for the same reasons.
```c++
#include <stdio.h>
#include "Halide.h"
using namespace Halide;
int main(int argc, char **argv) {
Halide::Func A("A"), B("B");
Halide::Var i("i");
A(i) = i;
B() = -1;
Halide::RDom r(0, 1024);
B() = A(r.x);
A.compute_root();
B.update().atomic().gpu_blocks(r.x);
B.compile_jit(get_host_target().with_feature(Target::CUDA));
Halide::Buffer<int32_t> b = B.realize();
printf("%d\n", b());
return 0;
}
```
Member
|
I believe this is correct. Thanks for the fix. |
abadams
approved these changes
Feb 11, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because parallelization changes the order of computation within the reduction, parallelizing associative but non-commutative reductions can result in (non-deterministically) incorrect results in the same way
reordering them can.For instance Halide currently accepts the following code, but generates non-deterministic outputs on GPU. On CPU with
.parallel(r.x), OpenMP rejects the generated code (correctly) stating that the#pragma omp atomicis invalid for the same reasons.