onnxruntime/onnxruntime/core/session/environment.cc
Dmitri Smirnov 17c8fe44e3
Integrate featurizers (#1573)
Added Sample Featurizer and Infrastructure
  Make featurizers and unit tests compile and run with GTest.
  Create definitions for the first featurizer kernel.
  Add new operator domain.
  Create datetime_transformer kernel and build.
  Move OPAQUE types definitions for featurizers kerneles out to a separate cc.
  Register them with the type system.
 Provide unit tests for new AutoML DateTimeTransformer kernel.
  Make necessary adjustments to the test infrastructure to make it run
  with new types.
2019-08-15 13:59:59 -07:00

93 lines
3.2 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "core/session/environment.h"
#include "core/framework/allocatormgr.h"
#include "core/graph/constants.h"
#include "core/graph/op.h"
#include "onnx/defs/operator_sets.h"
#include "onnx/defs/operator_sets-ml.h"
#ifndef DISABLE_CONTRIB_OPS
#include "core/graph/contrib_ops/contrib_defs.h"
#endif
#ifdef MICROSOFT_AUTOML
#include "core/graph/automl_ops/automl_defs.h"
#endif
namespace onnxruntime {
using namespace ::onnxruntime::common;
using namespace ONNX_NAMESPACE;
std::once_flag schemaRegistrationOnceFlag;
std::atomic<bool> Environment::is_initialized_{false};
Status Environment::Create(std::unique_ptr<Environment>& environment) {
environment = std::unique_ptr<Environment>(new Environment());
auto status = environment->Initialize();
return status;
}
Status Environment::Initialize() {
auto status = Status::OK();
try {
// Register Microsoft domain with min/max op_set version as 1/1.
std::call_once(schemaRegistrationOnceFlag, []() {
ONNX_NAMESPACE::OpSchemaRegistry::DomainToVersionRange::Instance().AddDomainToVersion(onnxruntime::kMSDomain, 1, 1);
ONNX_NAMESPACE::OpSchemaRegistry::DomainToVersionRange::Instance().AddDomainToVersion(onnxruntime::kMSNchwcDomain, 1, 1);
ONNX_NAMESPACE::OpSchemaRegistry::DomainToVersionRange::Instance().AddDomainToVersion(onnxruntime::kMSAutoMLDomain, 1, 1);
// Register contributed schemas.
// The corresponding kernels are registered inside the appropriate execution provider.
#ifndef DISABLE_CONTRIB_OPS
contrib::RegisterContribSchemas();
#endif
#ifdef MICROSOFT_AUTOML
automl::RegisterAutoMLSchemas();
#endif
RegisterOnnxOperatorSetSchema();
RegisterOnnxMLOperatorSetSchema();
});
// Register MemCpy schema;
// These ops are internal-only, so register outside of onnx
ORT_ATTRIBUTE_UNUSED ONNX_OPERATOR_SCHEMA(MemcpyFromHost)
.Input(0, "X", "input", "T")
.Output(0, "Y", "output", "T")
.TypeConstraint(
"T",
OpSchema::all_tensor_types(),
"Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.")
.TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)
.SetDoc(R"DOC(
Internal copy node
)DOC");
ORT_ATTRIBUTE_UNUSED ONNX_OPERATOR_SCHEMA(MemcpyToHost)
.Input(0, "X", "input", "T")
.Output(0, "Y", "output", "T")
.TypeConstraint(
"T",
OpSchema::all_tensor_types(),
"Constrain to any tensor type. If the dtype attribute is not provided this must be a valid output type.")
.TypeAndShapeInferenceFunction(propagateShapeAndTypeFromFirstInput)
.SetDoc(R"DOC(
Internal copy node
)DOC");
is_initialized_ = true;
} catch (std::exception& ex) {
status = Status{ONNXRUNTIME, common::RUNTIME_EXCEPTION, std::string{"Exception caught: "} + ex.what()};
} catch (...) {
status = Status{ONNXRUNTIME, common::RUNTIME_EXCEPTION};
}
return status;
}
Environment::~Environment() {
::google::protobuf::ShutdownProtobufLibrary();
}
} // namespace onnxruntime