Skip to content

Commit f5fee6f

Browse files
committed
Add emitFromONNX to generate automatically headers and weight file
for SOFIE tests Remove then header file from repository Remove also obsolate onnx file that cannot be parsed by SOFIE Add new FindONNXRuntime and a new FindLWTNN to find the required dependency package. Use minimial FIndModule file, which requires only to define an env variable to find the package
1 parent 03617f1 commit f5fee6f

24 files changed

+226
-7967
lines changed

cmake/FindONNXRuntime.cmake

Lines changed: 0 additions & 102 deletions
This file was deleted.

cmake/modules/FindLWTNN.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
# Find the LWTNN includes and library.
8+
#
9+
# This module defines
10+
# LWTNN_INCLUDE_DIR, where to locate LWTNN.h file
11+
# LWTNN_LIBRARIES, the libraries to link against to use LWTNN
12+
# LWTNN_FOUND. If false, you cannot build anything that requires LWTNN.
13+
# LWTNN_LIBRARY, where to find the libLWTNN library.
14+
15+
set(LWTNN_FOUND 0)
16+
if(LWTNN_LIBRARY AND LWTNN_INCLUDE_DIR)
17+
set(LWTNN_FIND_QUIETLY TRUE)
18+
endif()
19+
20+
find_path(LWTNN_INCLUDE_DIR lwtnn/Graph.hh
21+
$ENV{LWTNN_DIR}/include
22+
$ENV{LWTNN} $ENV{LWTNN}/include
23+
/usr/local/include
24+
/usr/include
25+
DOC "Specify the directory containing LWTNN.h"
26+
)
27+
28+
find_library(LWTNN_LIBRARY NAMES lwtnn PATHS
29+
$ENV{LWTNN_DIR}/lib
30+
$ENV{LWTNN} $ENV{LWTNN}/lib $ENV{LWTNN}/.libs
31+
/usr/local/lib
32+
/usr/lib
33+
/opt/LWTNN/lib
34+
DOC "Specify the lwtnn library here."
35+
)
36+
37+
if(LWTNN_INCLUDE_DIR AND LWTNN_LIBRARY)
38+
set(LWTNN_FOUND 1 )
39+
if(NOT LWTNN_FIND_QUIETLY)
40+
message(STATUS "Found LWTNN includes at ${LWTNN_INCLUDE_DIR}")
41+
message(STATUS "Found LWTNN library at ${LWTNN_LIBRARY}")
42+
endif()
43+
endif()
44+
45+
set(LWTNN_LIBRARIES ${LWTNN_LIBRARY})
46+
47+
mark_as_advanced(LWTNN_FOUND LWTNN_LIBRARY LWTNN_INCLUDE_DIR)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
# Find the ONNXRuntime includes and library.
8+
#
9+
# This module defines
10+
# ONNXRuntime_INCLUDE_DIR, where to locate ONNXRuntime include file
11+
# ONNXRuntime_LIBRARIES, the libraries to link against to use ONNXRuntime
12+
# ONNXRuntime_FOUND. If false, you cannot build anything that requires ONNXRuntime.
13+
# ONNXRuntime_LIBRARY, where to find the libONNXRuntime library.
14+
15+
set(ONNXRuntime_FOUND 0)
16+
if(ONNXRuntime_LIBRARY AND ONNXRuntime_INCLUDE_DIR)
17+
set(ONNXRuntime_FIND_QUIETLY TRUE)
18+
endif()
19+
20+
find_path(ONNXRuntime_INCLUDE_DIR onnxruntime_cxx_api.h
21+
$ENV{ONNXRuntime_DIR}/include
22+
$ENV{ONNXRuntime} $ENV{ONNXRuntime}/include
23+
/usr/local/include
24+
/usr/include
25+
DOC "Specify the directory containing ONNXRuntime.h"
26+
)
27+
28+
find_library(ONNXRuntime_LIBRARY NAMES onnxruntime PATHS
29+
$ENV{ONNXRuntime_DIR}/lib
30+
$ENV{ONNXRuntime} $ENV{ONNXRuntime}/lib $ENV{ONNXRuntime}/.libs
31+
/usr/local/lib
32+
/usr/lib
33+
/opt/ONNXRuntime/lib
34+
DOC "Specify the ONNXRuntime library here."
35+
)
36+
37+
if(ONNXRuntime_INCLUDE_DIR AND ONNXRuntime_LIBRARY)
38+
set(ONNXRuntime_FOUND 1 )
39+
if(NOT ONNXRuntime_FIND_QUIETLY)
40+
message(STATUS "Found ONNXRuntime includes at ${ONNXRuntime_INCLUDE_DIR}")
41+
message(STATUS "Found ONNXRuntime library at ${ONNXRuntime_LIBRARY}")
42+
endif()
43+
endif()
44+
45+
set(ONNXRuntime_LIBRARIES ${ONNXRuntime_LIBRARY})
46+
47+
mark_as_advanced(ONNXRuntime_FOUND ONNXRuntime_LIBRARY ONNXRuntime_INCLUDE_DIR)

root/tmva/sofie/CMakeLists.txt

Lines changed: 94 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ if(ROOT_tmva_FOUND AND ROOT_tmva-sofie_FOUND)
1919
# Looking for ONNXRuntime
2020
## to find OONX run time configure cmake with
2121
## -DONNXRuntime_INCLUDE_DIRS=..onxruntime_location.../include -DONNXRuntime_LIBRARIES=.../lib
22-
find_package(ONNXRuntime QUIET)
22+
find_package(ONNXRuntime)
2323
if(ONNXRuntime_FOUND)
24-
message(STATUS "Found ONNXRuntime (build type: ${ONNXRuntime_BUILD_TYPE}, version: ${ONNXRuntime_VERSION_STRING})")
24+
message(STATUS "Found ONNXRuntime (library is ${ONNXRuntime_LIBRARY}, libraries ${ONNXRuntime_LIBRARIES})")
2525

2626
# Configuring ONNXRuntimeInference_Template.cxx.in
2727
set(FUNC_NAME "BM_ONNXRuntime_Inference")
@@ -42,13 +42,13 @@ if(ROOT_tmva_FOUND AND ROOT_tmva-sofie_FOUND)
4242
RB_ADD_GBENCHMARK(ONNXRuntimeInference
4343
ONNXRuntimeInference.cxx
4444
LABEL short
45-
LIBRARIES TMVA onnxruntime
45+
LIBRARIES TMVA ${ONNXRuntime_LIBRARIES}
4646
)
4747
target_link_directories(ONNXRuntimeInference PRIVATE ${ONNXRuntime_LIBRARIES})
4848
target_include_directories(ONNXRuntimeInference PRIVATE ${ONNXRuntime_INCLUDE_DIR})
4949

5050
else()
51-
message(WARNING "ONNXRuntime not found")
51+
message(STATUS "ONNXRuntime not found")
5252
endif()
5353

5454
if (Use_SOFIE_TEMPLATE)
@@ -95,71 +95,115 @@ if(ROOT_tmva_FOUND AND ROOT_tmva-sofie_FOUND)
9595

9696
endif()
9797

98-
configure_file(input_models/compiled/Linear_event.hxx Linear_event.hxx COPYONLY)
99-
configure_file(input_models/compiled/Linear_event.dat Linear_event.dat COPYONLY)
10098

101-
configure_file(input_models/compiled/Linear_16.hxx Linear_16.hxx COPYONLY)
102-
configure_file(input_models/compiled/Linear_16.dat Linear_16.dat COPYONLY)
99+
# configure_file(input_models/compiled/Linear_event.hxx Linear_event.hxx COPYONLY)
100+
# configure_file(input_models/compiled/Linear_event.dat Linear_event.dat COPYONLY)
101+
102+
# configure_file(input_models/compiled/Linear_16.hxx Linear_16.hxx COPYONLY)
103+
# configure_file(input_models/compiled/Linear_16.dat Linear_16.dat COPYONLY)
103104

104-
configure_file(input_models/compiled/Linear_32.hxx Linear_32.hxx COPYONLY)
105-
configure_file(input_models/compiled/Linear_32.dat Linear_32.dat COPYONLY)
105+
# configure_file(input_models/compiled/Linear_32.hxx Linear_32.hxx COPYONLY)
106+
# configure_file(input_models/compiled/Linear_32.dat Linear_32.dat COPYONLY)
106107

107-
configure_file(input_models/compiled/Linear_64.hxx Linear_64.hxx COPYONLY)
108-
configure_file(input_models/compiled/Linear_64.dat Linear_64.dat COPYONLY)
108+
# configure_file(input_models/compiled/Linear_64.hxx Linear_64.hxx COPYONLY)
109+
# configure_file(input_models/compiled/Linear_64.dat Linear_64.dat COPYONLY)
109110

110111

111-
configure_file(input_models/compiled/Conv_d100_L1_B1.hxx Conv_d100_L1_B1.hxx COPYONLY)
112-
configure_file(input_models/compiled/Conv_d100_L1_B1.dat Conv_d100_L1_B1.dat COPYONLY)
112+
# configure_file(input_models/compiled/Conv_d100_L1_B1.hxx Conv_d100_L1_B1.hxx COPYONLY)
113+
# configure_file(input_models/compiled/Conv_d100_L1_B1.dat Conv_d100_L1_B1.dat COPYONLY)
113114

114-
configure_file(input_models/compiled/Conv_d100_L14_B1.hxx Conv_d100_L14_B1.hxx COPYONLY)
115-
configure_file(input_models/compiled/Conv_d100_L14_B1.dat Conv_d100_L14_B1.dat COPYONLY)
116-
configure_file(input_models/compiled/Conv_d100_L14_B32.hxx Conv_d100_L14_B32.hxx COPYONLY)
117-
#use file B1 as B32 for weights : it is the same
118-
configure_file(input_models/compiled/Conv_d100_L14_B32.dat Conv_d100_L14_B32.dat COPYONLY)
115+
# configure_file(input_models/compiled/Conv_d100_L14_B1.hxx Conv_d100_L14_B1.hxx COPYONLY)
116+
# configure_file(input_models/compiled/Conv_d100_L14_B1.dat Conv_d100_L14_B1.dat COPYONLY)
117+
# configure_file(input_models/compiled/Conv_d100_L14_B32.hxx Conv_d100_L14_B32.hxx COPYONLY)
118+
# #use file B1 as B32 for weights : it is the same
119+
# configure_file(input_models/compiled/Conv_d100_L14_B32.dat Conv_d100_L14_B32.dat COPYONLY)
120+
121+
# configure_file(input_models/compiled/resnet18v1.hxx resnet18v1.hxx COPYONLY)
122+
# configure_file(input_models/compiled/resnet18v1.dat resnet18v1.dat COPYONLY)
123+
124+
125+
add_executable(emitFromONNX
126+
EmitFromONNX.cxx
127+
)
128+
#target_include_directories(emitFromONNX PRIVATE )
129+
target_link_libraries(emitFromONNX ${Protobuf_LIBRARIES} Core ROOTTMVASofie ROOTTMVASofieParser)
130+
set_target_properties(emitFromONNX PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
131+
132+
if (NOT ONNX_MODELS_DIR)
133+
set(ONNX_MODELS_DIR input_models)
134+
endif()
119135

120-
configure_file(input_models/compiled/resnet18v1.hxx resnet18v1.hxx COPYONLY)
121-
configure_file(input_models/compiled/resnet18v1.dat resnet18v1.dat COPYONLY)
136+
add_custom_target(SofieCompileModels)
137+
add_dependencies(SofieCompileModels emitFromONNX)
122138

123-
# Benchmark for models emitted by SOFIE
124-
RB_ADD_GBENCHMARK(SOFIEInference
139+
140+
file(GLOB ONNX_FILES "${ONNX_MODELS_DIR}/*.onnx")
141+
foreach(onnx_file ${ONNX_FILES})
142+
#get_filename_component(fname ${onnx_file} NAME_WE)
143+
#get_filename_component(fdir ${onnx_file} DIRECTORY)
144+
add_custom_command(TARGET SofieCompileModels POST_BUILD
145+
COMMAND ./emitFromONNX ${onnx_file}
146+
USES_TERMINAL
147+
)
148+
endforeach()
149+
150+
find_package(BLAS)
151+
if(BLAS_FOUND)
152+
message(STATUS "Found BLAS ( libraries ${BLAS_LIBRARIES})")
153+
154+
#set(SOFIE_BLAS_LIBS /home/moneta/intel/mkl/lib/intel64/libmkl_intel_lp64.so /home/moneta/intel/mkl/lib/intel64/libmkl_sequential.so /home/moneta/intel/mkl/lib/intel64/libmkl_core.so -lpthread)
155+
#set(SOFIE_BLAS_LIBS /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Accelerate.framework)
156+
157+
# Benchmark for models emitted by SOFIE
158+
RB_ADD_GBENCHMARK(SOFIEInference
125159
SOFIEInference.cxx
126160
LABEL short
127-
#LIBRARIES TMVA ROOTTMVASofie openblas
128-
#LIBRARIES TMVA ROOTTMVASofie /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Accelerate.framework
129-
LIBRARIES TMVA ROOTTMVASofie /home/moneta/intel/mkl/lib/intel64/libmkl_intel_lp64.so /home/moneta/intel/mkl/lib/intel64/libmkl_sequential.so /home/moneta/intel/mkl/lib/intel64/libmkl_core.so -lpthread
130-
)
161+
LIBRARIES TMVA ROOTTMVASofie ${BLAS_LIBRARIES}
162+
)
163+
131164
# target_include_directories(SOFIEInference PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
132165

133-
set(SOFIE_BLAS_LIBS /home/moneta/intel/mkl/lib/intel64/libmkl_intel_lp64.so /home/moneta/intel/mkl/lib/intel64/libmkl_sequential.so /home/moneta/intel/mkl/lib/intel64/libmkl_core.so -lpthread)
166+
#add_dependencies(SOFIEInference SofieCompileModels)
167+
134168

135-
configure_file(input_models/compiled/higgs_model_dense.hxx higgs_model_dense.hxx COPYONLY)
136-
configure_file(input_models/compiled/higgs_model_dense.dat higgs_model_dense.dat COPYONLY)
169+
#configure_file(input_models/compiled/higgs_model_dense.hxx higgs_model_dense.hxx COPYONLY)
170+
#configure_file(input_models/compiled/higgs_model_dense.dat higgs_model_dense.dat COPYONLY)
137171
RB_ADD_GBENCHMARK(RDF_SOFIE_Inference
138172
RDF_SOFIE_Inference.cxx
139173
LABEL short
140174
#LIBRARIES TMVA ROOTTMVASofie openblas
141-
#LIBRARIES TMVA ROOTTMVASofie /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Accelerate.framework
142-
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie ${SOFIE_BLAS_LIBS}
175+
#LIBRARIES TMVA ROOTTMVASofie
176+
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie ${BLAS_LIBRARIES}
143177
)
144178

145-
endif()
179+
add_dependencies(RDF_SOFIE_Inference SofieCompileModels)
146180

147-
configure_file(input_models/higgs_model_dense.json higgs_model_dense.json COPYONLY)
148-
set(LWTNN_INCLUDE_DIR /home/moneta/cernbox/root/tests/tmva/sofie/lwtnn-build/include)
149-
set(LWTNN_LIBS /home/moneta/cernbox/root/tests/tmva/sofie/lwtnn-build/lib/liblwtnn.so)
150-
RB_ADD_GBENCHMARK(RDF_lwtnn_Inference
151-
RDF_lwtnn_Inference.cxx
152-
LABEL short
153-
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie ${LWTNN_LIBS}
154-
)
155-
target_include_directories(RDF_lwtnn_Inference PRIVATE ${LWTNN_INCLUDE_DIR})
181+
endif()
182+
endif()
156183

184+
find_package(LWTNN QUIET)
185+
if (LWTNN_FOUND)
186+
187+
message(STATUS "Found LWTNN (library is ${LWTNN_LIBRARY}, libraries ${LWTNN_LIBRARIES})")
188+
configure_file(input_models/higgs_model_dense.json higgs_model_dense.json COPYONLY)
189+
# set(LWTNN_INCLUDE_DIR /home/moneta/cernbox/root/tests/tmva/sofie/lwtnn-build/include)
190+
# set(LWTNN_LIBS /home/moneta/cernbox/root/tests/tmva/sofie/lwtnn-build/lib/liblwtnn.so)
191+
RB_ADD_GBENCHMARK(RDF_lwtnn_Inference
192+
RDF_lwtnn_Inference.cxx
193+
LABEL short
194+
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie ${LWTNN_LIBRARY})
195+
target_include_directories(RDF_lwtnn_Inference PRIVATE ${LWTNN_INCLUDE_DIR})
196+
else()
197+
message(STATUS "LWTNN not found")
198+
endif()
157199

158-
configure_file(input_models/higgs_model_dense.onnx higgs_model_dense.onnx COPYONLY)
159-
RB_ADD_GBENCHMARK(RDF_ONNXRuntime_Inference
160-
RDF_ONNXRuntime_Inference.cxx
161-
LABEL short
162-
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie onnxruntime
163-
)
164-
target_link_directories(RDF_ONNXRuntime_Inference PRIVATE ${ONNXRuntime_LIBRARIES})
165-
target_include_directories(RDF_ONNXRuntime_Inference PRIVATE ${ONNXRuntime_INCLUDE_DIR})
200+
if (ONNXRuntime_FOUND)
201+
configure_file(input_models/higgs_model_dense.onnx higgs_model_dense.onnx COPYONLY)
202+
RB_ADD_GBENCHMARK(RDF_ONNXRuntime_Inference
203+
RDF_ONNXRuntime_Inference.cxx
204+
LABEL short
205+
LIBRARIES Core Hist Imt RIO Tree TreePlayer ROOTDataFrame ROOTVecOps TMVA ROOTTMVASofie ${ONNXRuntime_LIBRARIES}
206+
)
207+
target_link_directories(RDF_ONNXRuntime_Inference PRIVATE ${ONNXRuntime_LIBRARIES})
208+
target_include_directories(RDF_ONNXRuntime_Inference PRIVATE ${ONNXRuntime_INCLUDE_DIR})
209+
endif()

0 commit comments

Comments
 (0)