Skip to content

Commit

Permalink
[tint][build] Generate benchmarks for GN and Bazel
Browse files Browse the repository at this point in the history
These were not emitted, or were emitted incorrectly.

Aside from fuzzers, CMake, GN and Bazel now all generate the same executable, library, test and benchmark targets.

Change-Id: I88c115d4fb974755fc7c476694f4ef79d6e18e49
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/150860
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
  • Loading branch information
ben-clayton authored and Dawn LUCI CQ committed Sep 29, 2023
1 parent 6d8662d commit 9d1b610
Show file tree
Hide file tree
Showing 101 changed files with 891 additions and 381 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ group("all") {
"src/tint/api",
]
if (tint_build_unittests) {
deps += [ "src/tint/cmd/test" ]
deps += [ "src/tint/cmd/test:test_cmd" ]
}
if (dawn_standalone) {
deps += [
Expand Down
5 changes: 5 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ local_repository(
path = "third_party/abseil-cpp",
)

local_repository(
name = "benchmark",
path = "third_party/google_benchmark/src",
)

local_repository(
name = "gtest",
path = "third_party/googletest",
Expand Down
30 changes: 17 additions & 13 deletions docs/tint/gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ There are 6 kinds of build target:
production code.
* `bench_cmd` are benchmark executables.

The build generator uses a file naming convention to classify each source file to a single target kind:

* Source files with a `_test` suffix before the file extension are classed as
`test` library targets. Example: `parser_test.cc`.
* Source files with a `_bench` suffix before the file extension are classed as
`bench` library targets. Example: `writer_bench.cc`.
* Source files with the name `main.cc` are classed as executable targets.
These typically exist under `src/tint/cmd`. Example: `cmd/tint/main.cc`.
* Source files with the name `main_test.cc` are classed as test executable targets.
These typically exist under `src/tint/cmd`. Example: `cmd/test/main_test.cc`.
* Source files with the name `main_bench.cc` are classed as benchmark executable targets.
These typically exist under `src/tint/cmd`. Example: `cmd/benchmark/main_bench.cc`.
* All other files are considered `lib` targets. Example: `parser.cc`.
The build generator uses a file naming convention based on the file name before the extension to classify each source file to a single target kind.

* Source files named `test` or with a `_test` suffix are classed as `test` library targets. \
Example: `parser_test.cc`.
* Source files named `bench` or with a `_bench` suffix are classed as `bench` library targets. \
Example: `writer_bench.cc`.
* Source files with the name `main` are classed as executable targets.
These typically exist under `src/tint/cmd`. \
Example: `cmd/tint/main.cc`.
* Source files with the name `main_test` are classed as test executable targets.
These typically exist under `src/tint/cmd`. \
Example: `cmd/test/main_test.cc`.
* Source files with the name `main_bench` are classed as benchmark executable targets.
These typically exist under `src/tint/cmd`. \
Example: `cmd/benchmark/main_bench.cc`.
* All other files are considered `lib` targets. \
Example: `parser.cc`.

Each source directory can have at most one `lib`, `test`, `test_main`, `bench`, `bench_main` or `cmd`
target.
Expand Down
5 changes: 5 additions & 0 deletions scripts/tint_overrides_with_defaults.gni
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ declare_args() {
if (!defined(tint_build_unittests)) {
tint_build_unittests = true
}

# Build benchmarks
if (!defined(tint_build_benchmarks)) {
tint_build_benchmarks = true
}
}

declare_args() {
Expand Down
12 changes: 11 additions & 1 deletion src/tint/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ if (tint_build_unittests) {
}
}

if (tint_build_benchmarks) {
group("google_benchmark") {
testonly = true
public_deps = [
"//third_party/google_benchmark",
"//third_party/google_benchmark:benchmark_main",
]
}
}

group("abseil") {
# When build_with_chromium=true we need to include "//third_party/abseil-cpp:absl" while
# it's beneficial to be more specific with standalone Dawn, especially when it comes to
Expand All @@ -215,6 +225,6 @@ source_set("winsock") {
if (tint_build_unittests) {
group("tint_unittests") {
testonly = true
public_deps = [ "${tint_src_dir}/cmd/test" ]
public_deps = [ "${tint_src_dir}/cmd/test:test_cmd" ]
}
}
15 changes: 8 additions & 7 deletions src/tint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,6 @@ endfunction()

function(tint_bench_compile_options TARGET)
tint_core_compile_options(${TARGET})
set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks")
target_link_libraries(${TARGET} PRIVATE benchmark::benchmark)
if(TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER)
target_compile_definitions(${TARGET} PRIVATE
"TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER=\"${TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER}\""
)
endif()
endfunction()

function(tint_fuzz_compile_options TARGET)
Expand Down Expand Up @@ -456,6 +449,14 @@ function(tint_target_add_external_dependencies TARGET KIND)
target_link_libraries(${TARGET} PRIVATE
glslang-default-resource-limits
)
elseif(${DEPENDENCY} STREQUAL "google-benchmark")
set_target_properties(${TARGET} PROPERTIES FOLDER "Benchmarks")
target_link_libraries(${TARGET} PRIVATE benchmark::benchmark)
if(TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER)
target_compile_definitions(${TARGET} PRIVATE
"TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER=\"${TINT_BENCHMARK_EXTERNAL_SHADERS_HEADER}\""
)
endif()
elseif(${DEPENDENCY} STREQUAL "gtest")
target_include_directories(${TARGET} PRIVATE ${gmock_SOURCE_DIR}/include)
target_link_libraries(${TARGET} PRIVATE gmock)
Expand Down
33 changes: 17 additions & 16 deletions src/tint/cmd/bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,44 @@ load("//src/tint:flags.bzl", "COPTS")
load("@bazel_skylib//lib:selects.bzl", "selects")
cc_library(
name = "bench",
alwayslink = True,
srcs = [
"benchmark.cc",
],
hdrs = [
"bench.cc",
"bench.h",
],
deps = [
"//src/tint/api/common",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/ir",
"//src/tint/lang/core/type",
"//src/tint/lang/spirv/reader/common",
"//src/tint/lang/wgsl",
"//src/tint/lang/wgsl/ast",
"//src/tint/lang/wgsl/program",
"//src/tint/lang/wgsl/reader",
"//src/tint/lang/wgsl/sem",
"//src/tint/lang/wgsl/writer",
"//src/tint/utils/containers",
"//src/tint/utils/diagnostic",
"//src/tint/utils/ice",
"//src/tint/utils/id",
"//src/tint/utils/macros",
"//src/tint/utils/math",
"//src/tint/utils/memory",
"//src/tint/utils/reflection",
"//src/tint/utils/result",
"//src/tint/utils/rtti",
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
],
"@benchmark",
] + select({
":tint_build_spv_reader": [
"//src/tint/lang/spirv/reader",
],
"//conditions:default": [],
}),
copts = COPTS,
visibility = ["//visibility:public"],
)
Expand All @@ -61,21 +72,16 @@ cc_binary(
"main_bench.cc",
],
deps = [
"//src/tint/api/common",
"//src/tint/cmd/bench",
"//src/tint/cmd/bench:bench",
"//src/tint/lang/core",
"//src/tint/lang/core/constant",
"//src/tint/lang/core/ir",
"//src/tint/lang/core/type",
"//src/tint/lang/core:bench",
"//src/tint/lang/spirv/reader/common",
"//src/tint/lang/wgsl",
"//src/tint/lang/wgsl/ast",
"//src/tint/lang/wgsl/program",
"//src/tint/lang/wgsl/reader",
"//src/tint/lang/wgsl/reader:bench",
"//src/tint/lang/wgsl/sem",
"//src/tint/lang/wgsl/writer",
"//src/tint/lang/wgsl/writer:bench",
"//src/tint/lang/wgsl:bench",
"//src/tint/utils/containers",
Expand All @@ -85,13 +91,13 @@ cc_binary(
"//src/tint/utils/macros",
"//src/tint/utils/math",
"//src/tint/utils/memory",
"//src/tint/utils/reflection",
"//src/tint/utils/result",
"//src/tint/utils/rtti",
"//src/tint/utils/rtti:bench",
"//src/tint/utils/symbol",
"//src/tint/utils/text",
"//src/tint/utils/traits",
"@benchmark",
] + select({
":tint_build_glsl_writer": [
"//src/tint/lang/glsl/writer:bench",
Expand All @@ -107,11 +113,6 @@ cc_binary(
"//src/tint/lang/msl/writer:bench",
],
"//conditions:default": [],
}) + select({
":tint_build_spv_reader": [
"//src/tint/lang/spirv/reader",
],
"//conditions:default": [],
}) + select({
":tint_build_spv_writer": [
"//src/tint/lang/spirv/writer:bench",
Expand Down
94 changes: 51 additions & 43 deletions src/tint/cmd/bench/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@
################################################################################

################################################################################
# Target: tint_cmd_bench
# Kind: lib
# Target: tint_cmd_bench_bench_cmd
# Kind: bench_cmd
################################################################################
tint_add_target(tint_cmd_bench lib
cmd/bench/bench.h
cmd/bench/benchmark.cc
tint_add_target(tint_cmd_bench_bench_cmd bench_cmd
cmd/bench/main_bench.cc
)

tint_target_add_dependencies(tint_cmd_bench lib
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_cmd_bench_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_type
tint_lang_core_bench
tint_lang_wgsl
tint_lang_wgsl_ast
tint_lang_wgsl_program
tint_lang_wgsl_reader_bench
tint_lang_wgsl_sem
tint_lang_wgsl_writer_bench
tint_lang_wgsl_bench
tint_utils_containers
tint_utils_diagnostic
tint_utils_ice
Expand All @@ -47,37 +51,64 @@ tint_target_add_dependencies(tint_cmd_bench lib
tint_utils_memory
tint_utils_result
tint_utils_rtti
tint_utils_rtti_bench
tint_utils_symbol
tint_utils_text
tint_utils_traits
)

tint_target_add_external_dependencies(tint_cmd_bench_bench_cmd bench_cmd
"google-benchmark"
)

if(TINT_BUILD_GLSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_glsl_writer_bench
)
endif(TINT_BUILD_GLSL_WRITER)

if(TINT_BUILD_HLSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_hlsl_writer_bench
)
endif(TINT_BUILD_HLSL_WRITER)

if(TINT_BUILD_MSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_msl_writer_bench
)
endif(TINT_BUILD_MSL_WRITER)

if(TINT_BUILD_SPV_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_spirv_writer_bench
)
endif(TINT_BUILD_SPV_WRITER)

tint_target_set_output_name(tint_cmd_bench_bench_cmd bench_cmd "tint_benchmark")

################################################################################
# Target: tint_cmd_bench_bench_cmd
# Kind: bench_cmd
# Target: tint_cmd_bench_bench
# Kind: bench
################################################################################
tint_add_target(tint_cmd_bench_bench_cmd bench_cmd
cmd/bench/main_bench.cc
tint_add_target(tint_cmd_bench_bench bench
cmd/bench/bench.cc
cmd/bench/bench.h
)

tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_target_add_dependencies(tint_cmd_bench_bench bench
tint_api_common
tint_cmd_bench
tint_lang_core
tint_lang_core_constant
tint_lang_core_ir
tint_lang_core_type
tint_lang_core_bench
tint_lang_spirv_reader_common
tint_lang_wgsl
tint_lang_wgsl_ast
tint_lang_wgsl_program
tint_lang_wgsl_reader
tint_lang_wgsl_reader_bench
tint_lang_wgsl_sem
tint_lang_wgsl_writer
tint_lang_wgsl_writer_bench
tint_lang_wgsl_bench
tint_utils_containers
tint_utils_diagnostic
tint_utils_ice
Expand All @@ -88,40 +119,17 @@ tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_utils_reflection
tint_utils_result
tint_utils_rtti
tint_utils_rtti_bench
tint_utils_symbol
tint_utils_text
tint_utils_traits
)

if(TINT_BUILD_GLSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_glsl_writer_bench
)
endif(TINT_BUILD_GLSL_WRITER)

if(TINT_BUILD_HLSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_hlsl_writer_bench
)
endif(TINT_BUILD_HLSL_WRITER)

if(TINT_BUILD_MSL_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_msl_writer_bench
)
endif(TINT_BUILD_MSL_WRITER)
tint_target_add_external_dependencies(tint_cmd_bench_bench bench
"google-benchmark"
)

if(TINT_BUILD_SPV_READER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_target_add_dependencies(tint_cmd_bench_bench bench
tint_lang_spirv_reader
)
endif(TINT_BUILD_SPV_READER)

if(TINT_BUILD_SPV_WRITER)
tint_target_add_dependencies(tint_cmd_bench_bench_cmd bench_cmd
tint_lang_spirv_writer_bench
)
endif(TINT_BUILD_SPV_WRITER)

tint_target_set_output_name(tint_cmd_bench_bench_cmd bench_cmd "tint_benchmark")
Loading

0 comments on commit 9d1b610

Please sign in to comment.