Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable no exception build and update exception handling for DataTypeUtils #3265

Merged
merged 18 commits into from
Feb 17, 2021

Conversation

askhade
Copy link
Contributor

@askhade askhade commented Feb 9, 2021

Adding an option for creating a no exception build for ONNX. This gives runtimes an ability to build onnx without exceptions.
This is restricted to c++ only. Exceptions are required with python bindings. When exceptions are disabled we abort at the site of first exception.

This PR also updates error handling for DataTypeUtils. We throw an exception when any error is encountered. As stated above when exceptions are disabled we abort instead.

Also adding windows CI for testing no exception builds.

Signed-off-by: Ashwini Khade askhade@microsoft.com

… utils

Signed-off-by: Ashwini Khade <askhade@microsoft.com>
@askhade askhade requested review from a team as code owners February 9, 2021 18:38
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
CMakeLists.txt Outdated
Comment on lines 88 to 90
if(ONNX_DISABLE_EXCEPTIONS)
add_compile_definitions("ONNX_NO_EXCEPTIONS")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you have flags to explicitly fail the build if there's an attempt to use exceptions?

e.g. -fno-exceptions for gcc/clang, /EH-s-c for MSVC

onnx/checker.h Outdated
Comment on lines 38 to 39
#define fail_check(...) std::cerr << ONNX_NAMESPACE::MakeString(__VA_ARGS__);\
abort();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for not using ONNX_THROW or ONNX_THROW_EX here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated these macros first and then decided to add ONNX_THROW and ONNX_THROW_EX . I should have gone back to these macros again and updated them ... updated them now.

onnx/defs/schema.cc Outdated Show resolved Hide resolved
onnx/defs/schema.h Outdated Show resolved Hide resolved
Comment on lines 158 to 159
TEST(FunctionAPITest, TypeContextTest) {
// Does not test registering schema twice when no exceptions are enabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would maybe be simpler to just put all the 'register twice' tests and infrastructure inside an #ifndef ONNX_NO_EXCEPTIONS.

Comment on lines 120 to 124
#ifndef ONNX_NO_EXCEPTIONS
ONNX_NAMESPACE::OpSchemaRegistry::OpSchemaRegisterOnce unused(schema);
(void)unused;
#endif
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't RegisterTwiceFloatSchema need a similar update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was not written properly - RegisterTwiceFloatSchema would register the CustomFunc for the first time and then it was registered for the second time here. Anyways I updated both the test to remove a lot of common code and make the intention of the tests clear.

Signed-off-by: Ashwini Khade <askhade@microsoft.com>
onnx/common/common.h Outdated Show resolved Hide resolved
#define ONNX_HANDLE_EXCEPTION(func)

#else
#define ONNX_THROW(...) throw std::runtime_error(ONNX_NAMESPACE::MakeString(__VA_ARGS__));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop semicolon?

Signed-off-by: Ashwini Khade <askhade@microsoft.com>
ContextDependentFuntionTest();
}

// Does not test registering schema twice when no exceptions are enabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two tests here are actually testing different aspects. The first tests a simple function where the parameter is of a fixed type (float), while the second tests a function where the parameter may be one of several types (float or double). The name "RegisterTwiceSchema" may be confusing, but it is meant to register a function called "CustomFunTwice". Does running these two tests cause a problem (such as same function name being registered twice)? If so, I suggest just renaming the functions as "CustomFunTwice1" and "CustomFunTwice2" or use a static boolean to ensure it is registered only once. Thanks!

Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
CMakeLists.txt Outdated
if(ONNX_WERROR)
if(MSVC)
string(APPEND CMAKE_CXX_FLAGS " /WX")
elseif(MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't elseif need a different condition?

Not sure about the 'else(MSVC)' on line 94 as the cmake doco doesn't mention anything about repeating the condition from the 'if' in the 'else' or 'endif'.

https://cmake.org/cmake/help/latest/command/if.html

Copy link
Contributor Author

@askhade askhade Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a typo It should be else and not elseif. Originally ONNX_WERROR did not have any effect on windows and mac platforms... with this change it should take effect on all 3 platforms...

else does allow condition.
"Per legacy, the else() and endif() commands admit an optional argument. If used, it must be a verbatim repeat of the argument of the opening if command."

However to keep it consistent with the rest of the document I will remove the condition

Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Signed-off-by: Ashwini Khade <askhade@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants