Fix warning C4003 in ORT python binding code (#18612)

### Description
Fix warning C4003 in ORT python binding code.

### Motivation and Context
It's better to fix the warning instead of suppressing it.
This commit is contained in:
Changming Sun 2023-11-30 08:07:47 -08:00 committed by GitHub
parent 1b5675ff0f
commit 23a91c8ba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 22 deletions

View file

@ -16,11 +16,13 @@ static constexpr bool HAS_COLLECTIVE_OPS = true;
static constexpr bool HAS_COLLECTIVE_OPS = false;
#endif
void CreateInferencePybindStateModule(py::module& m);
bool CreateInferencePybindStateModule(py::module& m);
void CreateQuantPybindModule(py::module& m);
PYBIND11_MODULE(onnxruntime_pybind11_state, m) {
CreateInferencePybindStateModule(m);
if (!CreateInferencePybindStateModule(m)) {
throw pybind11::import_error();
}
// move it out of shared method since training build has a little different behavior.
m.def(
"get_available_providers", []() -> const std::vector<std::string>& { return GetAvailableExecutionProviderNames(); },

View file

@ -49,16 +49,12 @@ namespace onnxruntime {
} // namespace onnxruntime
#if defined(_MSC_VER)
#pragma warning(disable : 4267 4996 4503 4003)
#pragma warning(disable : 4267 4996 4503)
#endif // _MSC_VER
#include <iterator>
#include <algorithm>
#if defined(_MSC_VER)
#pragma warning(disable : 4267 4996 4503 4003)
#endif // _MSC_VER
namespace onnxruntime {
namespace python {
@ -2059,15 +2055,11 @@ including arg name, arg type (contains both type and shape).)pbdoc")
.export_values();
}
void CreateInferencePybindStateModule(py::module& m) {
bool CreateInferencePybindStateModule(py::module& m) {
m.doc() = "pybind11 stateful interface to ONNX runtime";
RegisterExceptions(m);
// Initialization of the module
([]() -> void {
// import_array1() forces a void return value.
import_array1();
})();
import_array1(false);
auto env = GetEnv();
@ -2087,13 +2079,13 @@ void CreateInferencePybindStateModule(py::module& m) {
addGlobalSchemaFunctions(m);
addOpSchemaSubmodule(m);
addOpKernelSubmodule(m);
return true;
}
void InitArray() {
([]() -> void {
// import_array1() forces a void return value.
import_array1();
})();
// This function is only used by orttraining module
bool InitArray() {
import_array1(false);
return true;
}
namespace {
@ -2136,8 +2128,6 @@ class EnvInitializer {
private:
EnvInitializer() {
// Initialization of the module
InitArray();
std::unique_ptr<Environment> env_ptr;
Env::Default().GetTelemetryProvider().SetLanguageProjection(OrtLanguageProjection::ORT_PROJECTION_PYTHON);
OrtPybindThrowIfError(Environment::Create(std::make_unique<LoggingManager>(

View file

@ -45,7 +45,7 @@ void addObjectMethodsForEager(py::module& m);
#ifdef ENABLE_LAZY_TENSOR
void addObjectMethodsForLazyTensor(py::module& m);
#endif
void InitArray();
bool InitArray();
bool GetDyanmicExecutionProviderHash(
const std::string& ep_shared_lib_path,
@ -225,7 +225,7 @@ class TrainingEnvInitialzer {
private:
TrainingEnvInitialzer() {
InitArray();
ORT_ENFORCE(InitArray());
Env::Default().GetTelemetryProvider().SetLanguageProjection(OrtLanguageProjection::ORT_PROJECTION_PYTHON);
ort_training_env_ = std::make_unique<ORTTrainingPythonEnv>();
}