Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator based template for reproducing issues. #7999

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions test/failing_with_issue/generator_based_template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Makefile inspired by the structure of the apps/

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

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


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

$(BIN)/$(HL_TARGET)/runtime.a: $(GENERATOR_BIN)/generator
@mkdir -p $(@D)
$^ -r runtime -o $(@D) -e static_library target=$(HL_TARGET)

$(BIN)/$(HL_TARGET)/generated_pipeline.a: $(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=$(HL_TARGET)-no_runtime-no_bounds_query

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

clean:
rm -rf $(BIN)

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

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=... codegen`, 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=... run
```

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;
}