From ef6f7e9b37fc8660f549b2e096013dbfb70b6ffe Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Sat, 9 Dec 2023 00:27:24 +0100 Subject: [PATCH 1/3] Generator based template for reproducing issues. --- .../generator_based_template/Makefile | 26 +++++++++++++++ .../generator_based_template/README.md | 32 +++++++++++++++++++ .../generator_based_template/generator.cpp | 19 +++++++++++ .../generator_based_template/test.cpp | 11 +++++++ 4 files changed, 88 insertions(+) create mode 100644 test/failing_with_issue/generator_based_template/Makefile create mode 100644 test/failing_with_issue/generator_based_template/README.md create mode 100644 test/failing_with_issue/generator_based_template/generator.cpp create mode 100644 test/failing_with_issue/generator_based_template/test.cpp diff --git a/test/failing_with_issue/generator_based_template/Makefile b/test/failing_with_issue/generator_based_template/Makefile new file mode 100644 index 000000000000..40d54de43fc1 --- /dev/null +++ b/test/failing_with_issue/generator_based_template/Makefile @@ -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) diff --git a/test/failing_with_issue/generator_based_template/README.md b/test/failing_with_issue/generator_based_template/README.md new file mode 100644 index 000000000000..6185a7521622 --- /dev/null +++ b/test/failing_with_issue/generator_based_template/README.md @@ -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. diff --git a/test/failing_with_issue/generator_based_template/generator.cpp b/test/failing_with_issue/generator_based_template/generator.cpp new file mode 100644 index 000000000000..3d11ad9fb3db --- /dev/null +++ b/test/failing_with_issue/generator_based_template/generator.cpp @@ -0,0 +1,19 @@ +#include +using namespace Halide; + +class TestGenerator : public Generator { +public: + // Define Input/Outputs. + Output output{"output"}; + + void generate() { + output() = 0.0f; + // Fill in. + } + + void schedule() { + // Fill in. + } +}; + +HALIDE_REGISTER_GENERATOR(TestGenerator, test_generator) diff --git a/test/failing_with_issue/generator_based_template/test.cpp b/test/failing_with_issue/generator_based_template/test.cpp new file mode 100644 index 000000000000..05985e86e813 --- /dev/null +++ b/test/failing_with_issue/generator_based_template/test.cpp @@ -0,0 +1,11 @@ +#include "generated_pipeline.h" +#include +#include + +int main(int argc, char **argv) { + Halide::Runtime::Buffer output = Halide::Runtime::Buffer::make_scalar(); + generated_pipeline(output); + std::printf("Output: %f\n", output()); + + return 0; +} From bfc90a3cb3b5b4836b9059345048c00e0b620a6d Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Sat, 9 Dec 2023 00:57:10 +0100 Subject: [PATCH 2/3] Improve makefile to generate a separate runtime to reduce code size that will be inspected. --- .../generator_based_template/Makefile | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/failing_with_issue/generator_based_template/Makefile b/test/failing_with_issue/generator_based_template/Makefile index 40d54de43fc1..95c904b964c1 100644 --- a/test/failing_with_issue/generator_based_template/Makefile +++ b/test/failing_with_issue/generator_based_template/Makefile @@ -3,24 +3,29 @@ HALIDE_DISTRIB_PATH ?= ../../../distrib include ../../../apps/support/Makefile.inc -.PHONY: build clean test codegen -build: $(BIN)/$(HL_TARGET)/generated_pipeline.stmt +.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)/%/generated_pipeline.stmt: $(GENERATOR_BIN)/generator +$(BIN)/$(HL_TARGET)/runtime.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=$* + $^ -r runtime -o $(@D) -e static_library target=$(HL_TARGET) -$(BIN)/%/test: $(BIN)/%/generated_pipeline.a test.cpp +$(BIN)/$(HL_TARGET)/generated_pipeline.a: $(GENERATOR_BIN)/generator @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -Wall -O2 -I$(BIN)/$* test.cpp $(BIN)/$*/generated_pipeline.a -o $@ $(LDFLAGS) + $^ -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 -test: $(BIN)/$(HL_TARGET)/test - $< +$(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 + $< + From 7d03caa63c95c3bc60b044c32bbe53393a9ff51a Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Sat, 9 Dec 2023 00:58:24 +0100 Subject: [PATCH 3/3] Correct the readme to reflect new changes. --- .../generator_based_template/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/failing_with_issue/generator_based_template/README.md b/test/failing_with_issue/generator_based_template/README.md index 6185a7521622..0129fee034f3 100644 --- a/test/failing_with_issue/generator_based_template/README.md +++ b/test/failing_with_issue/generator_based_template/README.md @@ -2,17 +2,17 @@ ## 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`. +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., + 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. @@ -22,11 +22,11 @@ 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: +main-file provided `test.cpp`. There is an additional rule in the Makefile, +which you can run with: ```sh -make HL_TARGET=... test +make HL_TARGET=... run ``` If this is part of the problem demonstration, include this code in the issue.