Skip to content

Commit 2d6a17c

Browse files
add heracles tracer (w/ end-to-end example)
Note: `run_simple_tracing` target works up to expected functional modeler issue `key not found: partQHatInvModq_0_0` which is due to the fact that partQHatInvModq is no longer present in recent OpenFHE versions.
1 parent 69becbf commit 2d6a17c

File tree

7 files changed

+1174
-0
lines changed

7 files changed

+1174
-0
lines changed

.typos.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# variation of params
99
parms = "parms"
1010
bload = "bload"
11+
ser = "ser"
12+
SerType = "SerType"
1113

1214
[files]
1315
extend-exclude = [

p-isa_tools/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ message(ENABLE_DATA_FORMATS="${ENABLE_DATA_FORMATS}")
2828
option(ENABLE_FUNCTIONAL_MODELER "Enable building of functional modeler" ON)
2929
message(ENABLE_FUNCTIONAL_MODELER="${ENABLE_FUNCTIONAL_MODELER}")
3030

31+
option(ENABLE_KERNGEN "Enable kerngen (dependencies only)" ON)
32+
message(ENABLE_KERNGEN="${ENABLE_KERNGEN}")
33+
3134
option(ENABLE_PROGRAM_MAPPER "Enable building of program mapper" ON)
3235
message(ENABLE_PROGRAM_MAPPER="${ENABLE_PROGRAM_MAPPER}")
3336

@@ -63,6 +66,9 @@ file(GLOB_RECURSE IDE_HEADERS program_mapper/*.h functional_modeler/*.h dependen
6366

6467
# Build sub-directories
6568
add_subdirectory(common)
69+
if(ENABLE_KERNGEN)
70+
add_subdirectory(kerngen)
71+
endif()
6672
if(ENABLE_DATA_FORMATS)
6773
add_subdirectory(data_formats)
6874
endif()

p-isa_tools/data_formats/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ add_custom_command(
5050
POST_BUILD
5151
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/python ${PROJECT_BINARY_DIR}/python/
5252
)
53+
54+
option(ENABLE_OPENFHE_TRACER "Build the openfhe tracer" ON)
55+
if(ENABLE_OPENFHE_TRACER)
56+
add_subdirectory(openfhe_tracer)
57+
endif()
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Include FetchContent module
2+
include(FetchContent)
3+
4+
# Add OpenFHE via FetchContent
5+
FetchContent_Declare(
6+
OpenFHE
7+
GIT_REPOSITORY https://github.com/AlexanderViand/openfhe-development.git
8+
GIT_TAG 274e470b99495d571a1f6008578601b99e569d84 # head of `tracing` branch (2025-07-28)
9+
)
10+
11+
# Set OpenFHE build options before making it available
12+
set(BUILD_UNITTESTS OFF CACHE BOOL "" FORCE)
13+
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
14+
set(BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
15+
set(ENABLE_TRACER ON CACHE BOOL "" FORCE)
16+
17+
message(STATUS "Fetching OpenFHE, this may take a while...")
18+
FetchContent_MakeAvailable(OpenFHE)
19+
message(STATUS "Finished configuring OpenFHE")
20+
21+
FetchContent_GetProperties(openfhe)
22+
23+
# Create executable from simple_tracing.cpp
24+
add_executable(simple_tracing simple_tracing.cpp heraclestracer.h)
25+
# Set C++ standard
26+
target_compile_features(simple_tracing PRIVATE cxx_std_17)
27+
# Link with OpenFHE libraries
28+
target_link_libraries(simple_tracing PRIVATE HERACLES_DATA_FORMATS::heracles_data_formats OPENFHEcore OPENFHEpke OPENFHEbinfhe)
29+
30+
target_include_directories(simple_tracing PRIVATE
31+
# Third Party Includes
32+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/third-party/include>
33+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/third-party/cereal/include>
34+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/third-party/google-test/googletest>
35+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/third-party/google-test/googletest/include>
36+
# public headers that sit in the repo
37+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/src/core/include>
38+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/src/pke/include>
39+
$<BUILD_INTERFACE:${openfhe_SOURCE_DIR}/src/binfhe/include>
40+
# generated header (configure_file → config_core.h)
41+
$<BUILD_INTERFACE:${openfhe_BINARY_DIR}/src/core>)
42+
43+
44+
# Set compiler flags for optimization and debug info
45+
target_compile_options(simple_tracing PRIVATE
46+
$<$<CONFIG:Release>:-O3>
47+
$<$<CONFIG:Debug>:-g -O0>
48+
)
49+
50+
51+
# define a custom target that runs tracing, then submits the trace to the program mapper, finally sending the pisa and mem file to the functional modeler
52+
add_custom_target(
53+
run_simple_tracing
54+
# Run the actual example, which will generate the traces as end-to-end-test/simple_tracing.bin and end-to-end-test/simple_tracing_data.bin
55+
COMMAND simple_tracing
56+
# Run the program mapper on the instruction trace, generating end-to-end-test/simple_tracing.bin.csv
57+
COMMAND env VIRTUAL_ENV=${VENV_PATH} PATH=${VENV_PATH}/bin:$ENV{PATH} PYTHONPATH=${VENV_SITE_PACKAGES}:$ENV{PYTHONPATH} $<TARGET_FILE:program_mapper> ${CMAKE_BINARY_DIR}/end-to-end-test/simple_tracing.bin ${CMAKE_SOURCE_DIR}/kerngen/kerngen.py
58+
COMMAND $<TARGET_FILE:functional_modeler> ${CMAKE_BINARY_DIR}/end-to-end-test/simple_tracing_pisa.csv --verbose --hec_dataformats_mode --hec_dataformats_poly_program_location ${CMAKE_BINARY_DIR}/end-to-end-test/simple_tracing.bin --hec_dataformats_data ${CMAKE_BINARY_DIR}/end-to-end-test/simple_tracing_data.bin
59+
# TODO: Next step: assemble the *.pisa.csv and the *tw.mem using the assembler from https://github.com/IntelLabs/HERACLES-HGCF
60+
# TODO: Then it's a dead end :( as we don't have any tooling that can support non-toy sized workloads
61+
DEPENDS simple_tracing program_mapper functional_modeler create-end-to-end-test-dir
62+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/end-to-end-test
63+
)
64+
65+
add_custom_target(create-end-to-end-test-dir
66+
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/end-to-end-test
67+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/end-to-end-test
68+
)

0 commit comments

Comments
 (0)