User/brianma/eo (#13152)

fixing SDL issues. One was a SAL mismatch, the other was handling an
optional null pointer.
This commit is contained in:
Brian Martin 2022-09-30 09:43:56 -07:00 committed by GitHub
parent 402e1995f0
commit c20abcab87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 55 deletions

View file

@ -21,7 +21,7 @@ ORT_API_STATUS(EnvConfigureCustomLoggerAndProfiler, _In_ OrtEnv* env, OrtLogging
// OrtModel methods
ORT_API_STATUS(CreateModelFromPath, _In_ const char* model_path, _In_ size_t size, _Outptr_ OrtModel** out);
ORT_API_STATUS(CreateModelFromData, _In_ void* data, _In_ size_t size, _Outptr_ OrtModel** out);
ORT_API_STATUS(CreateModelFromData, _In_opt_ void* data, _In_ size_t size, _Outptr_ OrtModel** out);
ORT_API_STATUS(CloneModel, _In_ const OrtModel* in, _Outptr_ OrtModel** out);
ORT_API_STATUS(ModelGetAuthor, _In_ const OrtModel* model, _Out_ const char** const author, _Out_ size_t* len);
ORT_API_STATUS(ModelGetName, _In_ const OrtModel* model, _Out_ const char** const name, _Out_ size_t* len);
@ -88,7 +88,7 @@ ORT_API_STATUS(CreateModel, _In_ int64_t opset, _Outptr_ OrtModel** out);
ORT_API_STATUS(ModelAddInput, _In_ OrtModel* model, _In_ const char* const input_name, _In_ OrtTypeInfo* info);
ORT_API_STATUS(ModelAddConstantInput, _In_ OrtModel* model, _In_ const char* const input_name, _In_ OrtTypeInfo* info, _In_ OrtValue* value);
ORT_API_STATUS(ModelAddOutput, _In_ OrtModel* model, _In_ const char* const output_name, _In_ OrtTypeInfo* info);
ORT_API_STATUS(ModelAddOperator,
ORT_API_STATUS(ModelAddOperator,
_In_ OrtModel* model,
_In_ const char* const op_type,
_In_ const char* const op_name,
@ -103,7 +103,7 @@ ORT_API_STATUS(ModelGetOpsetVersion, _In_ OrtModel* model, _In_ const char* cons
ORT_API_STATUS(OperatorGetNumInputs,
_In_ const char* const op_type,
_In_ int64_t opset,
_In_ const char* const op_domain,
_In_ const char* const op_domain,
_Out_ size_t* num_inputs);
ORT_API_STATUS(OperatorGetInputName,
@ -136,8 +136,8 @@ ORT_API_STATUS(JoinModels,
_In_ const char* const join_node_prefix);
ORT_API_STATUS(CreateThreadPool,
ThreadPoolType type,
OrtThreadPoolOptions* params,
_In_ ThreadPoolType type,
_In_ OrtThreadPoolOptions* params,
_Outptr_ OrtThreadPool** out);
// maps and sequences???
@ -146,4 +146,4 @@ ORT_API_STATUS(CreateThreadPool,
} // namespace Adapter
} // namespace MachineLearning
} // namespace AI
} // namespace Windows
} // namespace Windows

View file

@ -8,7 +8,7 @@
/**
* All APIs exported by winml_adapter_c_api.h are part of the private interface dedicated to supporting the WinML API.
* This contract is subject to change based on the needs of the WinML API and is not intended for direct use by callers
* This contract is subject to change based on the needs of the WinML API and is not intended for direct use by callers
* of the onnxruntime c-api and usage of APIs in this header are *not* supported by the onnxruntime product.
*/
@ -110,7 +110,7 @@ struct WinmlAdapterApi {
* There is no inferencing or evaluation setup performed. Only ONNX load is done to reflect on the model's inputs/outputs and other properties.
* This is used by WinML to support model reflection APIs.
*/
OrtStatus*(ORT_API_CALL* CreateModelFromData)(_In_ void* data, _In_ size_t size, _Outptr_ OrtModel** out)NO_EXCEPTION;
OrtStatus*(ORT_API_CALL* CreateModelFromData)(_In_opt_ void* data, _In_ size_t size, _Outptr_ OrtModel** out)NO_EXCEPTION;
/**
* CloneModel
@ -236,7 +236,7 @@ struct WinmlAdapterApi {
* ModelEnsureNoFloat16
* This api checks whether the model requires float 16 support.
* This is used by WinML to fail gracefully when float 16 support is not available on the device.
*
*
* Can this API be moved into the EP during session initialization. Currently we do an early fp16 check to avoid initialization when it is not supported.
*/
OrtStatus*(ORT_API_CALL* ModelEnsureNoFloat16)(_In_ const OrtModel* model)NO_EXCEPTION;
@ -267,7 +267,7 @@ struct WinmlAdapterApi {
* CreateSessionWithoutModel
* This api is used to create a Session that is completely uninitialized. While there are other Session creation APIs in the
* c-abi, WinML uses this so that it can perform optimizations prior to loading the model, and initializing.
* Moreover, WinML needs a new api to support the OrtModel type, and prevent the parsing model protobufs again on session creation.
* Moreover, WinML needs a new api to support the OrtModel type, and prevent the parsing model protobufs again on session creation.
*/
OrtStatus*(ORT_API_CALL* CreateSessionWithoutModel)(_In_ OrtEnv* env, _In_ const OrtSessionOptions* options,
_In_ OrtThreadPool* inter_op_thread_pool, _In_ OrtThreadPool* intra_op_thread_pool, _Outptr_ OrtSession** session)NO_EXCEPTION;
@ -289,8 +289,8 @@ struct WinmlAdapterApi {
/**
* SessionRegisterGraphTransformers
* This api is used to enable DML specific graph transformations on an OrtSession.
*
* Ideally these transformations should be configured by the contract between the runtime and the EP and not overridden by WinML.
*
* Ideally these transformations should be configured by the contract between the runtime and the EP and not overridden by WinML.
*/
OrtStatus*(ORT_API_CALL* SessionRegisterGraphTransformers)(_In_ OrtSession* session)NO_EXCEPTION;
@ -303,7 +303,7 @@ struct WinmlAdapterApi {
/**
* SessionLoadAndPurloinModel
* This api is used to load an OrtModel into an OrtSession.
*
*
* Don't free the 'out' value as this API will defunct and release the OrtModel internally.
*/
OrtStatus*(ORT_API_CALL* SessionLoadAndPurloinModel)(_In_ OrtSession* session, _In_ OrtModel* model)NO_EXCEPTION;
@ -311,7 +311,7 @@ struct WinmlAdapterApi {
/**
* SessionStartProfiling
* This api is used to start profiling OrtSession. The existing mechanism only allows configuring profiling at session creation.
*
*
* WinML uses this to toggle profilling on and off based on if a telemetry providers are being listened to.
*/
OrtStatus*(ORT_API_CALL* SessionStartProfiling)(_In_ OrtEnv* env, _In_ OrtSession* session)NO_EXCEPTION;
@ -319,7 +319,7 @@ struct WinmlAdapterApi {
/**
* SessionEndProfiling
* This api is used to end profiling OrtSession. The existing mechanism only allows configuring profiling at session creation.
*
*
* WinML uses this to toggle profilling on and off based on if a telemetry providers are being listened to.
*/
OrtStatus*(ORT_API_CALL* SessionEndProfiling)(_In_ OrtSession* session)NO_EXCEPTION;
@ -327,7 +327,7 @@ struct WinmlAdapterApi {
/**
* SessionCopyOneInputAcrossDevices
* This api is used to copy and create an OrtValue input to prepare the input on the correct device.
*
*
* WinML uses this to copy gpu device OrtValues to the CPU and vice-versa.
*/
OrtStatus*(ORT_API_CALL* SessionCopyOneInputAcrossDevices)(_In_ OrtSession* session, _In_ const char* const input_name, _In_ OrtValue* orig_value, _Outptr_ OrtValue** new_value)NO_EXCEPTION;
@ -345,7 +345,7 @@ struct WinmlAdapterApi {
/**
* SessionGetIntrapOpThreadSpinning
* This api returns false if the ort session options config entry "session.intra_op.allow_spinning" is set to "0", and true otherwise
*
*
* WinML uses this to determine that the intra op thread spin policy was set correctly through OrtSessionOptions
*/
OrtStatus*(ORT_API_CALL* SessionGetIntraOpThreadSpinning)(_In_ OrtSession* session, _Out_ bool* allow_spinning)NO_EXCEPTION;
@ -361,7 +361,7 @@ struct WinmlAdapterApi {
/**
* DmlExecutionProviderSetDefaultRoundingMode
* This api is used to configure the DML EP to turn on/off rounding.
*
*
* WinML uses this to disable rounding during session initialization and then enables it again post initialization.
*/
OrtStatus*(ORT_API_CALL* DmlExecutionProviderSetDefaultRoundingMode)(_In_ OrtExecutionProvider* dml_provider, _In_ bool is_enabled)NO_EXCEPTION;
@ -369,7 +369,7 @@ struct WinmlAdapterApi {
/**
* DmlExecutionProviderFlushContext
* This api is used to flush the DML EP.
*
*
* WinML communicates directly with DML to perform this as an optimization.
*/
OrtStatus*(ORT_API_CALL* DmlExecutionProviderFlushContext)(_In_ OrtExecutionProvider* dml_provider)NO_EXCEPTION;
@ -377,7 +377,7 @@ struct WinmlAdapterApi {
/**
* DmlExecutionProviderReleaseCompletedReferences
* This api is used to release completed references after first run the DML EP.
*
*
* WinML communicates directly with DML to perform this as an optimization.
*/
OrtStatus*(ORT_API_CALL* DmlExecutionProviderReleaseCompletedReferences)(_In_ OrtExecutionProvider* dml_provider)NO_EXCEPTION;
@ -385,7 +385,7 @@ struct WinmlAdapterApi {
/**
* DmlCopyTensor
* This api is used copy a tensor allocated by the DML EP Allocator to the CPU.
*
*
* WinML uses this when graphs are evaluated with DML, and their outputs remain on the GPU but need to be copied back to the CPU.
*/
OrtStatus*(ORT_API_CALL* DmlCopyTensor)(_In_ OrtExecutionProvider* provider, _In_ OrtValue* src, _In_ OrtValue* dst)NO_EXCEPTION;
@ -393,7 +393,7 @@ struct WinmlAdapterApi {
/**
* GetProviderMemoryInfo
* This api gets the memory info object associated with an EP.
*
*
* WinML uses this to manage caller specified D3D12 inputs/outputs. It uses the memory info here to call DmlCreateGPUAllocationFromD3DResource.
*/
OrtStatus*(ORT_API_CALL* GetProviderMemoryInfo)(_In_ OrtExecutionProvider* provider, OrtMemoryInfo** memory_info)NO_EXCEPTION;
@ -401,7 +401,7 @@ struct WinmlAdapterApi {
/**
* GetProviderAllocator
* This api gets associated allocator used by a provider.
*
*
* WinML uses this to create tensors, and needs to hold onto the allocator for the duration of the associated value's lifetime.
*/
OrtStatus*(ORT_API_CALL* GetProviderAllocator)(_In_ OrtExecutionProvider* provider, OrtAllocator** allocator)NO_EXCEPTION;
@ -409,7 +409,7 @@ struct WinmlAdapterApi {
/**
* FreeProviderAllocator
* This api frees an allocator.
*
*
* WinML uses this to free the associated allocator for an ortvalue when creating tensors.
* Internally this derefs a shared_ptr.
*/
@ -418,7 +418,7 @@ struct WinmlAdapterApi {
/**
* ExecutionProviderSync
* This api syncs the EP.
*
*
* WinML uses this to sync EP inputs/outputs directly.
*/
OrtStatus*(ORT_API_CALL* ExecutionProviderSync)(_In_ OrtExecutionProvider* provider)NO_EXCEPTION;
@ -434,7 +434,7 @@ struct WinmlAdapterApi {
/**
* ValueGetDeviceId
* This api returns the device id of the OrtValue.
*
*
* WinML uses this to determine if an OrtValue is created on the needed device.
*/
OrtStatus*(ORT_API_CALL* ValueGetDeviceId)(_In_ OrtValue* ort_value, _Out_ int16_t* device_id)NO_EXCEPTION;
@ -442,7 +442,7 @@ struct WinmlAdapterApi {
/**
* SessionGetInputRequiredDeviceId
* This api returns the required device id for a model input.
*
*
* WinML uses this to determine if an OrtValue is created on the needed device.
*/
OrtStatus*(ORT_API_CALL* SessionGetInputRequiredDeviceId)(_In_ OrtSession* session, _In_ const char* const input_name, _Out_ int16_t* device_id)NO_EXCEPTION;
@ -471,7 +471,7 @@ struct WinmlAdapterApi {
OrtStatus*(ORT_API_CALL* OperatorGetNumInputs)(
_In_ const char* const op_type,
_In_ int64_t opset,
_In_ const char* const op_domain,
_In_ const char* const op_domain,
_Out_ size_t* num_inputs)NO_EXCEPTION;
OrtStatus*(ORT_API_CALL* OperatorGetInputName)(
@ -511,4 +511,4 @@ struct WinmlAdapterApi {
ORT_CLASS_RELEASE(Model);
ORT_CLASS_RELEASE(ThreadPool);
};
};

View file

@ -127,7 +127,7 @@ static OrtStatus* CreateModelProto(const char* path, std::unique_ptr<ONNX_NAMESP
auto path_str = std::string(path);
auto wide_path = onnxruntime::ToWideString(path_str);
_set_errno(0); // clear errno
_wsopen_s(
&file_descriptor,
@ -235,7 +235,7 @@ ORT_API_STATUS_IMPL(winmla::CreateModelFromPath, _In_ const char* model_path, _I
API_IMPL_END
}
ORT_API_STATUS_IMPL(winmla::CreateModelFromData, _In_ void* data, _In_ size_t size, _Outptr_ OrtModel** out) {
ORT_API_STATUS_IMPL(winmla::CreateModelFromData, _In_opt_ void* data, _In_ size_t size, _Outptr_ OrtModel** out) {
API_IMPL_BEGIN
if (auto status = OrtModel::CreateOrtModelFromData(data, size, out)) {
return status;
@ -617,7 +617,7 @@ ORT_API_STATUS_IMPL(winmla::ModelAddOperator,
_In_ OrtModel* model,
_In_ const char* const op_type,
_In_ const char* const op_name,
_In_ int64_t opset,
_In_ int64_t opset,
_In_ const char* const op_domain,
_In_ const char* const* input_names, _In_ size_t num_inputs,
_In_ const char* const* output_names, _In_ size_t num_outputs,
@ -635,7 +635,7 @@ ORT_API_STATUS_IMPL(winmla::ModelAddOperator,
for (size_t i = 0; i < num_attributes; i++) {
auto tensor = attribute_values[i]->GetMutable<onnxruntime::Tensor>();
auto attr = node.add_attribute();
attr->set_name(attribute_names[i]);
auto& schema_attribute_definition = all_attributes.at(attribute_names[i]);
@ -822,7 +822,7 @@ ORT_API_STATUS_IMPL(winmla::CreateThreadPool,
params.set_denormal_as_zero = options->set_denormal_as_zero;
auto unique_tp = onnxruntime::concurrency::CreateThreadPool(&onnxruntime::Env::Default(), params, (onnxruntime::concurrency::ThreadPoolType)type);
*out = reinterpret_cast<OrtThreadPool*>(unique_tp.release());
*out = reinterpret_cast<OrtThreadPool*>(unique_tp.release());
return nullptr;
API_IMPL_END
}
@ -849,7 +849,7 @@ ORT_API_STATUS_IMPL(winmla::JoinModels,
if (promote_unlinked_outputs) {
// Copy the output of the first model
auto first_outputs = first_model_proto->graph().output();
// Clear all outputs
first_model_proto->mutable_graph()->mutable_output()->Clear();
@ -929,7 +929,7 @@ ORT_API_STATUS_IMPL(winmla::JoinModels,
// does the domain exist in the first model?
auto found_it = std::find_if(first_model_proto->mutable_opset_import()->begin(), first_model_proto->mutable_opset_import()->end(),
[&domain](auto& mutable_opset_import) {
auto first_model_domain = mutable_opset_import.has_domain() ? mutable_opset_import.domain() : std::string("");
return 0 == strcmp(first_model_domain.c_str(), domain.c_str());
});
@ -942,7 +942,7 @@ ORT_API_STATUS_IMPL(winmla::JoinModels,
}
// add identity ops to rename all of the first model outputs to secondmodel inputs with prefix for each linkage
for (int i = 0; i < num_linkages; i++) {
for (int i = 0; i < num_linkages; i++) {
auto op_output_name = second_model_prefix + *(input_names + i);
const char* const op_output_name_const_str = op_output_name.c_str();
std::string name = "IdentityTo";
@ -960,4 +960,4 @@ ORT_API_STATUS_IMPL(winmla::JoinModels,
return nullptr;
API_IMPL_END
}
}

View file

@ -171,7 +171,7 @@ HRESULT OnnxruntimeValue::GetResource(_winml::Resource& out) {
void* mutable_data = nullptr;
RETURN_HR_IF_NOT_OK_MSG(ort_api->GetTensorMutableData(value_.get(), &mutable_data),
ort_api);
const OrtMemoryInfo* ort_memory_info;
RETURN_HR_IF_NOT_OK_MSG(ort_api->GetTensorMemoryInfo(value_.get(), &ort_memory_info),
ort_api);
@ -186,7 +186,7 @@ HRESULT OnnxruntimeValue::GetResource(_winml::Resource& out) {
RETURN_HR_IF_NOT_OK_MSG(ort_api->CreateAllocator(engine_->UseOrtSession(), ort_memory_info, &ort_allocator),
ort_api);
auto allocator = UniqueOrtAllocator(ort_allocator, ort_api->ReleaseAllocator);
winrt::com_ptr<ID3D12Resource> resource;
RETURN_HR_IF_NOT_OK_MSG(ort_dml_api->GetD3D12ResourceFromAllocation(allocator.get(), mutable_data,
resource.put()),
@ -568,7 +568,7 @@ HRESULT OnnxruntimeEngine::CreateTensorValueFromDefaultAllocator(const int64_t*
/*
* OnnxruntimeEngine::CreateTensorValue
*
*
* Used by callers like ImageFeatureValue to allocate a cpu or gpu OrtValue with ORT owned memory.
* In the image feature value case, tensorization creates temporary buffers, and will need to copy the value from
* its source location to the ort value. Since a copy is required, there is need to preserve the caller's memory locations.
@ -618,7 +618,7 @@ class DmlAllocatorWrapper : public Microsoft::WRL::RuntimeClass<
/*
* OnnxruntimeEngine::CreateTensorValueFromExternalD3DResource
*
*
* Used by callers like TensorBase to allocate a gpu OrtValue based on a called owned ID3D12Resource.
* WinML cannot use ORT allocators here since they will allocate the ID3D12Resource and force a copy from the user provided value.
*/
@ -678,7 +678,7 @@ HRESULT OnnxruntimeEngine::CreateTensorValueFromExternalD3DResource(ID3D12Resour
/*
* OnnxruntimeEngine::CreateStringTensorValueFromDataWithCopy
*
*
* Used by callers like TensorString to allocate a cpu OrtValue and populate the contents with use specified data.
* WinML cannot use CreateTensorWithDataAsOrtValue since externally allocated strings are not supported on the c-abi.
* The c-abi string implementation requires a copy the external buffer into its own internal std::string copy.
@ -698,7 +698,7 @@ HRESULT OnnxruntimeEngine::CreateStringTensorValueFromDataWithCopy(const char* c
/*
* OnnxruntimeEngine::CreateTensorValueFromExternalBuffer
*
*
* Used by callers like TensorBase<T> to allocate a cpu OrtValue that is backed by caller owned memory.
*/
HRESULT OnnxruntimeEngine::CreateTensorValueFromExternalBuffer(void* data, size_t size_in_bytes, const int64_t* shape, size_t count, winml::TensorKind kind, _Out_ IValue** out) {
@ -753,7 +753,7 @@ HRESULT OnnxruntimeEngine::CreateSequenceOfValuesValue(IValue** values, size_t s
/*
* OnnxruntimeEngine::CreateNullValue
*
*
* Used by callers like TensorBase<T> and the binding object to allocate a cpu OrtValue that is empty.
* This is used for WinML unbound outputs.
*/
@ -1341,7 +1341,7 @@ STDMETHODIMP OnnxruntimeEngineFactory::CreateModel(_In_ const char* model_path,
return S_OK;
}
STDMETHODIMP OnnxruntimeEngineFactory::CreateModel(_In_ void* data, _In_ size_t size, _Outptr_ IModel** out) {
STDMETHODIMP OnnxruntimeEngineFactory::CreateModel(_In_opt_ void* data, _In_ size_t size, _Outptr_ IModel** out) {
RETURN_IF_FAILED(EnsureEnvironment());
OrtModel* ort_model = nullptr;
if (auto status = winml_adapter_api_->CreateModelFromData(data, size, &ort_model)) {
@ -1511,10 +1511,10 @@ HRESULT OnnxruntimeThreading::SetInterOpThreadPool(UniqueOrtThreadPool&& inter_o
OrtThreadPool* OnnxruntimeThreading::UseIntraOpThreadPool()
{
return intra_op_ort_pool_.get();
return intra_op_ort_pool_.get();
}
OrtThreadPool* OnnxruntimeThreading::UseInterOpThreadPool()
{
return inter_op_ort_pool_.get();
}
return inter_op_ort_pool_.get();
}

View file

@ -142,7 +142,7 @@ class OnnxruntimeEngineFactory : public Microsoft::WRL::RuntimeClass<
STDMETHOD(CreateModel)
(_In_ const char* model_path, _In_ size_t len, _Outptr_ IModel** out) override;
STDMETHOD(CreateModel)
(_In_ void* data, _In_ size_t size, _Outptr_ IModel** out) override;
(_In_opt_ void* data, _In_ size_t size, _Outptr_ IModel** out) override;
STDMETHOD(CreateEmptyModel)
(_In_ int64_t opset, _Outptr_ IModel** out) override;
STDMETHOD(CreateEngineBuilder)
@ -184,7 +184,7 @@ public:
~OnnxruntimeThreading();
HRESULT RuntimeClassInitialize(OnnxruntimeEngineFactory* engine_factory);
HRESULT SetIntraOpThreadPool(UniqueOrtThreadPool&& intra_op_ort_pool);
HRESULT SetInterOpThreadPool(UniqueOrtThreadPool&& inter_op_ort_pool);
OrtThreadPool* UseIntraOpThreadPool();
@ -194,7 +194,7 @@ private:
Microsoft::WRL::ComPtr<OnnxruntimeEngineFactory> engine_factory_ = nullptr;
UniqueOrtThreadPool inter_op_ort_pool_;
UniqueOrtThreadPool intra_op_ort_pool_;
};
} // namespace _winml

View file

@ -206,7 +206,7 @@ IEngine : IUnknown {
MIDL_INTERFACE("69fbc1d5-66ff-4c79-b14d-fad288dbf8ca")
IThreading : IUnknown {
};
MIDL_INTERFACE("8ac0b6b9-4561-492b-b63d-a07bdd8292c6")
@ -234,7 +234,7 @@ IEngineBuilder : IUnknown {
STDMETHOD(SetIntraOpThreadSpinning)
(bool allow_spinning) PURE;
STDMETHOD(SetThreadPool)
(IThreading* thread_pool) PURE;
@ -249,7 +249,7 @@ IEngineFactory : IUnknown {
(_In_ const char* model_path, _In_ size_t len, _Outptr_ IModel** out) PURE;
STDMETHOD(CreateModel)
(_In_ void* data, _In_ size_t size, _Outptr_ IModel** out) PURE;
(_In_opt_ void* data, _In_ size_t size, _Outptr_ IModel** out) PURE;
STDMETHOD(CreateEmptyModel)
(_In_ int64_t opset, _Outptr_ IModel * *out) PURE;