Skip to content

Commit 4f02dbd

Browse files
committed
Merged PR 1970: Refactor code
1. Remove "using namespace onnx" from header files 2. onnx_test_runner: combine input/output data into a single file for each dataset. 3. onnx_test_runner: change the way how finished event was sent, to fix a crash on exit bug. 4. cmake: Cleanup include_directories, change it to target_include_directories, so that it only make effect on special targets. 5. cmake: remove lotusIR_graph_obj and lotus_common_obj target 6. cmake: perfer to use prebuilt zlib library 7. cloudtest: disable "LotusModelTest.resnet50.debug" and "LotusModelTest.vgg19.debug". They run too long. 8. cloudtest: add 6 models. coreml_SVC_sklearn_load_wine,coreml_SVC_sklearn_load_breast_cancer,coreml_SVC_OpenML_1464_blood_transfusion,coreml_SVC_OpenML_312_scene,coreml_SVR_sklearn_load_boston,coreml_SVR_sklearn_load_diabetes 9. logging: move the implementation of OStreamSink to a ".cc" file, so that users of it has no dependency on the "date" library. Related work items: #137
1 parent 0961af5 commit 4f02dbd

File tree

79 files changed

+713
-1055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+713
-1055
lines changed

cmake/CMakeLists.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ if(WIN32)
9191
#Always enable exception handling, even for Windows ARM
9292
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
9393
endif()
94+
95+
# External dependencies
96+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external)
97+
9498
#Here we support three build mode:
9599
#1. (recommended)lotus_USE_PREBUILT_PB is set (ONNX_CUSTOM_PROTOC_EXECUTABLE should also be set)
96100
# We will not build protobuf, will use a prebuilt binary instead. This mode can also support cross-compiling
@@ -108,9 +112,20 @@ if(lotus_USE_PREBUILT_PB)
108112
_PROTOBUF_INSTALL_PREFIX
109113
${_PROTOBUF_INSTALL_PREFIX}/..
110114
REALPATH)
111-
include(${_PROTOBUF_INSTALL_PREFIX}/cmake/protobuf-config.cmake)
115+
if(WIN32)
116+
include(${_PROTOBUF_INSTALL_PREFIX}/cmake/protobuf-config.cmake)
117+
else()
118+
include(${_PROTOBUF_INSTALL_PREFIX}/lib64/cmake/protobuf/protobuf-config.cmake)
119+
endif()
112120
include(protobuf_function.cmake)
113121
else()
122+
# zlib
123+
find_package(ZLIB)
124+
if (NOT ZLIB_FOUND)
125+
include(zlib)
126+
set_target_properties(zlib_copy_headers_to_destination PROPERTIES FOLDER "External/zlib")
127+
set_target_properties(zlib_create_destination_dir PROPERTIES FOLDER "External/zlib")
128+
endif()
114129
# use protobuf as a submodule
115130
add_subdirectory(${PROJECT_SOURCE_DIR}/external/protobuf/cmake EXCLUDE_FROM_ALL)
116131
set_target_properties(libprotobuf PROPERTIES FOLDER "External/Protobuf")
@@ -125,8 +140,6 @@ endif()
125140
get_target_property(PROTOBUF_INCLUDE_DIRS protobuf::libprotobuf
126141
INTERFACE_INCLUDE_DIRECTORIES)
127142

128-
set(googletest_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/external/googletest/googletest/include ${PROJECT_SOURCE_DIR}/external/googletest/googlemock/include)
129-
130143
if (lotus_USE_CUDA AND "${lotus_CUDNN_HOME}" STREQUAL "")
131144
message(FATAL_ERROR "lotus_CUDNN_HOME required for lotus_USE_CUDA")
132145
endif()
@@ -155,10 +168,6 @@ if (lotus_SPLIT_UNIT_TEST_PROJECTS)
155168
set(SingleUnitTestProject OFF)
156169
endif()
157170

158-
159-
160-
# External dependencies
161-
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external)
162171
set(LOTUS_ROOT ${PROJECT_SOURCE_DIR}/../lotus)
163172

164173
include(date)
@@ -174,11 +183,6 @@ include(eigen)
174183
set(lotus_EXTERNAL_DEPENDENCIES eigen)
175184
set(lotus_EXTERNAL_LIBRARIES protobuf::libprotobuf)
176185

177-
# zlib
178-
include(zlib)
179-
set_target_properties(zlib_copy_headers_to_destination PROPERTIES FOLDER "External/zlib")
180-
set_target_properties(zlib_create_destination_dir PROPERTIES FOLDER "External/zlib")
181-
182186
# gtest and gmock
183187
add_subdirectory(${PROJECT_SOURCE_DIR}/external/googletest EXCLUDE_FROM_ALL)
184188
set_target_properties(gmock PROPERTIES FOLDER "External/GTest")
@@ -247,12 +251,8 @@ endif()
247251

248252
include_directories(
249253
${LOTUS_ROOT}
250-
${PROJECT_SOURCE_DIR}/external/onnx
251-
${CMAKE_CURRENT_BINARY_DIR}/external/onnx
252254
# External dependencies.
253-
${PROTOBUF_INCLUDE_DIRS}
254255
${eigen_INCLUDE_DIRS}
255-
${date_INCLUDE_DIR}
256256
${gsl_INCLUDE_DIR}
257257
)
258258

cmake/lotusIR_graph.cmake

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,15 @@ file(GLOB_RECURSE lotusIR_defs_src
77
"${LOTUS_ROOT}/core/defs/*.cc"
88
)
99

10-
add_library(lotusIR_graph_obj OBJECT ${lotusIR_graph_src} ${lotusIR_defs_src})
11-
add_dependencies(lotusIR_graph_obj onnx gsl)
10+
add_library(lotusIR_graph ${lotusIR_graph_src} ${lotusIR_defs_src})
11+
add_dependencies(lotusIR_graph onnx_proto gsl)
12+
target_include_directories(lotusIR_graph PUBLIC $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
1213

13-
set_target_properties(lotusIR_graph_obj PROPERTIES FOLDER "Lotus")
14-
set_target_properties(lotusIR_graph_obj PROPERTIES LINKER_LANGUAGE CXX)
15-
16-
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotusIR_graph_src} ${lotusIR_defs_src})
17-
18-
if (WIN32)
19-
set(lotusIR_graph_obj_static_library_flags
20-
-IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
21-
)
22-
23-
set_target_properties(lotusIR_graph_obj PROPERTIES
24-
STATIC_LIBRARY_FLAGS "${lotusIR_graph_obj_static_library_flags}")
25-
26-
target_compile_options(lotusIR_graph_obj PRIVATE
27-
/EHsc # exception handling - C++ may throw, extern "C" will not
28-
)
29-
30-
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
31-
set_target_properties(lotusIR_graph_obj PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
32-
endif()
33-
34-
35-
36-
add_library(lotusIR_graph $<TARGET_OBJECTS:lotusIR_graph_obj>)
37-
target_link_libraries(lotusIR_graph PUBLIC lotus_common onnx)
3814

3915
set_target_properties(lotusIR_graph PROPERTIES FOLDER "Lotus")
16+
set_target_properties(lotusIR_graph PROPERTIES LINKER_LANGUAGE CXX)
17+
18+
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotusIR_graph_src} ${lotusIR_defs_src})
4019

4120
if (WIN32)
4221
set(lotusIR_graph_static_library_flags
@@ -49,4 +28,7 @@ if (WIN32)
4928
target_compile_options(lotusIR_graph PRIVATE
5029
/EHsc # exception handling - C++ may throw, extern "C" will not
5130
)
31+
32+
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
33+
set_target_properties(lotusIR_graph PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
5234
endif()

cmake/lotus_common.cmake

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,17 @@ file(GLOB lotus_common_src ${lotus_common_src_patterns})
3232

3333
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotus_common_src})
3434

35-
add_library(lotus_common_obj OBJECT ${lotus_common_src})
36-
35+
add_library(lotus_common ${lotus_common_src})
36+
target_include_directories(lotus_common PRIVATE ${date_INCLUDE_DIR})
3737
# logging uses date. threadpool uses eigen
38-
add_dependencies(lotus_common_obj date eigen gsl)
38+
add_dependencies(lotus_common date eigen gsl)
3939

40-
set_target_properties(lotus_common_obj PROPERTIES LINKER_LANGUAGE CXX)
41-
set_target_properties(lotus_common_obj PROPERTIES FOLDER "Lotus")
40+
set_target_properties(lotus_common PROPERTIES LINKER_LANGUAGE CXX)
41+
set_target_properties(lotus_common PROPERTIES FOLDER "Lotus")
4242

4343
if(WIN32)
4444
# Add Code Analysis properties to enable C++ Core checks. Have to do it via a props file include.
45-
set_target_properties(lotus_common_obj PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
45+
set_target_properties(lotus_common PROPERTIES VS_USER_PROPS ${PROJECT_SOURCE_DIR}/EnableVisualStudioCodeAnalysis.props)
4646
endif()
4747

48-
# add library that tests can link against
49-
add_library(lotus_common
50-
$<TARGET_OBJECTS:lotus_common_obj>)
51-
52-
set_target_properties(lotus_common PROPERTIES FOLDER "Lotus")
53-
54-
if (WIN32)
55-
target_compile_definitions(lotus_common PRIVATE
56-
_SCL_SECURE_NO_WARNINGS
57-
)
58-
59-
set(lotus_common_static_library_flags
60-
-IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
61-
)
62-
63-
set_target_properties(lotus_common PROPERTIES
64-
STATIC_LIBRARY_FLAGS "${lotus_common_static_library_flags}"
65-
)
66-
67-
target_compile_options(lotus_common PRIVATE
68-
/EHsc # exception handling - C++ may throw, extern "C" will not
69-
)
70-
endif()
7148

cmake/lotus_framework.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif()
1111
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotus_framework_srcs})
1212

1313
add_library(lotus_framework_obj OBJECT ${lotus_framework_srcs})
14+
target_include_directories(lotus_framework_obj PUBLIC $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
1415
set_target_properties(lotus_framework_obj PROPERTIES FOLDER "Lotus")
1516
set_target_properties(lotus_framework_obj PROPERTIES LINKER_LANGUAGE CUDA)
1617
# need onnx to build to create headers that this project includes
@@ -37,7 +38,7 @@ file(GLOB_RECURSE lotus_util_srcs
3738
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotus_util_srcs})
3839

3940
add_library(lotus_util_obj OBJECT ${lotus_util_srcs})
40-
41+
target_include_directories(lotus_util_obj PUBLIC $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> PUBLIC $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
4142
set_target_properties(lotus_util_obj PROPERTIES LINKER_LANGUAGE CXX)
4243
set_target_properties(lotus_util_obj PROPERTIES FOLDER "Lotus")
4344
add_dependencies(lotus_util_obj onnx gsl ${lotus_EXTERNAL_DEPENDENCIES})

cmake/lotus_providers.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ file(GLOB lotus_providers_common_srcs
1111
source_group(TREE ${LOTUS_ROOT}/core FILES ${lotus_providers_common_srcs} ${lotus_providers_srcs})
1212

1313
add_library(lotus_providers_obj OBJECT ${lotus_providers_common_srcs} ${lotus_providers_srcs})
14+
target_include_directories(lotus_providers_obj PRIVATE $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
1415

1516
add_dependencies(lotus_providers_obj eigen gsl onnx)
1617

@@ -40,7 +41,8 @@ if (lotus_USE_CUDA)
4041
add_library(lotus_providers_cuda_cc_obj OBJECT ${lotus_providers_cuda_cc_srcs})
4142
add_dependencies(lotus_providers_cuda_cc_obj eigen gsl onnx)
4243
set_target_properties(lotus_providers_cuda_cc_obj PROPERTIES FOLDER "Lotus")
43-
44+
target_include_directories(lotus_providers_cuda_cc_obj PRIVATE $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
45+
4446
add_library(lotus_providers_cuda $<TARGET_OBJECTS:lotus_providers_cuda_cc_obj> ${lotus_providers_cuda_cu_srcs})
4547
set_target_properties(lotus_providers_cuda PROPERTIES LINKER_LANGUAGE CUDA)
4648
set_target_properties(lotus_providers_cuda PROPERTIES FOLDER "Lotus")

cmake/lotus_unittests.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function(AddTest)
1919
endif(_UT_DEPENDS)
2020

2121
target_link_libraries(${_UT_TARGET} ${_UT_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${lotus_EXTERNAL_LIBRARIES})
22-
22+
target_include_directories(${_UT_TARGET} PRIVATE ${date_INCLUDE_DIR})
2323
if (WIN32)
2424
#It's cmake bug, cannot add this compile option for cuda compiler
2525
#(https://gitlab.kitware.com/cmake/cmake/issues/17535)
@@ -260,9 +260,10 @@ endif()
260260

261261
add_library(onnx_test_runner_common ${onnx_test_runner_common_srcs})
262262
add_dependencies(onnx_test_runner_common lotus_providers lotus_framework lotusIR_graph onnx)
263+
target_include_directories(onnx_test_runner_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/onnx/onnx $<TARGET_PROPERTY:onnx,INTERFACE_INCLUDE_DIRECTORIES> $<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
263264
set_target_properties(onnx_test_runner_common PROPERTIES FOLDER "LotusTest")
264265

265-
lotus_protobuf_generate(APPEND_PATH TARGET onnx_test_runner_common)
266+
lotus_protobuf_generate(APPEND_PATH IMPORT_DIRS ${PROJECT_SOURCE_DIR}/external/onnx/onnx TARGET onnx_test_runner_common)
266267

267268
set(onnx_test_libs
268269
${FS_STDLIB}
@@ -299,7 +300,6 @@ if (lotus_USE_OPENBLAS)
299300
endif()
300301

301302
add_executable(onnx_test_runner ${onnx_test_runner_src_dir}/main.cc)
302-
target_include_directories(onnx_test_runner PUBLIC ${lotusIR_graph_header})
303303
target_link_libraries(onnx_test_runner PRIVATE onnx_test_runner_common ${GETOPT_LIB} ${onnx_test_libs})
304304
set_target_properties(onnx_test_runner PROPERTIES FOLDER "LotusTest")
305305

@@ -311,6 +311,7 @@ if(WIN32)
311311
if(NOT ${CMAKE_GENERATOR_PLATFORM} MATCHES "ARM")
312312
add_library(onnx_test_runner_vstest SHARED ${onnx_test_runner_src_dir}/vstest_logger.cc ${onnx_test_runner_src_dir}/vstest_main.cc)
313313
target_compile_options(onnx_test_runner_vstest PRIVATE ${DISABLED_WARNINGS_FOR_PROTOBUF})
314+
target_include_directories(onnx_test_runner_vstest PRIVATE ${date_INCLUDE_DIR})
314315
target_link_libraries(onnx_test_runner_vstest ${onnx_test_libs} onnx_test_runner_common)
315316
set_target_properties(onnx_test_runner_vstest PROPERTIES FOLDER "LotusTest")
316317
endif()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "ostream_sink.h"
2+
#include "date/date.h"
3+
4+
namespace Lotus {
5+
namespace Logging {
6+
7+
void OStreamSink::SendImpl(const Timestamp &timestamp, const std::string &logger_id, const Capture &message) {
8+
// operator for formatting of timestamp in ISO8601 format including microseconds
9+
using date::operator<<;
10+
11+
// Two options as there may be multiple calls attempting to write to the same sink at once:
12+
// 1) Use mutex to synchronize access to the stream.
13+
// 2) Create the message in an ostringstream and output in one call.
14+
//
15+
// Going with #2 as it should scale better at the cost of creating the message in memory first
16+
// before sending to the stream.
17+
18+
std::ostringstream msg;
19+
20+
msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", "
21+
<< message.Location().ToString() << "] " << message.Message();
22+
23+
(*stream_) << msg.str() << "\n";
24+
25+
if (flush_) {
26+
stream_->flush();
27+
}
28+
}
29+
} // namespace Logging
30+
} // namespace Lotus

lotus/core/common/logging/sinks/ostream_sink.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <sstream>
55
#include <string>
66

7-
#include "date/date.h"
8-
97
#include "core/common/logging/capture.h"
108
#include "core/common/logging/isink.h"
119

@@ -22,28 +20,7 @@ class OStreamSink : public ISink {
2220
}
2321

2422
public:
25-
void SendImpl(const Timestamp &timestamp, const std::string &logger_id, const Capture &message) override {
26-
// operator for formatting of timestamp in ISO8601 format including microseconds
27-
using date::operator<<;
28-
29-
// Two options as there may be multiple calls attempting to write to the same sink at once:
30-
// 1) Use mutex to synchronize access to the stream.
31-
// 2) Create the message in an ostringstream and output in one call.
32-
//
33-
// Going with #2 as it should scale better at the cost of creating the message in memory first
34-
// before sending to the stream.
35-
36-
std::ostringstream msg;
37-
38-
msg << timestamp << " [" << message.SeverityPrefix() << ":" << message.Category() << ":" << logger_id << ", "
39-
<< message.Location().ToString() << "] " << message.Message();
40-
41-
(*stream_) << msg.str() << "\n";
42-
43-
if (flush_) {
44-
stream_->flush();
45-
}
46-
}
23+
void SendImpl(const Timestamp &timestamp, const std::string &logger_id, const Capture &message) override;
4724

4825
private:
4926
std::ostream *stream_;

lotus/core/framework/allocation_planner.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "core/framework/session_state.h"
99
#include "core/graph/utils.h"
1010
#include "core/framework/data_types.h"
11-
11+
using namespace onnx;
1212
namespace Lotus {
1313

1414
std::ostream& operator<<(std::ostream& out, AllocKind alloc_kind) {
@@ -216,14 +216,14 @@ class PlannerImpl {
216216

217217
MLDataType GetMLDataType(const LotusIR::NodeArg& arg) {
218218
const DataType ptype = arg.Type();
219-
const onnx::TypeProto& type_proto = onnx::Utils::DataTypeUtils::ToTypeProto(ptype);
219+
const TypeProto& type_proto = Utils::DataTypeUtils::ToTypeProto(ptype);
220220
return DataTypeImpl::TypeFromProto(type_proto);
221221
}
222222

223223
/*! \brief Given a tensor-type, return the size of an element of the tensor.
224224
*/
225225
size_t GetElementSize(const DataType& tensor_type) {
226-
const onnx::TypeProto& type_proto = onnx::Utils::DataTypeUtils::ToTypeProto(tensor_type);
226+
const TypeProto& type_proto = Utils::DataTypeUtils::ToTypeProto(tensor_type);
227227
MLDataType ml_data_type = DataTypeImpl::TypeFromProto(type_proto);
228228
const TensorTypeBase* tensor_type_base = ml_data_type->AsTensorType();
229229
LOTUS_ENFORCE(nullptr != tensor_type_base);
@@ -492,7 +492,7 @@ class PlannerImpl {
492492
bool IsNonTensor(const LotusIR::NodeArg& nodearg) {
493493
// TODO: unclear why we should go through a string-representation of type
494494
auto ptype = nodearg.Type();
495-
auto& type_proto = onnx::Utils::DataTypeUtils::ToTypeProto(ptype);
495+
auto& type_proto = Utils::DataTypeUtils::ToTypeProto(ptype);
496496
return !type_proto.has_tensor_type();
497497
}
498498

lotus/core/framework/allocation_planner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ std::ostream& operator<<(std::ostream& out, std::pair<const SequentialExecutionP
103103
// to do the planning.
104104
class ISequentialPlannerContext {
105105
public:
106-
virtual const TensorShapeProto* GetShape(const LotusIR::NodeArg& arg) const = 0;
106+
virtual const onnx::TensorShapeProto* GetShape(const LotusIR::NodeArg& arg) const = 0;
107107
};
108108

109109
class SequentialPlannerContext : public ISequentialPlannerContext {
110110
public:
111-
const TensorShapeProto* GetShape(const LotusIR::NodeArg& arg) const override {
111+
const onnx::TensorShapeProto* GetShape(const LotusIR::NodeArg& arg) const override {
112112
return arg.Shape();
113113
}
114114
};

0 commit comments

Comments
 (0)