Skip to content

Commit 5e40b9c

Browse files
committed
Move vectorize_pred to test/correctness, fix failing_with_issue build
Issue #3357 now passes. Rewrote the test to initialize f/g with cast<A>(0) rather than undef so all positions are deterministic and the full output is compared. Widened to W = vec_width * 4, H = 1000 to cover more predicate-edge conditions. Update 3292 and 3293 to the current JITUserContext* allocator API (set_custom_allocator was removed). Add EXPECT_FAILURE so ctest treats the still-crashing tests as known failures. Comment out 4283 whose source file does not exist. Enable add_subdirectory(failing_with_issue) in test/CMakeLists.txt.
1 parent c936df9 commit 5e40b9c

6 files changed

Lines changed: 94 additions & 9 deletions

File tree

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if (WITH_TEST_RUNTIME)
6565
add_subdirectory(runtime)
6666
endif ()
6767

68-
# FIXME: failing_with_issue is dead code :)
68+
add_subdirectory(failing_with_issue)
6969

7070
Halide_feature(WITH_TEST_FUZZ "Build fuzz tests" ON)
7171
if (WITH_TEST_FUZZ)

test/correctness/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ tests(GROUPS correctness
350350
vectorize_guard_with_if.cpp
351351
vectorize_mixed_widths.cpp
352352
vectorize_nested.cpp
353+
vectorize_pred.cpp
353354
vectorize_varying_allocation_size.cpp
354355
vectorized_assert.cpp
355356
vectorized_gpu_allocation.cpp
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "Halide.h"
2+
#include <cstdio>
3+
4+
using namespace Halide;
5+
6+
template<typename T>
7+
T tolerance() {
8+
return 0;
9+
}
10+
11+
template<>
12+
float tolerance<float>() {
13+
return 1e-7f;
14+
}
15+
16+
17+
template<typename T>
18+
bool equals(T a, T b, T epsilon = tolerance<T>()) {
19+
T error = std::abs(a - b);
20+
return error <= epsilon;
21+
}
22+
23+
template<typename A>
24+
bool test(int vec_width) {
25+
26+
int W = vec_width * 4;
27+
int H = 1000;
28+
29+
Buffer<A> input(W, H + 20);
30+
for (int y = 0; y < H + 20; y++) {
31+
for (int x = 0; x < W; x++) {
32+
input(x, y) = (A)((rand() & 0xffff) * 0.125 + 1.0);
33+
}
34+
}
35+
36+
Var x("x"), y("y");
37+
Func f("f"), g("g");
38+
39+
RDom r(0, W, 0, H);
40+
r.where((r.x * r.y) % 8 < 7);
41+
42+
Expr e = input(r.x, r.y);
43+
for (int i = 1; i < 5; i++) {
44+
e = e + input(r.x, r.y + i);
45+
}
46+
47+
for (int i = 5; i >= 0; i--) {
48+
e = e + input(r.x, r.y + i);
49+
}
50+
51+
f(x, y) = cast<A>(0);
52+
f(r.x, r.y) = e;
53+
g(x, y) = cast<A>(0);
54+
g(r.x, r.y) = e;
55+
f.update(0).vectorize(r.x);
56+
57+
Buffer<A> outputg = g.realize({W, H});
58+
Buffer<A> outputf = f.realize({W, H});
59+
60+
for (int j = 0; j < H; j++) {
61+
for (int i = 0; i < W; i++) {
62+
if (!equals(outputf(i, j), outputg(i, j))) {
63+
std::cout << type_of<A>() << " x " << vec_width << " failed at "
64+
<< i << " " << j << ": "
65+
<< outputf(i, j) << " vs " << outputg(i, j) << "\n"
66+
<< "Failure!\n";
67+
return false;
68+
}
69+
}
70+
}
71+
72+
return true;
73+
}
74+
75+
int main(int argc, char **argv) {
76+
if (!test<float>(4)) return 1;
77+
if (!test<float>(8)) return 1;
78+
79+
printf("Success!\n");
80+
return 0;
81+
}

test/failing_with_issue/3292_async_specialize.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ using namespace Halide;
77

88
size_t custom_malloc_size = 0;
99

10-
void *my_malloc(void *user_context, size_t x) {
10+
void *my_malloc(JITUserContext *user_context, size_t x) {
1111
custom_malloc_size = x;
1212
void *orig = malloc(x + 32);
1313
void *ptr = (void *)((((size_t)orig + 32) >> 5) << 5);
1414
((void **)ptr)[-1] = orig;
1515
return ptr;
1616
}
1717

18-
void my_free(void *user_context, void *ptr) {
18+
void my_free(JITUserContext *user_context, void *ptr) {
1919
free(((void **)ptr)[-1]);
2020
}
2121

@@ -49,7 +49,8 @@ int main(int argc, char **argv) {
4949
// automatic storage folding refused to fold this (the case
5050
// above).
5151

52-
g.set_custom_allocator(my_malloc, my_free);
52+
g.jit_handlers().custom_malloc = my_malloc;
53+
g.jit_handlers().custom_free = my_free;
5354

5455
Buffer<int> im = g.realize({100, 1000});
5556

test/failing_with_issue/3293_storage_folding_async.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ using namespace Halide;
77

88
size_t custom_malloc_size = 0;
99

10-
void *my_malloc(void *user_context, size_t x) {
10+
void *my_malloc(JITUserContext *user_context, size_t x) {
1111
custom_malloc_size = x;
1212
void *orig = malloc(x + 32);
1313
void *ptr = (void *)((((size_t)orig + 32) >> 5) << 5);
1414
((void **)ptr)[-1] = orig;
1515
return ptr;
1616
}
1717

18-
void my_free(void *user_context, void *ptr) {
18+
void my_free(JITUserContext *user_context, void *ptr) {
1919
free(((void **)ptr)[-1]);
2020
}
2121

@@ -51,7 +51,8 @@ int main(int argc, char **argv) {
5151
// automatic storage folding refused to fold this (the case
5252
// above).
5353

54-
h.set_custom_allocator(my_malloc, my_free);
54+
h.jit_handlers().custom_malloc = my_malloc;
55+
h.jit_handlers().custom_free = my_free;
5556

5657
Buffer<int> im = h.realize({100, 1000});
5758

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
tests(GROUPS failing_with_issue
2+
EXPECT_FAILURE
23
SOURCES
34
3292_async_specialize.cpp
45
3293_storage_folding_async.cpp
5-
3357_vectorize_pred.cpp
6-
4283_store_at_gpu.cpp
6+
# 3357_vectorize_pred.cpp # moved to test/correctness/vectorize_pred.cpp
7+
# 4283_store_at_gpu.cpp # TODO: test file missing, tracked in issue #4283
78
)

0 commit comments

Comments
 (0)