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 Enhancements #1523

Merged
merged 33 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c7ab93f
Merge branch 'master' into generator_revisions
steven-johnson Sep 23, 2016
20663db
Merge branch 'master' into generator_revisions
steven-johnson Sep 23, 2016
3c85603
Merge branch 'master' into generator_revisions
steven-johnson Sep 26, 2016
fb26100
Merge branch 'master' into generator_revisions
steven-johnson Sep 27, 2016
1810833
Generator Enhancements
steven-johnson Sep 27, 2016
4aaa3d5
Merge branch 'master' into generator_revisions
steven-johnson Oct 3, 2016
4c9dd45
Merge branch 'master' into generator_revisions
steven-johnson Oct 4, 2016
77a0e97
Revise the Stub generator to use a struct for Inputs as well
steven-johnson Oct 4, 2016
7814575
Merge branch 'master' into generator_revisions
steven-johnson Oct 5, 2016
485ce28
Merge branch 'master' into generator_revisions
steven-johnson Oct 6, 2016
ef0899d
Merge branch 'master' into generator_revisions
steven-johnson Oct 18, 2016
acd10e3
Add inference for type-and-dim for Func, and size for Array
steven-johnson Oct 18, 2016
b590b6c
Update Generator.cpp
abadams Oct 18, 2016
278818f
Merge branch 'master' into generator_revisions
steven-johnson Oct 18, 2016
b9ce0c9
Merge pull request #1555 from halide/abadams-patch-1
steven-johnson Oct 18, 2016
be8f10f
Merge remote-tracking branch 'origin/generator_revisions' into genera…
steven-johnson Oct 18, 2016
406fe3b
Fix compilation error in rational_approximation_helper
steven-johnson Oct 18, 2016
7f28b71
rename make_image
steven-johnson Oct 18, 2016
76dc2dc
rework HALIDE_REGISTER_GENERATOR macro to avoid "auto register_me = "
steven-johnson Oct 18, 2016
35836c6
Merge branch 'master' into generator_revisions
steven-johnson Oct 19, 2016
19b1fb8
rational_approximation tweaks
steven-johnson Oct 19, 2016
d585b04
Add NamesInterface to GeneratorStub
steven-johnson Oct 19, 2016
4c009d1
Omit certain ctors in stubs when there are no GP/SP present
steven-johnson Oct 19, 2016
8abacb5
Use args().at() for output Vars
steven-johnson Oct 20, 2016
8a6a8f7
Merge branch 'master' into generator_revisions
steven-johnson Oct 24, 2016
d18d210
Use *this instead of context() in StubUser
steven-johnson Oct 24, 2016
5c6fcbc
Minor nomenclature cleanup
steven-johnson Oct 24, 2016
db33afe
Tweak GeneratorContext API
steven-johnson Oct 24, 2016
cecfed4
Add doc comments, EXPORTS, etc
steven-johnson Oct 24, 2016
a8861d8
Add link to https://github.com/halide/Halide/wiki/Generator-Enhancements
steven-johnson Oct 24, 2016
70ded22
Fixes for MSVC issues
steven-johnson Oct 25, 2016
f842a4b
Merge branch 'master' into generator_revisions
steven-johnson Oct 25, 2016
3195766
Rewrite Generator doxygen comment
steven-johnson Oct 26, 2016
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
56 changes: 52 additions & 4 deletions HalideGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ endfunction()
# GENERATOR_ARGS are optional extra arguments passed to the generator executable during
# build.
function(halide_add_aot_library AOT_LIBRARY_TARGET)

# Parse arguments
set(options )
set(oneValueArgs GENERATOR_TARGET GENERATOR_NAME GENERATED_FUNCTION)
Expand Down Expand Up @@ -156,13 +155,62 @@ function(halide_add_aot_library_dependency TARGET AOT_LIBRARY_TARGET)
endfunction(halide_add_aot_library_dependency)

function(halide_add_generator NAME)
set(options )
set(oneValueArgs )
set(multiValueArgs SRCS)
set(options WITH_STUB)
set(oneValueArgs STUB_GENERATOR_NAME)
set(multiValueArgs SRCS STUB_DEPS)
cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

halide_project("${NAME}"
"generator"
"${CMAKE_SOURCE_DIR}/tools/GenGen.cpp"
${args_SRCS})

# Declare a stub library if requested.
if (${args_WITH_STUB})
halide_add_generator_stub_library(STUB_GENERATOR_TARGET "${NAME}"
STUB_GENERATOR_NAME ${args_STUB_GENERATOR_NAME})
endif()

# Add any stub deps passed to us.
foreach(STUB ${args_STUB_DEPS})
halide_add_generator_stub_dependency(TARGET ${NAME} STUB_GENERATOR_TARGET ${STUB})
endforeach()
endfunction(halide_add_generator)

function(halide_add_generator_stub_library)
set(options )
set(oneValueArgs STUB_GENERATOR_TARGET STUB_GENERATOR_NAME)
set(multiValueArgs )
cmake_parse_arguments(args "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

halide_generator_genfiles_dir(${args_STUB_GENERATOR_TARGET} GENFILES_DIR)

set(STUB_HDR "${GENFILES_DIR}/${args_STUB_GENERATOR_TARGET}.stub.h")

set(GENERATOR_EXEC_ARGS "-o" "${GENFILES_DIR}" "-e" "cpp_stub")
if (NOT ${args_STUB_GENERATOR_NAME} STREQUAL "")
list(APPEND GENERATOR_EXEC_ARGS "-g" "${args_STUB_GENERATOR_NAME}")
endif()

set(STUBGEN "${args_STUB_GENERATOR_TARGET}.exec_stub_generator")
halide_generator_add_exec_generator_target(${STUBGEN}
GENERATOR_TARGET ${args_STUB_GENERATOR_TARGET}
GENERATOR_ARGS "${GENERATOR_EXEC_ARGS}"
GENFILES_DIR ${GENFILES_DIR}
OUTPUTS "${STUB_HDR}"
)
set_source_files_properties("${STUB_HDR}" PROPERTIES GENERATED TRUE)
endfunction(halide_add_generator_stub_library)

function(halide_add_generator_stub_dependency)
# Parse arguments
set(options )
set(oneValueArgs TARGET STUB_GENERATOR_TARGET)
set(multiValueArgs )
cmake_parse_arguments(args "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

halide_generator_genfiles_dir(${args_STUB_GENERATOR_TARGET} GENFILES_DIR)
set(STUBGEN "${args_STUB_GENERATOR_TARGET}.exec_stub_generator")
add_dependencies("${args_TARGET}" ${STUBGEN})
target_include_directories("${args_TARGET}" PRIVATE "${GENFILES_DIR}")
endfunction(halide_add_generator_stub_dependency)
26 changes: 24 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,11 @@ $(FILTERS_DIR)/%.a: $(BIN_DIR)/%.generator
$(FILTERS_DIR)/%.h: $(FILTERS_DIR)/%.a
@echo $@ produced implicitly by $^

$(FILTERS_DIR)/%.stub.h: $(BIN_DIR)/%.generator
@mkdir -p $(FILTERS_DIR)
@-mkdir -p $(TMP_DIR)
cd $(TMP_DIR); $(CURDIR)/$< -o $(CURDIR)/$(FILTERS_DIR) -e cpp_stub

# If we want to use a Generator with custom GeneratorParams, we need to write
# custom rules: to pass the GeneratorParams, and to give a unique function and file name.
$(FILTERS_DIR)/cxx_mangling.a: $(BIN_DIR)/cxx_mangling.generator
Expand Down Expand Up @@ -907,16 +912,20 @@ $(FILTERS_DIR)/pyramid.a: $(BIN_DIR)/pyramid.generator
@-mkdir -p $(TMP_DIR)
cd $(TMP_DIR); $(CURDIR)/$< -f pyramid -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET) levels=10

METADATA_TESTER_GENERATOR_ARGS=input.type=uint8 input.dim=3 output.type=float32,float32 output.dim=3 \
input_not_nod.type=uint8 input_not_nod.dim=3 input_nod.dim=3 input_not.type=uint8 array_input.size=2 \
array_i8.size=2 array_i16.size=2 array_i32.size=2 array_h.size=2 array_outputs.size=2

# metadata_tester is built with and without user-context
$(FILTERS_DIR)/metadata_tester.a: $(BIN_DIR)/metadata_tester.generator
@mkdir -p $(FILTERS_DIR)
@-mkdir -p $(TMP_DIR)
cd $(TMP_DIR); $(CURDIR)/$< -f metadata_tester -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET)-no_runtime
cd $(TMP_DIR); $(CURDIR)/$< -f metadata_tester -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET)-no_runtime $(METADATA_TESTER_GENERATOR_ARGS)

$(FILTERS_DIR)/metadata_tester_ucon.a: $(BIN_DIR)/metadata_tester.generator
@mkdir -p $(FILTERS_DIR)
@-mkdir -p $(TMP_DIR)
cd $(TMP_DIR); $(CURDIR)/$< -f metadata_tester_ucon -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET)-user_context-no_runtime
cd $(TMP_DIR); $(CURDIR)/$< -f metadata_tester_ucon -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET)-user_context-no_runtime $(METADATA_TESTER_GENERATOR_ARGS)

$(BIN_DIR)/generator_aot_metadata_tester: $(FILTERS_DIR)/metadata_tester_ucon.a

Expand Down Expand Up @@ -963,6 +972,19 @@ $(BIN_DIR)/generator_aot_tiled_blur: $(FILTERS_DIR)/tiled_blur_blur.a
$(BIN_DIR)/generator_aot_tiled_blur_interleaved: $(FILTERS_DIR)/tiled_blur_blur_interleaved.a
$(BIN_DIR)/generator_aot_cxx_mangling_define_extern: $(FILTERS_DIR)/cxx_mangling.a

$(BIN_DIR)/generator_jit_stubtest: $(FILTERS_DIR)/stubtest.stub.h $(BIN_DIR)/stubtest_generator.o

$(BIN_DIR)/stubuser_generator.o: $(FILTERS_DIR)/stubtest.stub.h
$(BIN_DIR)/stubuser.generator: $(BIN_DIR)/stubtest_generator.o

# stubtest has input and output funcs with undefined types and array sizes; this is fine for stub
# usage (the types can be inferred), but for AOT compilation, we must make the types
# concrete via generator args.
$(FILTERS_DIR)/stubtest.a: $(BIN_DIR)/stubtest.generator
@mkdir -p $(FILTERS_DIR)
@-mkdir -p $(TMP_DIR)
cd $(TMP_DIR); $(CURDIR)/$< -f stubtest -o $(CURDIR)/$(FILTERS_DIR) target=$(HL_TARGET)-no_runtime input.type=float32 input.size=2 int_arg.size=2 f.type=float32,float32

# Usually, it's considered best practice to have one Generator per
# .cpp file, with the generator-name and filename matching;
# nested_externs_generators.cpp is a counterexample, and thus requires
Expand Down
Loading