Skip to content

Commit

Permalink
Generator based template for reproducing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcourteaux committed Dec 8, 2023
1 parent 357e646 commit 43c055d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/failing_with_issue/generator_based_template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Makefile inspired by the structure of the apps/

HALIDE_DISTRIB_PATH ?= ../../../distrib
include ../../../apps/support/Makefile.inc

.PHONY: build clean test codegen
build: $(BIN)/$(HL_TARGET)/generated_pipeline.stmt


$(GENERATOR_BIN)/generator: generator.cpp $(GENERATOR_DEPS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(filter %.cpp,$^) -o $@ $(LIBHALIDE_LDFLAGS)

$(BIN)/%/generated_pipeline.stmt: $(GENERATOR_BIN)/generator
@mkdir -p $(@D)
$^ -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=$*

$(BIN)/%/test: $(BIN)/%/generated_pipeline.a test.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -Wall -O2 -I$(BIN)/$* test.cpp $(BIN)/$*/generated_pipeline.a -o $@ $(LDFLAGS)

test: $(BIN)/$(HL_TARGET)/test
$<

clean:
rm -rf $(BIN)
32 changes: 32 additions & 0 deletions test/failing_with_issue/generator_based_template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generator template for making issues.

## Making the generator and emitting the code.

This folder contains an app-like structure, but is meant
for making reproducible codegen issues.
By default the generator will emit `stmt`, `stmt_html`, `conceptual_stmt`,
`conceptual_stmt_html`, `device_code`, `assembly`, `bitcode`.

To use this template, you ...
1. Duplicate this folder and rename it (reference the issue number in the
folder name if you have one).
2. Edit the `generator.cpp` file to produce the issue you wish to
demonstrate.
3. Run `make HL_TARGET=...`, with your target triple (e.g.,
`HL_TARGET=host-cuda`).
4. Open an issue and paste the generator code.

As such, the everyone with the Halide repository checked out, can copy-paste
your generator code and reproduce the issue with relative ease.

## Running the code.

If you additionally wish to run the code as part of the issue, there is a starter
main-file provided `test.cpp`. There is an additional rule in the Makefile, which you can
run with:

```sh
make HL_TARGET=... test
```

If this is part of the problem demonstration, include this code in the issue.
19 changes: 19 additions & 0 deletions test/failing_with_issue/generator_based_template/generator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <Halide.h>
using namespace Halide;

class TestGenerator : public Generator<TestGenerator> {
public:
// Define Input/Outputs.
Output<float> output{"output"};

void generate() {
output() = 0.0f;
// Fill in.
}

void schedule() {
// Fill in.
}
};

HALIDE_REGISTER_GENERATOR(TestGenerator, test_generator)
11 changes: 11 additions & 0 deletions test/failing_with_issue/generator_based_template/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "generated_pipeline.h"
#include <HalideBuffer.h>
#include <cstdio>

int main(int argc, char **argv) {
Halide::Runtime::Buffer<float, 0> output = Halide::Runtime::Buffer<float>::make_scalar();
generated_pipeline(output);
std::printf("Output: %f\n", output());

return 0;
}

0 comments on commit 43c055d

Please sign in to comment.