-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow async nestings that violate read after write dependencies (#…
…7868) * Disallow async nestings that violate read after write dependencies Fixes #7867 * Add test * Add another failure case, and improve error message * Add some more tests * Update test * Add new test to cmakelists * Fix for llvm trunk * Always acquire the folding semaphore, even if unused * Skip async_order test under wasm * trigger buildbots --------- Co-authored-by: Volodymyr Kysenko <[email protected]> Co-authored-by: Steven Johnson <[email protected]>
- Loading branch information
1 parent
4fc2a7d
commit 674e6cc
Showing
8 changed files
with
228 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "Halide.h" | ||
#include <stdio.h> | ||
|
||
using namespace Halide; | ||
|
||
int main(int argc, char **argv) { | ||
if (get_jit_target_from_environment().arch == Target::WebAssembly) { | ||
printf("[SKIP] WebAssembly does not support async() yet.\n"); | ||
return 0; | ||
} | ||
|
||
{ | ||
Func producer1, producer2, consumer; | ||
Var x, y; | ||
|
||
producer1(x, y) = x + y; | ||
producer2(x, y) = producer1(x, y); | ||
consumer(x, y) = producer1(x, y - 1) + producer2(x, y + 1); | ||
|
||
consumer.compute_root(); | ||
|
||
producer1.compute_at(consumer, y); | ||
producer2.compute_at(consumer, y).async(); | ||
|
||
consumer.bound(x, 0, 16).bound(y, 0, 16); | ||
|
||
Buffer<int> out = consumer.realize({16, 16}); | ||
|
||
out.for_each_element([&](int x, int y) { | ||
int correct = 2 * (x + y); | ||
if (out(x, y) != correct) { | ||
printf("out(%d, %d) = %d instead of %d\n", | ||
x, y, out(x, y), correct); | ||
exit(-1); | ||
} | ||
}); | ||
} | ||
{ | ||
Func producer1, producer2, consumer; | ||
Var x, y; | ||
|
||
producer1(x, y) = x + y; | ||
producer2(x, y) = producer1(x, y); | ||
consumer(x, y) = producer1(x, y - 1) + producer2(x, y + 1); | ||
|
||
consumer.compute_root(); | ||
|
||
producer1.compute_root(); | ||
producer2.store_root().compute_at(consumer, y).async(); | ||
|
||
consumer.bound(x, 0, 16).bound(y, 0, 16); | ||
|
||
Buffer<int> out = consumer.realize({16, 16}); | ||
|
||
out.for_each_element([&](int x, int y) { | ||
int correct = 2 * (x + y); | ||
if (out(x, y) != correct) { | ||
printf("out(%d, %d) = %d instead of %d\n", | ||
x, y, out(x, y), correct); | ||
exit(-1); | ||
} | ||
}); | ||
} | ||
|
||
{ | ||
Func producer1, producer2, consumer; | ||
Var x, y; | ||
|
||
producer1(x, y) = x + y; | ||
producer2(x, y) = producer1(x, y); | ||
consumer(x, y) = producer1(x, y - 1) + producer2(x, y + 1); | ||
|
||
consumer.compute_root(); | ||
|
||
producer1.store_root().compute_at(consumer, y).async(); | ||
producer2.store_root().compute_at(consumer, y).async(); | ||
|
||
consumer.bound(x, 0, 16).bound(y, 0, 16); | ||
|
||
Buffer<int> out = consumer.realize({16, 16}); | ||
|
||
out.for_each_element([&](int x, int y) { | ||
int correct = 2 * (x + y); | ||
if (out(x, y) != correct) { | ||
printf("out(%d, %d) = %d instead of %d\n", | ||
x, y, out(x, y), correct); | ||
exit(-1); | ||
} | ||
}); | ||
} | ||
|
||
printf("Success!\n"); | ||
return 0; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#include "Halide.h" | ||
|
||
using namespace Halide; | ||
|
||
int main(int argc, char **argv) { | ||
|
||
Func f{"f"}, g{"g"}, h{"h"}; | ||
Var x; | ||
|
||
f(x) = cast<uint8_t>(x + 7); | ||
g(x) = f(x); | ||
h(x) = g(x); | ||
|
||
// The schedule below is an error. It should really be: | ||
// f.store_root().compute_at(g, Var::outermost()); | ||
// So that it's nested inside the consumer h. | ||
f.store_root().compute_at(h, x); | ||
g.store_root().compute_at(h, x).async(); | ||
|
||
Buffer<uint8_t> buf = h.realize({32}); | ||
for (int i = 0; i < buf.dim(0).extent(); i++) { | ||
uint8_t correct = i + 7; | ||
if (buf(i) != correct) { | ||
printf("buf(%d) = %d instead of %d\n", i, buf(i), correct); | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "Halide.h" | ||
|
||
using namespace Halide; | ||
|
||
// From https://github.com/halide/Halide/issues/5201 | ||
int main(int argc, char **argv) { | ||
Func producer1, producer2, consumer; | ||
Var x, y; | ||
|
||
producer1(x, y) = x + y; | ||
producer2(x, y) = producer1(x, y); | ||
consumer(x, y) = producer2(x, y - 1) + producer2(x, y + 1); | ||
|
||
consumer.compute_root(); | ||
|
||
producer1.compute_at(consumer, y).async(); | ||
producer2.store_root().compute_at(consumer, y).async(); | ||
|
||
consumer.bound(x, 0, 16).bound(y, 0, 16); | ||
|
||
Buffer<int> out = consumer.realize({16, 16}); | ||
return 0; | ||
} |
This file contains 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