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

Add CMake build rules for (some) of the generator jit tests #7693

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
915c46d
Add CMake build rules for (some) of the generator jit tests
steven-johnson Jul 20, 2023
a9d1af2
Update CMakeLists.txt
steven-johnson Jul 20, 2023
d3554b0
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Jul 24, 2023
0a4a456
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Jul 24, 2023
4727660
Update CMakeLists.txt
steven-johnson Jul 24, 2023
d3d40ca
Fix JIT skipping
steven-johnson Jul 25, 2023
585abef
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Jul 25, 2023
f303262
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Jul 26, 2023
7e97703
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Aug 1, 2023
91a00df
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Aug 28, 2023
ec9acfb
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Sep 18, 2023
ca6a774
Update cmake/HalideGeneratorHelpers.cmake
steven-johnson Sep 18, 2023
29ce2cf
Update test/generator/CMakeLists.txt
steven-johnson Sep 18, 2023
25852f4
Merge branch 'srj/cmake-jit-generators' of https://github.com/halide/…
steven-johnson Sep 18, 2023
4f2e34c
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Nov 29, 2023
408c73c
Merge branch 'main' into srj/cmake-jit-generators
steven-johnson Aug 23, 2024
b47d787
Update cmake/HalideGeneratorHelpers.cmake
steven-johnson Aug 23, 2024
4e7de96
Update HalideGeneratorHelpers.cmake
steven-johnson Aug 23, 2024
8090fb9
trigger buildbots
steven-johnson Aug 23, 2024
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
12 changes: 10 additions & 2 deletions cmake/HalideGeneratorHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ 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})
target_include_directories("${TARGET}" PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: why is this needed? Which files do they access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, I don't remember. I'll remove it and see what breaks :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target_include_directories is apparently unnecessary, removing


# 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_OBJECTS:${TARGET}>")
target_link_libraries("${TARGET}.objs" INTERFACE Halide::Halide ${ARG_LINK_LIBRARIES})
target_include_directories("${TARGET}.objs" INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
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,
Expand Down Expand Up @@ -183,11 +190,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
Expand All @@ -202,6 +209,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")
Expand Down
1 change: 1 addition & 0 deletions src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
43 changes: 37 additions & 6 deletions test/generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function(_add_halide_libraries TARGET)
FEATURES "${args_FEATURES}"
PARAMS "${args_PARAMS}"
PLUGINS "${args_PLUGINS}"
CPP_STUB cpp_stub_out
alexreinking marked this conversation as resolved.
Show resolved Hide resolved
FUNCTION_INFO_HEADER function_info_header_out)
if (args_EXTERNS)
target_link_libraries(${TARGET} INTERFACE ${args_EXTERNS})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
8 changes: 7 additions & 1 deletion test/generator/configure_jittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ void verify(const Buffer<int32_t, 3> &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<int, 3> input(kSize, kSize, 3);
input.for_each_element([&](int x, int y, int c) {
Expand Down
9 changes: 8 additions & 1 deletion test/generator/example_jittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ void verify(const Buffer<int32_t, 3> &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.
Expand Down
Loading