-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Expose build information in dynamic lib #15643
Conversation
@microsoft-github-policy-service agree |
cmake/CMakeLists.txt
Outdated
@@ -1229,6 +1229,15 @@ if (onnxruntime_USE_VITISAI) | |||
endif() | |||
endif() | |||
|
|||
execute_process(COMMAND git log -1 --format=%h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of our build environments do not have git. So this would not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snnn It does not matter whether the build envs have git or not. The cmake command won't fail. Instead, it will output to the variable ORT_GIT_COMMIT
& ORT_GIT_BRANCH
with an empty string. To make this clearer, I added a comment here and explicitly change the empty string to "Not-Available". An example is showed below:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it will be very confusing that users find our APIs has a function "GetBuildInfoString" but it always returns empty? Most users do not build onnxruntime from source. They use our prebuilt packages from nuget.org or the github release page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snnn I have reverted the change related to git in cmake/onnxruntime_config.h.in
. For GetBuildInfoString
in envs that has no git, it will returns the build type and cxx flags as follows. If the env has git, it will contain more information. Is it better?
I have also reverted the change in tuning_context_impl.h
since the commit id requires git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snnn Do you have more comments on this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No git.
} | ||
|
||
Status TuningResultsValidator::ValidateOrtGitCommit(const std::string& value) const { | ||
// TODO: | ||
ORT_UNUSED_PARAMETER(value); | ||
ORT_RETURN_IF(value != ORT_GIT_COMMIT, "onnxruntime git commit mismatch"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snnn As you said there could be build envs that have no git, is it better to revert this change for ValidateOrtGitCommit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, reverted.
cmake/CMakeLists.txt
Outdated
@@ -1229,6 +1229,15 @@ if (onnxruntime_USE_VITISAI) | |||
endif() | |||
endif() | |||
|
|||
execute_process(COMMAND git log -1 --format=%h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snnn It does not matter whether the build envs have git or not. The cmake command won't fail. Instead, it will output to the variable ORT_GIT_COMMIT
& ORT_GIT_BRANCH
with an empty string. To make this clearer, I added a comment here and explicitly change the empty string to "Not-Available". An example is showed below:
/// git commit id, build type(Debug/Release/RelWithDebInfo) and cmake cpp flags. | ||
/// </summary> | ||
/// <returns>string</returns> | ||
std::string GetBuildInfoString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to make it available in the python bindings as well. Any test to check its value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I will take a look at how to add the python binding and the test to cover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xadupre I have added the build info to python bindings. The figure below shows the effect by some temporary code.
5d1ffb3
to
ca7cedf
Compare
All API changes need to be reviewed by him. |
@@ -1229,6 +1229,19 @@ if (onnxruntime_USE_VITISAI) | |||
endif() | |||
endif() | |||
|
|||
set(ORT_BUILD_INFO "ORT Build Info: ") | |||
find_package(Git) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All ONNX Runtime's build pipelines are hosted on Azure DevOps, which already expose this information through environment variables. https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml . The name of the env var is: "BUILD_SOURCEVERSION".
cmake can read env vars:
https://cmake.org/cmake/help/latest/variable/ENV.html
So we can add an if there to test the variable exists or not first. Then only run "find_package(Git)" when the env doesn't exist.
You don't have to make this enhancement for us. I just want to speak it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If from the beginning we were very strict on this, we won't see such an issue: #15678
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If from the beginning we were very strict on this, we won't see such an issue: #15678
By this, you mean the ORTCHAR_T*
problem, right? Yes, I have changed const char *
to const ORTCHAR_T *
@@ -619,7 +619,8 @@ struct OrtApiBase { | |||
* older than the version created with this header file. | |||
*/ | |||
const OrtApi*(ORT_API_CALL* GetApi)(uint32_t version)NO_EXCEPTION; | |||
const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1") | |||
const char*(ORT_API_CALL* GetVersionString)(void)NO_EXCEPTION; ///< Returns a null terminated string of the version of the Onnxruntime library (eg: "1.8.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we should use const ORTCHAR_T* instead of const char*, because on Windows usually we prefer to use wide char.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. GetVersionString
is originally defined using char *
. I will change both.
LGTM. I hope the "const char*" could be changed to "const ORTCHAR_T*" to avoid confusion. |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 9 pipeline(s). |
/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
Azure Pipelines successfully started running 7 pipeline(s). |
Ahahaha, a good try to communicae with Microsoft ORT team. Antgroup will try to contribute more back to ORT based on what we did during last years. ORT rocks! |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 7 pipeline(s). |
/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 7 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
assert(version != NULL); | ||
#ifdef _WIN32 | ||
size_t len = wcslen(version); | ||
jstring versionStr = (*jniEnv)->NewString(jniEnv, (const jchar*)version, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, Java use UTF-16-BE while most Windows use UTF-16-LE. @Craigacp, is it true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't transform the output of jstring->GetStringChars to change UTF-16 endianness on Windows, and it can load & save things to those paths correctly. So I would expect it to be the same on platforms that we currently test in the CI. If it's the same on all platforms is beyond my knowledge of Windows. It should be straightforward to modify https://github.com/microsoft/onnxruntime/blob/main/java/src/test/java/ai/onnxruntime/InferenceTest.java#L74 to test that the output is correct. I haven't modified that test to check the string because it'll need updating every time the version number is bumped so it seems like it would fail a bunch of pipelines.
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline |
/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
Azure Pipelines successfully started running 9 pipeline(s). |
Azure Pipelines successfully started running 7 pipeline(s). |
55d910d
to
5fb5217
Compare
/azp run Windows CPU CI Pipeline, Windows GPU CI Pipeline, Windows GPU TensorRT CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline, orttraining-ortmodule-distributed |
/azp run Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline, Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline |
Azure Pipelines successfully started running 7 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
Thanks to @snnn @HectorSVC for your patience. :-) |
Happy holidays! |
### Description <!-- Describe your changes. --> 1. Add Build Info API to onnx. 2. Fix compile error while building onnxruntime_benchmark in MacOs. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> 1. When Onnxruntime lib is serving online, we need a way to detect how this lib is built. This PR helps the developer to get the build information using `strings` such as git branch, git commit id, build type and cmake cxx flags, which is showed as follows. ![image](https://user-images.githubusercontent.com/19584326/233794371-b2f95a2c-27fb-4709-a6dd-bf4bb12b0b5b.png) ![image](https://user-images.githubusercontent.com/19584326/233794360-f96f5d2e-332c-405c-83f1-370ccc2b86f8.png) If the build env has no git, there will be no git related infor: ![image](https://user-images.githubusercontent.com/19584326/234558596-298c1b01-9a90-41bf-9372-7259a8f8e5be.png) 3. Fix the following compile error while building benchmark in MacOs. ![image](https://user-images.githubusercontent.com/19584326/233793571-c261ac1f-47b2-434d-a293-7e9edc6c8a66.png) --------- Co-authored-by: Yuhong Guo <yuhong.gyh@antgroup.com>
What is the reason why simple version information is being returned as ORTTCHAR instead of UTF-8 as all other strings inside ORT? That typedef was introduced for paths, otherwise all strings are expected to contain UTF-8. It is just makes coding so much more complicated for what essentially is a stupid version string. |
…m to OrtApi (#15921) ### Description This PR partially reverts changes introduced in #15643 We make two API return std::string always in UTF-8. We also move the entry points from OrtApiBase to OrtApi to make them versioned. ### Motivation and Context `GetVersionString` always returns x.y.z numbers that are not subject to internationalization. `GetBuildInfoString` can hold international chars, but UTF-8 should be fine to contain those. We prefix them with u8"" in case the compiler default charset is not UTF-8. Furthermore, creating platform dependent APIs is discouraged. `ORTCHAR_T` is platform dependent and was created for paths only. On non-unix platforms would still produce `std::string` that can only contain UTF-8 The API was introduced after the latest release, and can still be adjusted.
@yuslepukhin Sorry for the inconvenience. I just followed the comment from @snnn , and not expected that would bring so much trouble. I learned that "We define all strings as UTF-8 internally, except Windows paths.". Thanks. |
…m to OrtApi (#15921) ### Description This PR partially reverts changes introduced in #15643 We make two API return std::string always in UTF-8. We also move the entry points from OrtApiBase to OrtApi to make them versioned. ### Motivation and Context `GetVersionString` always returns x.y.z numbers that are not subject to internationalization. `GetBuildInfoString` can hold international chars, but UTF-8 should be fine to contain those. We prefix them with u8"" in case the compiler default charset is not UTF-8. Furthermore, creating platform dependent APIs is discouraged. `ORTCHAR_T` is platform dependent and was created for paths only. On non-unix platforms would still produce `std::string` that can only contain UTF-8 The API was introduced after the latest release, and can still be adjusted.
…m to OrtApi (#15921) This PR partially reverts changes introduced in #15643 We make two API return std::string always in UTF-8. We also move the entry points from OrtApiBase to OrtApi to make them versioned. `GetVersionString` always returns x.y.z numbers that are not subject to internationalization. `GetBuildInfoString` can hold international chars, but UTF-8 should be fine to contain those. We prefix them with u8"" in case the compiler default charset is not UTF-8. Furthermore, creating platform dependent APIs is discouraged. `ORTCHAR_T` is platform dependent and was created for paths only. On non-unix platforms would still produce `std::string` that can only contain UTF-8 The API was introduced after the latest release, and can still be adjusted.
…m to OrtApi (#15921) This PR partially reverts changes introduced in #15643 We make two API return std::string always in UTF-8. We also move the entry points from OrtApiBase to OrtApi to make them versioned. `GetVersionString` always returns x.y.z numbers that are not subject to internationalization. `GetBuildInfoString` can hold international chars, but UTF-8 should be fine to contain those. We prefix them with u8"" in case the compiler default charset is not UTF-8. Furthermore, creating platform dependent APIs is discouraged. `ORTCHAR_T` is platform dependent and was created for paths only. On non-unix platforms would still produce `std::string` that can only contain UTF-8 The API was introduced after the latest release, and can still be adjusted.
Description
Motivation and Context
strings
such as git branch, git commit id, build type and cmake cxx flags, which is showed as follows.If the build env has no git, there will be no git related infor: