SR-4572 Remove jinja2 dependency from benchmark test harness generation

This commit is contained in:
Pavol Vaskovic
2017-05-02 16:20:30 +02:00
parent 6150894902
commit bdffb35d17
7 changed files with 227 additions and 316 deletions

View File

@@ -1,181 +0,0 @@
# -*- mode: cmake -*-
################################################################################
# WARNING: This file is automatically generated from templates and should not
# be directly modified. Instead, make changes to
# scripts/generate_harness/CMakeLists.txt_template and run
# scripts/generate_harness/generate_harness.py to regenerate this file.
################################################################################
cmake_minimum_required(VERSION 2.8.12)
# Add path for custom CMake modules.
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(AddSwiftBenchmarkSuite)
set(SWIFT_BENCH_MODULES
{% for test in tests %}
single-source/{{ test }}
{% endfor %}
)
set(SWIFT_MULTISOURCE_BENCHES
{% for multisource_bench in multisource_benches %}
multi-source/{{ multisource_bench.name }}
{% endfor %}
)
{% for multisource_bench in multisource_benches %}
set({{ multisource_bench.name }}_sources
{% for file in multisource_bench.files %}
multi-source/{{ multisource_bench.name }}/{{ file }}
{% endfor %}
)
{% endfor %}
set(BENCH_DRIVER_LIBRARY_MODULES
utils/DriverUtils
utils/TestsUtils
)
set(BENCH_DRIVER_LIBRARY_FLAGS)
if (SWIFT_RUNTIME_ENABLE_LEAK_CHECKER)
set(BENCH_DRIVER_LIBRARY_FLAGS -DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER)
endif()
set(BENCH_LIBRARY_MODULES
)
add_definitions(-DSWIFT_EXEC -DSWIFT_LIBRARY_PATH -DONLY_PLATFORMS
-DSWIFT_OPTIMIZATION_LEVELS -DSWIFT_BENCHMARK_EMIT_SIB)
if(NOT ONLY_PLATFORMS)
set(ONLY_PLATFORMS "macosx" "iphoneos" "appletvos" "watchos")
endif()
if(NOT SWIFT_EXEC)
runcmd(COMMAND "xcrun" "-f" "swiftc"
VARIABLE SWIFT_EXEC
ERROR "Unable to find Swift driver")
endif()
if(NOT SWIFT_LIBRARY_PATH)
get_filename_component(tmp_dir "${SWIFT_EXEC}" DIRECTORY)
get_filename_component(tmp_dir "${tmp_dir}" DIRECTORY)
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
endif()
# If the CMAKE_C_COMPILER is already clang, don't find it again,
# thus allowing the --host-cc build-script argument to work here.
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
if(${c_compiler} STREQUAL "clang")
set(CLANG_EXEC ${CMAKE_C_COMPILER})
else()
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
VARIABLE CLANG_EXEC
ERROR "Unable to find Clang driver")
endif()
# You have to delete CMakeCache.txt in the swift build to force a
# reconfiguration.
set(SWIFT_EXTRA_BENCH_CONFIGS CACHE STRING
"A semicolon separated list of benchmark configurations. \
Available configurations: <Optlevel>_SINGLEFILE, <Optlevel>_MULTITHREADED")
# Syntax for an optset: <optimization-level>_<configuration>
# where "_<configuration>" is optional.
if(NOT SWIFT_OPTIMIZATION_LEVELS)
set(SWIFT_OPTIMIZATION_LEVELS "Onone" "O" "Ounchecked"
${SWIFT_EXTRA_BENCH_CONFIGS})
endif()
set(SWIFT_BENCHMARK_NUM_O_ITERATIONS "" CACHE STRING
"Number of iterations to perform when running -O benchmarks via cmake")
set(SWIFT_BENCHMARK_NUM_ONONE_ITERATIONS "" CACHE STRING
"Number of iterations to perform when running -Onone benchmarks via cmake")
# Options for the default (= empty) configuration
set(BENCHOPTS "-whole-module-optimization")
# Options for other configurations
set(BENCHOPTS_MULTITHREADED
"-whole-module-optimization" "-num-threads" "4")
set(BENCHOPTS_SINGLEFILE "")
set(macosx_arch "x86_64")
set(iphoneos_arch "arm64" "armv7")
set(appletvos_arch "arm64")
set(watchos_arch "armv7k")
set(macosx_ver "10.9")
set(iphoneos_ver "8.0")
set(appletvos_ver "9.1")
set(watchos_ver "2.0")
set(macosx_triple_platform "macosx")
set(iphoneos_triple_platform "ios")
set(appletvos_triple_platform "tvos")
set(watchos_triple_platform "watchos")
set(sdks)
set(platforms)
foreach(platform ${ONLY_PLATFORMS})
execute_process(
COMMAND "xcrun" "--sdk" "${platform}" "--show-sdk-path"
OUTPUT_VARIABLE ${platform}_sdk
RESULT_VARIABLE result
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${result}" MATCHES "0")
list(APPEND sdks "${${platform}_sdk}")
list(APPEND platforms ${platform})
endif()
endforeach()
message("--")
message("-- Swift Benchmark Suite:")
message("-- SWIFT_EXEC = ${SWIFT_EXEC}")
message("-- SWIFT_LIBRARY_PATH = ${SWIFT_LIBRARY_PATH}")
message("-- CLANG_EXEC = ${CLANG_EXEC}")
message("-- SWIFT_OPTIMIZATION_LEVELS = ${SWIFT_OPTIMIZATION_LEVELS}")
message("-- ONLY_PLATFORMS = ${ONLY_PLATFORMS}")
message("-- found platforms: ${platforms}")
message("-- found sdks:")
foreach(sdk ${sdks})
message("-- ${sdk}")
endforeach()
set(executable_targets)
if(SWIFT_SDKS)
set(IS_SWIFT_BUILD true)
endif()
set(srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
if(IS_SWIFT_BUILD)
get_filename_component(swift-bin-dir "${SWIFT_EXEC}" DIRECTORY)
else()
set(swift-bin-dir "${CMAKE_BINARY_DIR}/bin")
endif()
set(benchmark-bin-dir "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(benchmark-lib-dir "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(benchmark-lib-swift-dir "${CMAKE_CURRENT_BINARY_DIR}/lib/swift")
file(MAKE_DIRECTORY "${swift-bin-dir}")
file(MAKE_DIRECTORY "${benchmark-bin-dir}")
file(MAKE_DIRECTORY "${benchmark-lib-dir}")
file(MAKE_DIRECTORY "${benchmark-lib-swift-dir}")
# Compile the perf test suite for each platform
foreach(platform ${platforms})
swift_benchmark_compile(PLATFORM ${platform})
endforeach()
add_subdirectory(scripts)

View File

@@ -18,16 +18,11 @@ from __future__ import print_function
import argparse
import os
import re
import subprocess
import jinja2
script_dir = os.path.dirname(os.path.realpath(__file__))
perf_dir = os.path.realpath(os.path.join(script_dir, '../..'))
gyb = os.path.realpath(os.path.join(perf_dir, '../utils/gyb'))
single_source_dir = os.path.join(perf_dir, 'single-source')
multi_source_dir = os.path.join(perf_dir, 'multi-source')
parser = argparse.ArgumentParser()
parser.add_argument("--output-dir",
help="Output directory (for validation test)",
@@ -35,138 +30,6 @@ parser.add_argument("--output-dir",
args = parser.parse_args()
output_dir = args.output_dir
template_map = {
'CMakeLists.txt_template': os.path.join(output_dir, 'CMakeLists.txt'),
'main.swift_template': os.path.join(output_dir, 'utils/main.swift')
}
# The test suites. Currently, "other" and "string"
other_tests = [
"Ackermann",
"Fibonacci",
"ExistentialTestArrayConditionalShift_ClassValueBuffer1",
"ExistentialTestArrayConditionalShift_ClassValueBuffer2",
"ExistentialTestArrayConditionalShift_ClassValueBuffer3",
"ExistentialTestArrayConditionalShift_ClassValueBuffer4",
"ExistentialTestArrayConditionalShift_IntValueBuffer0",
"ExistentialTestArrayConditionalShift_IntValueBuffer1",
"ExistentialTestArrayConditionalShift_IntValueBuffer2",
"ExistentialTestArrayConditionalShift_IntValueBuffer3",
"ExistentialTestArrayConditionalShift_IntValueBuffer4",
"ExistentialTestArrayMutating_ClassValueBuffer1",
"ExistentialTestArrayMutating_ClassValueBuffer2",
"ExistentialTestArrayMutating_ClassValueBuffer3",
"ExistentialTestArrayMutating_ClassValueBuffer4",
"ExistentialTestArrayMutating_IntValueBuffer0",
"ExistentialTestArrayMutating_IntValueBuffer1",
"ExistentialTestArrayMutating_IntValueBuffer2",
"ExistentialTestArrayMutating_IntValueBuffer3",
"ExistentialTestArrayMutating_IntValueBuffer4",
"ExistentialTestArrayOneMethodCall_ClassValueBuffer1",
"ExistentialTestArrayOneMethodCall_ClassValueBuffer2",
"ExistentialTestArrayOneMethodCall_ClassValueBuffer3",
"ExistentialTestArrayOneMethodCall_ClassValueBuffer4",
"ExistentialTestArrayOneMethodCall_IntValueBuffer0",
"ExistentialTestArrayOneMethodCall_IntValueBuffer1",
"ExistentialTestArrayOneMethodCall_IntValueBuffer2",
"ExistentialTestArrayOneMethodCall_IntValueBuffer3",
"ExistentialTestArrayOneMethodCall_IntValueBuffer4",
"ExistentialTestArrayShift_ClassValueBuffer1",
"ExistentialTestArrayShift_ClassValueBuffer2",
"ExistentialTestArrayShift_ClassValueBuffer3",
"ExistentialTestArrayShift_ClassValueBuffer4",
"ExistentialTestArrayShift_IntValueBuffer0",
"ExistentialTestArrayShift_IntValueBuffer1",
"ExistentialTestArrayShift_IntValueBuffer2",
"ExistentialTestArrayShift_IntValueBuffer3",
"ExistentialTestArrayShift_IntValueBuffer4",
"ExistentialTestArrayTwoMethodCalls_ClassValueBuffer1",
"ExistentialTestArrayTwoMethodCalls_ClassValueBuffer2",
"ExistentialTestArrayTwoMethodCalls_ClassValueBuffer3",
"ExistentialTestArrayTwoMethodCalls_ClassValueBuffer4",
"ExistentialTestArrayTwoMethodCalls_IntValueBuffer0",
"ExistentialTestArrayTwoMethodCalls_IntValueBuffer1",
"ExistentialTestArrayTwoMethodCalls_IntValueBuffer2",
"ExistentialTestArrayTwoMethodCalls_IntValueBuffer3",
"ExistentialTestArrayTwoMethodCalls_IntValueBuffer4",
"ExistentialTestMutatingAndNonMutating_ClassValueBuffer1",
"ExistentialTestMutatingAndNonMutating_ClassValueBuffer2",
"ExistentialTestMutatingAndNonMutating_ClassValueBuffer3",
"ExistentialTestMutatingAndNonMutating_ClassValueBuffer4",
"ExistentialTestMutatingAndNonMutating_IntValueBuffer0",
"ExistentialTestMutatingAndNonMutating_IntValueBuffer1",
"ExistentialTestMutatingAndNonMutating_IntValueBuffer2",
"ExistentialTestMutatingAndNonMutating_IntValueBuffer3",
"ExistentialTestMutatingAndNonMutating_IntValueBuffer4",
"ExistentialTestMutating_ClassValueBuffer1",
"ExistentialTestMutating_ClassValueBuffer2",
"ExistentialTestMutating_ClassValueBuffer3",
"ExistentialTestMutating_ClassValueBuffer4",
"ExistentialTestMutating_IntValueBuffer0",
"ExistentialTestMutating_IntValueBuffer1",
"ExistentialTestMutating_IntValueBuffer2",
"ExistentialTestMutating_IntValueBuffer3",
"ExistentialTestMutating_IntValueBuffer4",
"ExistentialTestOneMethodCall_ClassValueBuffer1",
"ExistentialTestOneMethodCall_ClassValueBuffer2",
"ExistentialTestOneMethodCall_ClassValueBuffer3",
"ExistentialTestOneMethodCall_ClassValueBuffer4",
"ExistentialTestOneMethodCall_IntValueBuffer0",
"ExistentialTestOneMethodCall_IntValueBuffer1",
"ExistentialTestOneMethodCall_IntValueBuffer2",
"ExistentialTestOneMethodCall_IntValueBuffer3",
"ExistentialTestOneMethodCall_IntValueBuffer4",
"ExistentialTestPassExistentialOneMethodCall_ClassValueBuffer1",
"ExistentialTestPassExistentialOneMethodCall_ClassValueBuffer2",
"ExistentialTestPassExistentialOneMethodCall_ClassValueBuffer3",
"ExistentialTestPassExistentialOneMethodCall_ClassValueBuffer4",
"ExistentialTestPassExistentialOneMethodCall_IntValueBuffer0",
"ExistentialTestPassExistentialOneMethodCall_IntValueBuffer1",
"ExistentialTestPassExistentialOneMethodCall_IntValueBuffer2",
"ExistentialTestPassExistentialOneMethodCall_IntValueBuffer3",
"ExistentialTestPassExistentialOneMethodCall_IntValueBuffer4",
"ExistentialTestPassExistentialTwoMethodCalls_ClassValueBuffer1",
"ExistentialTestPassExistentialTwoMethodCalls_ClassValueBuffer2",
"ExistentialTestPassExistentialTwoMethodCalls_ClassValueBuffer3",
"ExistentialTestPassExistentialTwoMethodCalls_ClassValueBuffer4",
"ExistentialTestPassExistentialTwoMethodCalls_IntValueBuffer0",
"ExistentialTestPassExistentialTwoMethodCalls_IntValueBuffer1",
"ExistentialTestPassExistentialTwoMethodCalls_IntValueBuffer2",
"ExistentialTestPassExistentialTwoMethodCalls_IntValueBuffer3",
"ExistentialTestPassExistentialTwoMethodCalls_IntValueBuffer4",
"ExistentialTestTwoMethodCalls_ClassValueBuffer1",
"ExistentialTestTwoMethodCalls_ClassValueBuffer2",
"ExistentialTestTwoMethodCalls_ClassValueBuffer3",
"ExistentialTestTwoMethodCalls_ClassValueBuffer4",
"ExistentialTestTwoMethodCalls_IntValueBuffer0",
"ExistentialTestTwoMethodCalls_IntValueBuffer1",
"ExistentialTestTwoMethodCalls_IntValueBuffer2",
"ExistentialTestTwoMethodCalls_IntValueBuffer3",
"ExistentialTestTwoMethodCalls_IntValueBuffer4",
]
string_tests = [
"StringWalkASCIIScalars",
"StringWalkASCIICharacters",
"StringWalkUnicodeScalars",
"StringWalkUnicodeCharacters",
"StringWalkMixedScalars",
"StringWalkMixedCharacters",
"StringWalkASCIIScalarsBackwards",
"StringWalkASCIICharactersBackwards",
"StringWalkUnicodeScalarsBackwards",
"StringWalkUnicodeCharactersBackwards",
"StringWalkMixedScalarsBackwards",
"StringWalkMixedCharactersBackwards",
]
ignored_run_funcs = other_tests + string_tests
template_loader = jinja2.FileSystemLoader(searchpath="/")
template_env = jinja2.Environment(loader=template_loader, trim_blocks=True,
lstrip_blocks=True)
def all_files(directory, extension): # matching: [directory]/**/*[extension]
return [
os.path.join(root, f)
@@ -185,58 +48,10 @@ def will_write(filename): # ensure path to file exists before writing
if __name__ == '__main__':
# Generate Your Boilerplate
gyb_files = all_files(perf_dir, '.gyb')
# FIXME make sure longer paths are done first,
# as CMakeLists and main.swift depend on the other gybs being generated first!
for f in gyb_files:
relative_path = os.path.relpath(f[:-4], perf_dir)
out_file = os.path.join(output_dir, relative_path)
will_write(out_file)
subprocess.call([gyb, '--line-directive', '', '-o', out_file, f])
# CMakeList single-source
test_files = all_files(single_source_dir, '.swift')
tests = sorted(os.path.basename(x).split('.')[0] for x in test_files)
# CMakeList multi-source
class MultiSourceBench(object):
def __init__(self, path):
self.name = os.path.basename(path)
self.files = [x for x in os.listdir(path)
if x.endswith('.swift')]
if os.path.isdir(multi_source_dir):
multisource_benches = [
MultiSourceBench(os.path.join(multi_source_dir, x))
for x in os.listdir(multi_source_dir)
if os.path.isdir(os.path.join(multi_source_dir, x))
]
else:
multisource_benches = []
# main.swift imports
imports = sorted(tests + [msb.name for msb in multisource_benches])
# main.swift run functions
def get_run_funcs(filepath):
content = open(filepath).read()
matches = re.findall(r'func run_(.*?)\(', content)
return filter(lambda x: x not in ignored_run_funcs, matches)
def find_run_funcs():
swift_files = all_files(perf_dir, '.swift')
return [func for f in swift_files for func in get_run_funcs(f)]
run_funcs = [(f, f) for f in sorted(find_run_funcs())]
# Replace originals with files generated from templates
for template_file in template_map:
template_path = os.path.join(script_dir, template_file)
template = template_env.get_template(template_path)
out_file = template_map[template_file]
will_write(out_file)
open(out_file, 'w').write(
template.render(tests=tests,
multisource_benches=multisource_benches,
imports=imports,
run_funcs=run_funcs,
string_tests=string_tests,
other_tests=other_tests)
)

View File

@@ -1,63 +0,0 @@
//===--- main.swift -------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
////////////////////////////////////////////////////////////////////////////////
// WARNING: This file is automatically generated from templates and should not
// be directly modified. Instead, make changes to
// scripts/generate_harness/main.swift_template and run
// scripts/generate_harness/generate_harness.py to regenerate this file.
////////////////////////////////////////////////////////////////////////////////
// This is just a driver for performance overview tests.
import TestsUtils
import DriverUtils
{% for import in imports %}
import {{ import }}
{% endfor %}
@inline(__always)
private func addPrecommitTest(
_ name: String, _ function: @escaping (Int) -> ()
) {
precommitTests[name] = function
}
@inline(__always)
private func addStringTest(
_ name: String, _ function: @escaping (Int) -> ()
) {
stringTests[name] = function
}
@inline(__always)
private func addOtherTest(
_ name: String, _ function: @escaping (Int) -> ()
) {
otherTests[name] = function
}
// The main test suite: precommit tests
{% for run_func in run_funcs %}
addPrecommitTest("{{ run_func[0] }}", run_{{ run_func[1] }})
{% endfor %}
// Other tests
{% for test_name in other_tests %}
addOtherTest("{{ test_name }}", run_{{ test_name }})
{% endfor %}
// String tests, an extended benchmark suite exercising finer-granularity
// behavior of our Strings.
{% for test_name in string_tests %}
addStringTest("{{ test_name }}", run_{{ test_name }})
{% endfor %}
main()