Skip to content

Commit 04b0eea

Browse files
abadamsclaude
andauthored
Add better error message for hoist_storage on extern stage (#8974)
Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent f90ddeb commit 04b0eea

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/ScheduleFunctions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,12 @@ bool validate_schedule(Function f, const Stmt &s, const Target &target, bool is_
23172317
user_error << "Func \"" << f.name() << "\" is scheduled with ring_buffer(), but has matching store_at and hoist_storage levels. Add an explicit hoist_storage directive to the schedule to fix the issue.\n";
23182318
}
23192319

2320+
// Check if hoist_storage is used with an extern stage
2321+
if (f.has_extern_definition() && !hoist_storage_at.is_inlined() && hoist_storage_at != store_at) {
2322+
user_error << "Func \"" << f.name() << "\" is an extern function with storage hoisted to a different level than store_at. "
2323+
<< "Func::hoist_storage is not currently supported for extern functions.";
2324+
}
2325+
23202326
vector<ComputeLegalSchedules::Site> &sites = legal.sites_allowed;
23212327
int store_idx = -1, compute_idx = -1, hoist_storage_idx = -1;
23222328
for (size_t i = 0; i < sites.size(); i++) {

test/error/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ tests(GROUPS error
6666
func_tuple_types_mismatch.cpp
6767
func_tuple_update_types_mismatch.cpp
6868
fuse_vectorized_var_with_rvar.cpp
69+
hoist_storage_extern.cpp
6970
hoist_storage_without_compute_at.cpp
7071
implicit_args.cpp
7172
impossible_constraints.cpp
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "Halide.h"
2+
#include <stdio.h>
3+
4+
using namespace Halide;
5+
6+
int main(int argc, char **argv) {
7+
Func f, g, h;
8+
Var x, y;
9+
10+
// Extern stage
11+
f.define_extern("make_data", {}, Int(32), 1);
12+
13+
// Two-stage pipeline
14+
g(x, y) = f(2 * x + y);
15+
h(x) = g(x, 0) + g(x, 1);
16+
17+
// Schedule with hoist_storage on an extern function
18+
// This should produce an error because buffer metadata needed
19+
// for device cleanup is only available at the store_at location
20+
h.compute_root().vectorize(x, 8, TailStrategy::RoundUp);
21+
g.compute_at(h, x).unroll(y).vectorize(x);
22+
f.hoist_storage(g, Var::outermost()).bound_storage(_0, 16).compute_at(g, y);
23+
24+
// This should fail with a user error
25+
h.compile_jit();
26+
27+
printf("Success!\n");
28+
return 0;
29+
}

0 commit comments

Comments
 (0)