Skip to content

Commit ef6f7e9

Browse files
committed
Generator based template for reproducing issues.
1 parent 357e646 commit ef6f7e9

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Makefile inspired by the structure of the apps/
2+
3+
HALIDE_DISTRIB_PATH ?= ../../../distrib
4+
include ../../../apps/support/Makefile.inc
5+
6+
.PHONY: build clean test codegen
7+
build: $(BIN)/$(HL_TARGET)/generated_pipeline.stmt
8+
9+
10+
$(GENERATOR_BIN)/generator: generator.cpp $(GENERATOR_DEPS)
11+
@mkdir -p $(@D)
12+
$(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS)
13+
14+
$(BIN)/%/generated_pipeline.stmt: $(GENERATOR_BIN)/generator
15+
@mkdir -p $(@D)
16+
$^ -g test_generator -e stmt,stmt_html,conceptual_stmt,conceptual_stmt_html,device_code,assembly,bitcode,static_library,c_header -o $(@D) -f generated_pipeline target=$*
17+
18+
$(BIN)/%/test: $(BIN)/%/generated_pipeline.a test.cpp
19+
@mkdir -p $(@D)
20+
$(CXX) $(CXXFLAGS) -Wall -O2 -I$(BIN)/$* test.cpp $(BIN)/$*/generated_pipeline.a -o $@ $(LDFLAGS)
21+
22+
test: $(BIN)/$(HL_TARGET)/test
23+
$<
24+
25+
clean:
26+
rm -rf $(BIN)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generator template for making issues.
2+
3+
## Making the generator and emitting the code.
4+
5+
This folder contains an app-like structure, but is meant
6+
for making reproducible codegen issues.
7+
By default the generator will emit `stmt`, `stmt_html`, `conceptual_stmt`,
8+
`conceptual_stmt_html`, `device_code`, `assembly`, `bitcode`.
9+
10+
To use this template, you ...
11+
1. Duplicate this folder and rename it (reference the issue number in the
12+
folder name if you have one).
13+
2. Edit the `generator.cpp` file to produce the issue you wish to
14+
demonstrate.
15+
3. Run `make HL_TARGET=...`, with your target triple (e.g.,
16+
`HL_TARGET=host-cuda`).
17+
4. Open an issue and paste the generator code.
18+
19+
As such, the everyone with the Halide repository checked out, can copy-paste
20+
your generator code and reproduce the issue with relative ease.
21+
22+
## Running the code.
23+
24+
If you additionally wish to run the code as part of the issue, there is a starter
25+
main-file provided `test.cpp`. There is an additional rule in the Makefile, which you can
26+
run with:
27+
28+
```sh
29+
make HL_TARGET=... test
30+
```
31+
32+
If this is part of the problem demonstration, include this code in the issue.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <Halide.h>
2+
using namespace Halide;
3+
4+
class TestGenerator : public Generator<TestGenerator> {
5+
public:
6+
// Define Input/Outputs.
7+
Output<float> output{"output"};
8+
9+
void generate() {
10+
output() = 0.0f;
11+
// Fill in.
12+
}
13+
14+
void schedule() {
15+
// Fill in.
16+
}
17+
};
18+
19+
HALIDE_REGISTER_GENERATOR(TestGenerator, test_generator)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "generated_pipeline.h"
2+
#include <HalideBuffer.h>
3+
#include <cstdio>
4+
5+
int main(int argc, char **argv) {
6+
Halide::Runtime::Buffer<float, 0> output = Halide::Runtime::Buffer<float>::make_scalar();
7+
generated_pipeline(output);
8+
std::printf("Output: %f\n", output());
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)