Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
714eaee
Implement sliding window warmups by backing up the loop min.
dsharletg Feb 9, 2021
5bfc8f4
Fix indirect sliding windows.
dsharletg Feb 9, 2021
1108c20
Improve is_monotonic.
dsharletg Feb 10, 2021
231b2ba
Small cleanups.
dsharletg Feb 10, 2021
626b4bd
Avoid generating vector valued bounds.
dsharletg Feb 10, 2021
bbf0e6c
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 10, 2021
78a6dc5
Fix build error on some compilers.
dsharletg Feb 10, 2021
27a3239
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 10, 2021
521ab9b
Fix loop bounds.
dsharletg Feb 10, 2021
ad04086
Don't try to slide things that should just be compute_at the store_at…
dsharletg Feb 11, 2021
696b05c
Print condition when printing boxes.
dsharletg Feb 11, 2021
7115acb
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 11, 2021
899bbaf
Less things broken.
dsharletg Feb 12, 2021
58e10f2
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 12, 2021
896808d
Add/fix comments.
dsharletg Feb 12, 2021
c1a9e98
Comments
dsharletg Feb 12, 2021
fb5a2a0
Fix async by moving if inside consume (and so inside acquires).
dsharletg Feb 12, 2021
3b0ea78
Fix division.
dsharletg Feb 12, 2021
067b2cf
This doesn't work on master either.
dsharletg Feb 12, 2021
4ad0214
Add TODO
dsharletg Feb 12, 2021
e3e17f4
Acquire is not a no-op.
dsharletg Feb 12, 2021
bf94364
Add comment about unfortunate simplification.
dsharletg Feb 12, 2021
93e7162
Remove debug(0)
dsharletg Feb 12, 2021
2cfd0b4
Add simplification of for { acquire { noop } }
dsharletg Feb 13, 2021
76afb2b
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 13, 2021
ad949e8
Fix folding factors finally!
dsharletg Feb 13, 2021
ab1e689
Update storage_folding test.
dsharletg Feb 13, 2021
4e1768f
Fix bug when cloning a semaphore used more than once.
dsharletg Feb 13, 2021
094ab25
Disable failing test.
dsharletg Feb 13, 2021
ada0bc6
Work around bad complexity in is_monotonic.
dsharletg Feb 13, 2021
f2a12a6
Fix sub bug
dsharletg Feb 13, 2021
22f4213
Significantly faster schedule for blur.
dsharletg Feb 13, 2021
710c48d
Update tracing test.
dsharletg Feb 13, 2021
5471d0e
New simplifications that help with upsampled and downsampled sliding …
dsharletg Feb 14, 2021
2dd47d2
This doesn't need explicit folding any more.
dsharletg Feb 14, 2021
95374ec
Fix new simplifier rules.
dsharletg Feb 14, 2021
cf6d436
Fix simplifier div rule
dsharletg Feb 14, 2021
9591baa
Remove ancient brittle test.
dsharletg Feb 14, 2021
adedac1
Fix simplify rule again
dsharletg Feb 14, 2021
b2a90f3
More LT -> EQ rules for mod
dsharletg Feb 14, 2021
4422d02
Fix nested sliding windows with upsamples.
dsharletg Feb 15, 2021
d9baccb
Replace hack with better solution.
dsharletg Feb 15, 2021
f1030c5
Add missing override
abadams Feb 15, 2021
e45963d
Merge branch 'dsharletg/sliding-window' of github.com:halide/Halide i…
dsharletg Feb 15, 2021
8f64734
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 15, 2021
07fd14c
Don't rewrite loop variable if the min doesn't change.
dsharletg Feb 16, 2021
6cd6601
Refactor sliding window lowering.
dsharletg Feb 16, 2021
b543bb6
Fixed bounds growing redundantly for independent producers.
dsharletg Feb 16, 2021
db89dec
Don't take the union unless possibly needed.
dsharletg Feb 16, 2021
35cd9f9
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 16, 2021
c1e94ee
Respect conditional provide/required.
dsharletg Feb 16, 2021
7375067
Add missing overrides
dsharletg Feb 16, 2021
e4518e9
Much better schedule.
dsharletg Feb 16, 2021
3ee34b7
Use a smaller image for blur benchmarking so that different schedules…
abadams Feb 16, 2021
a7f90c9
Replace Interval with ConstantInterval for is_monotonic.
dsharletg Feb 17, 2021
c6463f8
Merge branch 'dsharletg/sliding-window' of github.com:halide/Halide i…
dsharletg Feb 17, 2021
32caa31
Don't try to handle unsigned deltas.
dsharletg Feb 17, 2021
d63d5f1
Add failing test.
dsharletg Feb 17, 2021
89905d2
Remove unused new code.
dsharletg Feb 17, 2021
f90f12f
Remove weird debugging code.
dsharletg Feb 17, 2021
d57ce80
Avoid expanding bounds of split producers
dsharletg Feb 17, 2021
a5a2d3b
Remove stray likely_if_innermost.
dsharletg Feb 17, 2021
0f597f9
Remove old autotune tests.
dsharletg Feb 17, 2021
e0d1db7
Update test for guarded producers.
dsharletg Feb 17, 2021
abd4604
Reenable test.
dsharletg Feb 17, 2021
c22be02
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 17, 2021
45a087a
Update trace for guarding producers.
dsharletg Feb 17, 2021
8a74d4d
Don't overwrite required.used
dsharletg Feb 17, 2021
54a9577
Handle LE/LT in bounds of lanes in vectorize
abadams Feb 17, 2021
8adeb87
Merge branch 'dsharletg/sliding-window' of https://github.com/halide/…
abadams Feb 17, 2021
db8dcf5
Fix acquire and release of warmups
dsharletg Feb 18, 2021
e0895be
Earlier fix for multiply cloned acquires was wrong.
dsharletg Feb 18, 2021
75b9117
Handle nested vectorization.
dsharletg Feb 18, 2021
e18cb63
clang-format
dsharletg Feb 18, 2021
952e6d6
Remove autotune_bug_* tests
dsharletg Feb 18, 2021
1539749
Fix shadowing error on some compilers.
dsharletg Feb 18, 2021
3d0d136
Appease overzealous clang-tidy warning.
dsharletg Feb 18, 2021
b77d152
clang-format
dsharletg Feb 18, 2021
9257768
Don't use silly hack.
dsharletg Feb 18, 2021
967bebb
clang-tidy...
dsharletg Feb 18, 2021
c8ce21d
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 18, 2021
5130cde
It's no longer safe to assume monotonic means bounds_of_expr_in_scope…
abadams Feb 18, 2021
4a06724
Address review comments
dsharletg Feb 18, 2021
8994381
Merge branch 'dsharletg/sliding-window' of github.com:halide/Halide i…
dsharletg Feb 18, 2021
2c65818
Add comment
dsharletg Feb 18, 2021
31d95a7
Add missing override.
dsharletg Feb 19, 2021
f1765a1
Fix constant interval issues.
dsharletg Feb 19, 2021
1069d33
Revert and remove empty interval
dsharletg Feb 19, 2021
2efbe3f
Fix multiply!?
dsharletg Feb 19, 2021
d366408
Reduce need for simplifications.
dsharletg Feb 19, 2021
d4b9b38
Simplifications from dsharletg/sliding-window branch
dsharletg Feb 19, 2021
159fe4e
Merge branch 'dsharletg/simplify' into dsharletg/sliding-window
dsharletg Feb 19, 2021
088bf42
Don't learn likely(x) and x.
dsharletg Feb 19, 2021
8336761
Add comment
dsharletg Feb 19, 2021
93a3615
Merge branch 'dsharletg/simplify' into dsharletg/sliding-window
dsharletg Feb 19, 2021
594d02d
Add some min/max rules.
dsharletg Feb 19, 2021
455fe18
Also substitute facts from asserts
dsharletg Feb 19, 2021
c644ff9
Remove is_empty from header too.
dsharletg Feb 19, 2021
49ad245
More rules
dsharletg Feb 19, 2021
34715e5
Add double stairstep rule.
dsharletg Feb 20, 2021
290a076
Disable rule that uncovers bugs.
dsharletg Feb 20, 2021
03efb3f
Consider anded expressions as if they were independent nested ifs.
dsharletg Feb 20, 2021
cf04409
Add promise_clamped to producer guards.
dsharletg Feb 20, 2021
e014add
Revert "Consider anded expressions as if they were independent nested…
dsharletg Feb 20, 2021
9658259
Don't combine ifs, split them instead.
dsharletg Feb 20, 2021
4b64146
Update trace
dsharletg Feb 20, 2021
5573d78
clang-tidy/clang-format
dsharletg Feb 20, 2021
d4932fb
Remove splitting of ifs, it breaks brittle tests.
dsharletg Feb 20, 2021
e5d7b23
Safer check on old conditions.
dsharletg Feb 20, 2021
f35b63e
Fix producer guard condition.
dsharletg Feb 20, 2021
cf4efc1
Interval fixes.
dsharletg Feb 20, 2021
6dc8834
Handle sliding backwards
dsharletg Feb 20, 2021
a99f2dd
Handle transitive dependencies.
dsharletg Feb 21, 2021
08a1cca
Backport abadams' fix from abadams/slide_over_split_loop
dsharletg Feb 21, 2021
28be1d0
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 22, 2021
37bed40
Fix select visitor.
dsharletg Feb 22, 2021
ff6b936
More simplifier rules.
dsharletg Feb 23, 2021
cd60ef8
Bring back old logic as a fallback.
dsharletg Feb 23, 2021
013c522
Avoid specializations corrupting sliding
dsharletg Feb 23, 2021
2af11b9
Fix boneheaded rule errors.
dsharletg Feb 23, 2021
abd65e5
Fix slightly conservative bounds at the max for split case.
dsharletg Feb 23, 2021
4e0cd8a
This pattern is too sensitive to the simplifier. In a real use case, …
dsharletg Feb 23, 2021
7b1e441
Add missing clamp rule
dsharletg Feb 23, 2021
80d825c
Don't count unlikely loops as inner loops for likely_if_innermost
abadams Feb 23, 2021
78767bb
Use <= instead of == to solve for the new loop min
abadams Feb 23, 2021
e574e3b
Verify simplifier changes and add variants as suggested by synthesizer
abadams Feb 23, 2021
322ab62
Make implicit assumption explicit, for clarity
abadams Feb 23, 2021
27354a3
Use find_constant_bounds
dsharletg Feb 23, 2021
9901cdd
Merge branch 'dsharletg/sliding-window' of github.com:halide/Halide i…
dsharletg Feb 23, 2021
b297507
Guard against expanded bounds more effectively.
dsharletg Feb 24, 2021
64c9be3
Update tracing test
dsharletg Feb 24, 2021
fe9f18b
Small cleanup.
dsharletg Feb 24, 2021
9a4d1e1
Don't simplify/prove using lets that might change value.
dsharletg Feb 24, 2021
ca848dc
Stronger solving without expanding lets.
dsharletg Feb 24, 2021
aaafa20
New simplifier rule for alignment
dsharletg Feb 24, 2021
59706e9
Fix case where no warmup needed
dsharletg Feb 24, 2021
b50b936
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 24, 2021
b85e293
Add some useful rules.
dsharletg Feb 25, 2021
e32806c
Add safety check on when we can use the new loop min.
dsharletg Feb 25, 2021
b4f640b
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 25, 2021
07711d4
Better proof to avoid hacky condition that is hard to prove.
dsharletg Feb 25, 2021
b90bfd4
Small cleanup and use the nice new folding factors.
dsharletg Feb 25, 2021
686e781
Bring back unrolled producer test.
dsharletg Feb 25, 2021
439e200
clang-format
dsharletg Feb 25, 2021
79e05a1
Expand comment.
dsharletg Feb 25, 2021
b16b285
Fix sliding backwards condition.
dsharletg Feb 25, 2021
1aca038
min(new_loop_min, loop_min) isn't needed any more.
dsharletg Feb 26, 2021
f3dd3cc
We need that min, but we can be more conservative about it.
dsharletg Feb 26, 2021
e104484
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Feb 27, 2021
4dc8820
Stronger handling of previous loop mins.
dsharletg Mar 1, 2021
e59cf57
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Mar 3, 2021
8f0a0ca
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Mar 4, 2021
4be9feb
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Mar 8, 2021
dad4379
Remove unused is_monotonic_strong.
dsharletg Mar 8, 2021
da256bc
Remove ConstantInterval::make_intersection.
dsharletg Mar 8, 2021
f85ac93
Avoid need to handle uint specially.
dsharletg Mar 9, 2021
aae1966
Merge branch 'master' of github.com:halide/Halide into dsharletg/slid…
dsharletg Mar 9, 2021
c5d23bd
Add cache for depends_on.
dsharletg Mar 11, 2021
f036b4e
Reduce unnecessarily large cache scope
dsharletg Mar 11, 2021
929b6c9
The first part of the key is always the same
dsharletg Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/blur/halide_blur_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class HalideBlur : public Halide::Generator<HalideBlur> {
}
} else if (get_target().has_feature(Target::HVX)) {
// Hexagon schedule.
// TODO: Try using a schedule like the CPU one below.
const int vector_size = 128;

blur_y.compute_root()
Expand All @@ -96,8 +97,17 @@ class HalideBlur : public Halide::Generator<HalideBlur> {
.vectorize(x, vector_size);
} else {
// CPU schedule.
blur_y.split(y, y, yi, 8).parallel(y).vectorize(x, 8);
blur_x.store_at(blur_y, y).compute_at(blur_y, yi).vectorize(x, 8);
// Compute blur_x as needed at each vector of the output.
// Halide will store blur_x in a circular buffer so its
// results can be re-used.
blur_y
.split(y, y, yi, 32)
.parallel(y)
.vectorize(x, 16);
blur_x
.store_at(blur_y, y)
.compute_at(blur_y, x)
.vectorize(x, 16);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions apps/blur/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ int main(int argc, char **argv) {
const bool is_hexagon = strstr(md->target, "hvx_128") || strstr(md->target, "hvx_64");

// The Hexagon simulator can't allocate as much memory as the above wants.
const int width = is_hexagon ? 648 : 6408;
const int height = is_hexagon ? 482 : 4802;
const int width = is_hexagon ? 648 : 2568;
const int height = is_hexagon ? 482 : 1922;

Buffer<uint16_t> input(width, height);

Expand Down
4 changes: 2 additions & 2 deletions apps/camera_pipe/camera_pipe_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ void CameraPipe::generate() {
.compute_at(processed, yi)
.store_at(processed, yo)
.prefetch(input, y, 2)
.fold_storage(y, 16)
.fold_storage(y, 4)
.tile(x, y, x, y, xi, yi, 2 * vec, 2)
.vectorize(xi)
.unroll(yi);

deinterleaved
.compute_at(processed, yi)
.store_at(processed, yo)
.fold_storage(y, 8)
.fold_storage(y, 4)
.reorder(c, x, y)
.vectorize(x, 2 * vec, TailStrategy::RoundUp)
.unroll(c);
Expand Down
2 changes: 1 addition & 1 deletion apps/local_laplacian/local_laplacian_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class LocalLaplacian : public Halide::Generator<LocalLaplacian> {
outGPyramid[j]
.store_at(output, yo)
.compute_at(output, y)
.fold_storage(y, 8)
.fold_storage(y, 4)
.vectorize(x, 8);
}
outGPyramid[0].compute_at(output, y).vectorize(x, 8);
Expand Down
34 changes: 19 additions & 15 deletions src/FuseGPUThreadLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,12 @@ class ExtractSharedAndHeapAllocations : public IRMutator {
// repeated dependence on the block var
s.size = solve_expression(s.size, op->name).result;
s.size = simplify(common_subexpression_elimination(s.size));
auto result = is_monotonic(s.size, op->name);
if (result == Monotonic::Unknown) {
switch (is_monotonic(s.size, op->name)) {
case Monotonic::Unknown:
// TODO: if bounds_of_expr_in_scope becomes more
// powerful than is_monotonic, it might be better
// to call it here. That would be risky though, as
// it's not exact.
debug(1)
<< "Shared allocation for " << s.name
<< " has a size that is non-monontonic in the gpu block variable " << op->name
Expand All @@ -359,19 +363,19 @@ class ExtractSharedAndHeapAllocations : public IRMutator {
get_compiler_logger()->record_non_monotonic_loop_var(op->name, s.size);
}
precompute_allocation_size(s);
} else {
auto interval_bounds = bounds_of_expr_in_scope(s.size, scope);
user_assert(interval_bounds.has_upper_bound())
<< "Couldn't infer bounds for " << s.name << " shared memory allocation\n";
// In theory we could precompute the allocation
// size if there's no upper bound too, but for the
// assert above to fail we'd have to encounter an
// expression that is_monotonic detects as
// increasing, decreasing, or constant, but is
// somehow unbounded. It's probable that no such
// expression exists. is_monotonic is generally
// less capable than bounds_of_expr_in_scope.
s.size = interval_bounds.max;
break;
case Monotonic::Increasing:
s.size = substitute(op->name, simplify(op->min + op->extent - 1), s.size);
break;
case Monotonic::Constant:
// The size expression used the variable, but we
// may have successfully eliminated it above, or
// is_monotonic might have detected that the
// dependence is false somehow. Just treat it as
// decreasing...
case Monotonic::Decreasing:
s.size = substitute(op->name, op->min, s.size);
break;
}
}
if (in_threads && op->is_parallel()) {
Expand Down
86 changes: 86 additions & 0 deletions src/Interval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,91 @@ Expr Interval::neg_inf_noinline() {
return Interval::neg_inf_expr;
}

ConstantInterval::ConstantInterval() = default;

ConstantInterval::ConstantInterval(int64_t min, int64_t max)
: min(min), max(max), min_defined(true), max_defined(true) {
internal_assert(min <= max);
}

ConstantInterval ConstantInterval::everything() {
return ConstantInterval();
}

ConstantInterval ConstantInterval::single_point(int64_t x) {
return ConstantInterval(x, x);
}

ConstantInterval ConstantInterval::bounded_below(int64_t min) {
ConstantInterval result(min, min);
result.max_defined = false;
return result;
}

ConstantInterval ConstantInterval::bounded_above(int64_t max) {
ConstantInterval result(max, max);
result.min_defined = false;
return result;
}

bool ConstantInterval::is_everything() const {
return !min_defined && !max_defined;
}

bool ConstantInterval::is_single_point() const {
return min_defined && max_defined && min == max;
}

bool ConstantInterval::is_single_point(int64_t x) const {
return min_defined && max_defined && min == x && max == x;
}

bool ConstantInterval::has_upper_bound() const {
return max_defined;
}

bool ConstantInterval::has_lower_bound() const {
return min_defined;
}

bool ConstantInterval::is_bounded() const {
return has_upper_bound() && has_lower_bound();
}

bool ConstantInterval::operator==(const ConstantInterval &other) const {
if (min_defined != other.min_defined || max_defined != other.max_defined) {
return false;
}
return (!min_defined || min == other.min) && (!max_defined || max == other.max);
}

void ConstantInterval::include(const ConstantInterval &i) {
if (max_defined && i.max_defined) {
max = std::max(max, i.max);
} else {
max_defined = false;
}
if (min_defined && i.min_defined) {
min = std::min(min, i.min);
} else {
min_defined = false;
}
}

void ConstantInterval::include(int64_t x) {
if (max_defined) {
max = std::max(max, x);
}
if (min_defined) {
min = std::min(min, x);
}
}

ConstantInterval ConstantInterval::make_union(const ConstantInterval &a, const ConstantInterval &b) {
ConstantInterval result = a;
result.include(b);
return result;
}

} // namespace Internal
} // namespace Halide
57 changes: 57 additions & 0 deletions src/Interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,63 @@ struct Interval {
static Expr neg_inf_noinline();
};

/** A class to represent ranges of integers. Can be unbounded above or below, but
* they cannot be empty. */
struct ConstantInterval {
/** The lower and upper bound of the interval. They are included
* in the interval. */
int64_t min = 0, max = 0;
bool min_defined = false, max_defined = false;

/* A default-constructed Interval is everything */
ConstantInterval();

/** Construct an interval from a lower and upper bound. */
ConstantInterval(int64_t min, int64_t max);

/** The interval representing everything. */
static ConstantInterval everything();

/** Construct an interval representing a single point. */
static ConstantInterval single_point(int64_t x);

/** Construct intervals bounded above or below. */
static ConstantInterval bounded_below(int64_t min);
static ConstantInterval bounded_above(int64_t max);

/** Is the interval the entire range */
bool is_everything() const;

/** Is the interval just a single value (min == max) */
bool is_single_point() const;

/** Is the interval a particular single value */
bool is_single_point(int64_t x) const;

/** Does the interval have a finite least upper bound */
bool has_upper_bound() const;

/** Does the interval have a finite greatest lower bound */
bool has_lower_bound() const;

/** Does the interval have a finite upper and lower bound */
bool is_bounded() const;

/** Expand the interval to include another Interval */
void include(const ConstantInterval &i);

/** Expand the interval to include a point */
void include(int64_t x);

/** Construct the smallest interval containing two intervals. */
static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b);

/** Equivalent to same_as. Exists so that the autoscheduler can
* compare two map<string, Interval> for equality in order to
* cache computations. */
bool operator==(const ConstantInterval &other) const;
};

} // namespace Internal
} // namespace Halide

Expand Down
Loading