Skip to content

Commit 95774ba

Browse files
committed
added benchmark script for apx testing
1 parent 1ee6c0c commit 95774ba

5 files changed

Lines changed: 181 additions & 26 deletions

File tree

CMakePresets.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"scripts/cmake-presets/release.json",
1616
"scripts/cmake-presets/integrate.json",
1717
"scripts/cmake-presets/performance.json",
18-
"scripts/cmake-presets/public.json"
18+
"scripts/cmake-presets/public.json",
19+
"scripts/benchmark/presets.json"
1920
],
2021
"configurePresets": [
2122

common/cmake/clang.cmake

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ IF (EMBREE_ARM)
2323
ENDIF ()
2424
ELSE ()
2525
# for `thread` keyword
26-
_SET_IF_EMPTY(FLAGS_SSE2 "-msse -msse2 -mno-sse4.2")
27-
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2")
28-
_SET_IF_EMPTY(FLAGS_AVX "-mavx")
29-
_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2")
30-
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
31-
_SET_IF_EMPTY(FLAGS_APX "-march=skx -mapxf")
26+
IF (ENABLE_APX)
27+
_SET_IF_EMPTY(FLAGS_SSE2 "-msse -msse2 -mno-sse4.2 -mapxf")
28+
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2 -mapxf")
29+
_SET_IF_EMPTY(FLAGS_AVX "-mavx -mapxf")
30+
_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2 -mapxf")
31+
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx -mapxf")
32+
#_SET_IF_EMPTY(FLAGS_APX "-march=skx -mapxf")
33+
ELSE ()
34+
_SET_IF_EMPTY(FLAGS_SSE2 "-msse -msse2 -mno-sse4.2")
35+
_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2")
36+
_SET_IF_EMPTY(FLAGS_AVX "-mavx")
37+
_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2")
38+
_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx")
39+
ENDIF ()
3240
ENDIF ()
3341

3442
IF (WIN32)

kernels/CMakeLists.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,6 @@ IF (EMBREE_ISA_AVX512 AND EMBREE_LIBRARY_FILES_AVX512)
348348
ENDIF()
349349
ENDIF()
350350

351-
IF (EMBREE_ISA_APX AND EMBREE_LIBRARY_FILES_APX)
352-
message("APXAPXAPXAPXAPXAPXAPXAPXAPX")
353-
message("APXAPXAPXAPXAPXAPXAPXAPXAPX")
354-
message("APXAPXAPXAPXAPXAPXAPXAPXAPX")
355-
message("APXAPXAPXAPXAPXAPXAPXAPXAPX")
356-
message("${FLAGS_APX}")
357-
message("${EMBREE_LIBRARY_FILES_APX}")
358-
DISABLE_STACK_PROTECTOR_FOR_INTERSECTORS(${EMBREE_LIBRARY_FILES_APX})
359-
ADD_LIBRARY(embree_apx STATIC ${EMBREE_LIBRARY_FILES_APX})
360-
TARGET_LINK_LIBRARIES(embree_apx PRIVATE tasking)
361-
SET_TARGET_PROPERTIES(embree_apx PROPERTIES COMPILE_FLAGS "${FLAGS_APX}")
362-
SET_PROPERTY(TARGET embree_apx PROPERTY FOLDER kernels)
363-
SET(EMBREE_LIBRARIES ${EMBREE_LIBRARIES} embree_apx)
364-
CheckGlobals(embree_apx)
365-
IF (EMBREE_STATIC_LIB)
366-
INSTALL(TARGETS embree_apx EXPORT embree_apx-targets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT devel)
367-
INSTALL(EXPORT embree_apx-targets DESTINATION "${EMBREE_CMAKEEXPORT_DIR}" COMPONENT devel)
368-
ENDIF()
369-
ENDIF()
370351

371352

372353
TARGET_LINK_LIBRARIES(embree PRIVATE ${EMBREE_LIBRARIES} sys math simd lexers tasking)

scripts/benchmark/bench.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import os
2+
import json
3+
import argparse
4+
import subprocess
5+
6+
# Parse arguments
7+
parser = argparse.ArgumentParser(description="Benchmark script")
8+
parser.add_argument('--presets', nargs='*', default=[], help="Whitelist of presets, defaults to all presets if not specified")
9+
parser.add_argument('--models', default="", help="Path to embree models repository, accepts 'git clone' to clone into current path")
10+
parser.add_argument('--size', nargs=2, type=int, default=[2048, 2048], help="Width and height (default: 2048 2048)")
11+
parser.add_argument('--out', default="./benchmarks_out", help="Output directory for benchmark results (default: benchmarks_out)")
12+
args = parser.parse_args()
13+
14+
15+
# Ensure the current working directory is the root directory of the repository
16+
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
17+
os.chdir(repo_root)
18+
print(f"Changed working directory to repository root: {repo_root}")
19+
20+
21+
# PRESETS #
22+
###########
23+
with open("./scripts/benchmark/presets.json", 'r') as file:
24+
presets_data = json.load(file)
25+
26+
presets = []
27+
for p in presets_data["configurePresets"]:
28+
if not args.presets or p["name"] in args.presets:
29+
presets.append(p["name"])
30+
31+
for p in args.presets:
32+
if p not in presets:
33+
print(f"WARNING: Unknown preset '{p}' ignored.")
34+
35+
36+
37+
# BUILD EMBREE #
38+
################
39+
for preset in presets:
40+
print(f"Building embree with preset: {preset}")
41+
try:
42+
subprocess.run(["cmake", "-S", ".", "-B", f"build-{preset}", "--preset", preset], check=True)
43+
subprocess.run(["cmake", "--build", f"build-{preset}", "-j8"], check=True)
44+
except subprocess.CalledProcessError as e:
45+
print(f"Error while building embree with preset {preset}:\n{e.stderr}")
46+
continue
47+
48+
49+
# MODELS #
50+
##########
51+
if args.models == "git clone":
52+
print("Cloning embree models repository...")
53+
os.system(f"git lfs install")
54+
os.system(f"git clone https://github.com/intel-innersource/libraries.graphics.renderkit.embree.models.git ./embree-models")
55+
models_repo = os.path.abspath("./embree-models")
56+
else:
57+
models_repo = os.path.abspath(args.models)
58+
59+
ecs_files = []
60+
for root, _, files in os.walk(models_repo):
61+
for file in files:
62+
if file.endswith(".ecs"):
63+
ecs_files.append(os.path.join(root, file))
64+
65+
# Check for duplicate filenames in ecs_files
66+
filenames = [os.path.basename(ecs) for ecs in ecs_files]
67+
duplicates = set([name for name in filenames if filenames.count(name) > 1])
68+
69+
if duplicates:
70+
for duplicate in duplicates:
71+
print(f"WARNING: Duplicate filename detected: {duplicate}")
72+
73+
74+
# RUN BENCHMARKS #
75+
##################
76+
77+
def runbench(preset, exe, ecs):
78+
print(os.path.abspath(f"./{args.out}/viewer_{preset}_{os.path.basename(ecs)[:-4]}.json"))
79+
cmd = [
80+
f"./build-{preset}/{exe}",
81+
"-c", ecs,
82+
"--size", f"{args.size[0]}", f"{args.size[1]}",
83+
"--benchmark", "1", "8", f"--benchmark_out={os.path.abspath(f"./{args.out}/viewer_{preset}_{os.path.basename(ecs)[:-4]}.json")}"
84+
]
85+
try:
86+
print(f"embree viewer {preset}: {ecs} ...")
87+
result = subprocess.run(cmd, check=True, text=True, capture_output=True)
88+
print(result.stdout)
89+
except subprocess.CalledProcessError as e:
90+
print(f"Error while processing {ecs} with preset {preset}:\n{e.stderr}")
91+
92+
93+
# Ensure the output directory exists
94+
if not os.path.exists(args.out):
95+
os.makedirs(args.out)
96+
print(f"Created output directory: {args.out}")
97+
98+
99+
for preset in presets:
100+
for ecs in ecs_files:
101+
if not "crown.ecs" in ecs:
102+
continue
103+
104+
runbench(preset, "embree_viewer", ecs)
105+
#runbench(preset, "embree_pathtracer", ecs)
106+
107+
108+

scripts/benchmark/presets.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"version": 4,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 11,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "bench",
11+
"binaryDir": "${sourceDir}/build",
12+
"cacheVariables": {
13+
"CMAKE_C_COMPILER": "clang",
14+
"CMAKE_CXX_COMPILER": "clang++",
15+
"CMAKE_BUILD_TYPE": "Release",
16+
"EMBREE_MAX_ISA": "AVX2",
17+
"EMBREE_TASKING_SYSTEM": "TBB",
18+
"TBB_DIR": "/home/dopitz/tbb-2022.1.0/lib/cmake/tbb",
19+
"EMBREE_ZIP_MODE": "ON",
20+
"EMBREE_INSTALL_DEPENDENCIES": "ON",
21+
"EMBREE_BUILD_GLFW_FROM_SOURCE": "ON",
22+
"EMBREE_PATCH_GLFW_SOURCE": "ON",
23+
"CMAKE_INSTALL_INCLUDEDIR": "include",
24+
"CMAKE_INSTALL_LIBDIR": "lib",
25+
"CMAKE_INSTALL_DOCDIR": "doc",
26+
"CMAKE_INSTALL_BINDIR": "bin",
27+
"CMAKE_INSTALL_TESTDIR": "testing",
28+
"EMBREE_USE_GOOGLE_BENCHMARK": "ON",
29+
"EMBREE_BUILD_GOOGLE_BENCHMARK_FROM_SOURCE": "ON"
30+
}
31+
},
32+
{
33+
"name": "bench-apx",
34+
"binaryDir": "${sourceDir}/build",
35+
"cacheVariables": {
36+
"CMAKE_C_COMPILER": "clang",
37+
"CMAKE_CXX_COMPILER": "clang++",
38+
"CMAKE_BUILD_TYPE": "Release",
39+
"EMBREE_MAX_ISA": "AVX2",
40+
"ENABLE_APX": "ON",
41+
"EMBREE_TASKING_SYSTEM": "TBB",
42+
"TBB_DIR": "/home/dopitz/tbb-2022.1.0/lib/cmake/tbb",
43+
"EMBREE_ZIP_MODE": "ON",
44+
"EMBREE_INSTALL_DEPENDENCIES": "ON",
45+
"EMBREE_BUILD_GLFW_FROM_SOURCE": "ON",
46+
"EMBREE_PATCH_GLFW_SOURCE": "ON",
47+
"CMAKE_INSTALL_INCLUDEDIR": "include",
48+
"CMAKE_INSTALL_LIBDIR": "lib",
49+
"CMAKE_INSTALL_DOCDIR": "doc",
50+
"CMAKE_INSTALL_BINDIR": "bin",
51+
"CMAKE_INSTALL_TESTDIR": "testing",
52+
"EMBREE_USE_GOOGLE_BENCHMARK": "ON",
53+
"EMBREE_BUILD_GOOGLE_BENCHMARK_FROM_SOURCE": "ON"
54+
}
55+
}
56+
]
57+
}

0 commit comments

Comments
 (0)