diff --git a/cmake/HalideGeneratorHelpers.cmake b/cmake/HalideGeneratorHelpers.cmake index ffa69377e15b..9e8be3e8611f 100644 --- a/cmake/HalideGeneratorHelpers.cmake +++ b/cmake/HalideGeneratorHelpers.cmake @@ -93,8 +93,14 @@ function(add_halide_generator TARGET) # TODO: what do we need to do for PACKAGE_NAME PACKAGE_NAMESPACE EXPORT_FILE in this case? else () add_executable(${TARGET} ${ARG_SOURCES}) + target_link_libraries("${TARGET}" PRIVATE Halide::Generator ${ARG_LINK_LIBRARIES}) + + # Make a library of the Generator that can be used for (e.g.) cpp_stub. + add_library(${TARGET}.objs INTERFACE) + target_sources(${TARGET}.objs INTERFACE "$") + target_link_libraries("${TARGET}.objs" INTERFACE Halide::Halide ${ARG_LINK_LIBRARIES}) + target_include_directories("${TARGET}.objs" INTERFACE "$") add_executable(${gen} ALIAS ${TARGET}) - target_link_libraries(${TARGET} PRIVATE Halide::Generator ${ARG_LINK_LIBRARIES}) if (NOT ARG_NO_DEFAULT_FLAGS AND NOT Halide_NO_DEFAULT_FLAGS) # For crosscompiling builds, the Halide headers will be included using -isystem, @@ -183,11 +189,11 @@ function(add_halide_library TARGET) # - `c_source` is selected by C_BACKEND # - `object` is selected for CMake-target-compile # - `static_library` is selected for cross-compile - # - `cpp_stub` is not available set(extra_output_names ASSEMBLY BITCODE COMPILER_LOG + CPP_STUB FEATURIZATION FUNCTION_INFO_HEADER LLVM_ASSEMBLY @@ -202,6 +208,7 @@ function(add_halide_library TARGET) set(ASSEMBLY_extension ".s") set(BITCODE_extension ".bc") set(COMPILER_LOG_extension ".halide_compiler_log") + set(CPP_STUB_extension ".stub.h") set(FEATURIZATION_extension ".featurization") set(FUNCTION_INFO_HEADER_extension ".function_info.h") set(LLVM_ASSEMBLY_extension ".ll") diff --git a/src/Generator.cpp b/src/Generator.cpp index 478b585660a6..71d66dcf010d 100644 --- a/src/Generator.cpp +++ b/src/Generator.cpp @@ -1634,6 +1634,7 @@ bool GeneratorBase::emit_cpp_stub(const std::string &stub_file_path) { GeneratorParamInfo &pi = param_info(); std::ofstream file(stub_file_path); StubEmitter emit(file, generator_registered_name, generator_stub_name, pi.generator_params(), pi.inputs(), pi.outputs()); + debug(1) << "GeneratorBase::emit_cpp_stub(): generating cpp_stub at " << stub_file_path << "\n"; emit.emit(); return true; } diff --git a/test/generator/CMakeLists.txt b/test/generator/CMakeLists.txt index 431bd4d795ff..292b47acdebb 100644 --- a/test/generator/CMakeLists.txt +++ b/test/generator/CMakeLists.txt @@ -158,6 +158,7 @@ function(_add_halide_libraries TARGET) FEATURES "${args_FEATURES}" PARAMS "${args_PARAMS}" PLUGINS "${args_PLUGINS}" + CPP_STUB cpp_stub_out FUNCTION_INFO_HEADER function_info_header_out) if (args_EXTERNS) target_link_libraries(${TARGET} INTERFACE ${args_EXTERNS}) @@ -327,12 +328,6 @@ endif () _add_halide_libraries(acquire_release) _add_halide_aot_tests(acquire_release) -# TODO: what are these? -# configure_jittest.cpp -# example_jittest.cpp -# registration_test.cpp -# rungen_test.cpp - # alias_aottest.cpp # alias_generator.cpp set(EXTRA_ALIAS_LIBS alias_with_offset_42 alias_Adams2019 alias_Li2018 alias_Mullapudi2016) @@ -733,3 +728,39 @@ _add_halide_aot_tests(variable_num_threads # Requires threading support, not yet available for wasm tests ENABLE_IF NOT ${_USING_WASM} GROUPS multithreaded) + + +## +# Create targets for the JIT tests +## + +function(_add_halide_jit_test NAME) + set(options "") + set(oneValueArgs "") + set(multiValueArgs GROUPS) + cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(TARGET "generator_jit_${NAME}") + set(SRCS "${NAME}_jittest.cpp") + + add_executable("${TARGET}" "${SRCS}") + target_link_libraries("${TARGET}" PRIVATE "${NAME}.generator.objs" Halide::Test Halide::TerminateHandler) + + # Some of the jit tests require the cpp_stub file from the Generator, so ensure it's built first: + add_dependencies("${TARGET}" "${NAME}") + + add_halide_test(${TARGET} GROUPS generator ${args_GROUPS}) + +endfunction() + +# configure_jittest.cpp +# configure_generator.cpp +_add_halide_jit_test(configure) + +# example_jittest.cpp +# example_generator.cpp +_add_halide_jit_test(example GROUPS multithreaded) + +# TODO: +# registration_test.cpp +# rungen_test.cpp diff --git a/test/generator/configure_jittest.cpp b/test/generator/configure_jittest.cpp index 8854fc0daeda..a7cbe07067f7 100644 --- a/test/generator/configure_jittest.cpp +++ b/test/generator/configure_jittest.cpp @@ -16,7 +16,13 @@ void verify(const Buffer &img, float compiletime_factor, float runti } int main(int argc, char **argv) { - GeneratorContext context(get_jit_target_from_environment()); + Target t = get_jit_target_from_environment(); + if (t.has_feature(Target::WebGPU) || t.has_feature(Target::WasmThreads)) { + printf("[SKIP] This test does not support WebGPU or WasmThreads.\n"); + return 0; + } + + GeneratorContext context(t); Buffer input(kSize, kSize, 3); input.for_each_element([&](int x, int y, int c) { diff --git a/test/generator/example_jittest.cpp b/test/generator/example_jittest.cpp index 7596c4c27b68..cb6698f0882d 100644 --- a/test/generator/example_jittest.cpp +++ b/test/generator/example_jittest.cpp @@ -16,7 +16,14 @@ void verify(const Buffer &img, float compiletime_factor, float runti } int main(int argc, char **argv) { - GeneratorContext context(get_jit_target_from_environment()); + Target t = get_jit_target_from_environment(); + if (t.has_feature(Target::WebGPU) || t.has_feature(Target::WasmThreads)) { + printf("[SKIP] This test does not support WebGPU or WasmThreads.\n"); + return 0; + } + + GeneratorContext context(t); + const float runtime_factor = 4.5f; // Demonstrate (and test) various ways to use a Stub to invoke a Generator with the JIT.