mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
* Add onnxruntime-windows api. * minor fixes * add to package headers * Build ort_dml_api for provider extensions. * Cleanup * misc comment * remove winml specific comments * use dml check in onnxruntime * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/session/onnxruntime_c_api.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update onnxruntime/core/session/onnxruntime_c_api.cc Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update onnxruntime/core/session/ort_apis.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update winml/test/adapter/AdapterSessionTest.cpp Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update onnxruntime/core/session/onnxruntime_c_api.cc Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update winml/adapter/winml_adapter_c_api.cpp Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/session/onnxruntime_c_api.h Co-authored-by: Pranav Sharma <prs@microsoft.com> * Update onnxruntime/core/session/onnxruntime_c_api.cc Co-authored-by: Pranav Sharma <prs@microsoft.com> * Update winml/adapter/winml_adapter_c_api.cpp * PR feedback * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * Update include/onnxruntime/core/providers/dml/dml_provider_factory.h Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> * PR feedback * merge resolution and unreference param * (naming) Remove Dml prefix * maybe unused version * move DML code into DML path. CIs failing because DML is not available when --use_dml is not on * fix warning causing local build failures after merging * Change getvaluememoryinfo to gettensormemoryinfo * minor breaks * fix comment paste * fix comment Co-authored-by: Sheil Kumar <sheilk@microsoft.com> Co-authored-by: Dwayne Robinson <dwayner@microsoft.com> Co-authored-by: Pranav Sharma <prs@microsoft.com>
79 lines
No EOL
2.7 KiB
C++
79 lines
No EOL
2.7 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#pragma once
|
|
|
|
#include "adapter/pch.h"
|
|
|
|
#include "winml_adapter_c_api.h"
|
|
#include "core/session/ort_apis.h"
|
|
#include "winml_adapter_apis.h"
|
|
#include "core/framework/error_code_helper.h"
|
|
#include "core/framework/execution_provider.h"
|
|
|
|
namespace winmla = Windows::AI::MachineLearning::Adapter;
|
|
|
|
struct OrtAllocatorWrapper : public OrtAllocator {
|
|
public:
|
|
OrtAllocatorWrapper(onnxruntime::AllocatorPtr impl) : impl_(impl) {
|
|
version = ORT_API_VERSION;
|
|
Alloc = AllocImpl;
|
|
Free = FreeImpl;
|
|
Info = InfoImpl;
|
|
}
|
|
|
|
static void* ORT_API_CALL AllocImpl(struct OrtAllocator* this_, size_t size) {
|
|
return static_cast<OrtAllocatorWrapper*>(this_)->impl_->Alloc(size);
|
|
}
|
|
static void ORT_API_CALL FreeImpl(struct OrtAllocator* this_, void* p) {
|
|
return static_cast<OrtAllocatorWrapper*>(this_)->impl_->Free(p);
|
|
}
|
|
static const struct OrtMemoryInfo* ORT_API_CALL InfoImpl(const struct OrtAllocator* this_) {
|
|
return &(static_cast<const OrtAllocatorWrapper*>(this_)->impl_->Info());
|
|
}
|
|
|
|
private:
|
|
onnxruntime::AllocatorPtr impl_;
|
|
};
|
|
|
|
ORT_API_STATUS_IMPL(winmla::ExecutionProviderSync, _In_ OrtExecutionProvider* provider) {
|
|
API_IMPL_BEGIN
|
|
const auto execution_provider = reinterpret_cast<onnxruntime::IExecutionProvider*>(provider);
|
|
ORT_API_RETURN_IF_STATUS_NOT_OK(execution_provider->Sync());
|
|
return nullptr;
|
|
API_IMPL_END
|
|
}
|
|
|
|
ORT_API_STATUS_IMPL(winmla::GetProviderAllocator, _In_ OrtExecutionProvider* provider, OrtAllocator** allocator) {
|
|
API_IMPL_BEGIN
|
|
const auto execution_provider = reinterpret_cast<onnxruntime::IExecutionProvider*>(provider);
|
|
auto allocator_ptr = execution_provider->GetAllocator(0, ::OrtMemType::OrtMemTypeDefault);
|
|
*allocator = new (std::nothrow) OrtAllocatorWrapper(allocator_ptr);
|
|
if (*allocator == nullptr) {
|
|
return OrtApis::CreateStatus(ORT_FAIL, "Out of memory");
|
|
}
|
|
return nullptr;
|
|
API_IMPL_END
|
|
}
|
|
|
|
ORT_API_STATUS_IMPL(winmla::GetProviderMemoryInfo, _In_ OrtExecutionProvider* provider, OrtMemoryInfo** memory_info) {
|
|
API_IMPL_BEGIN
|
|
const auto execution_provider = reinterpret_cast<onnxruntime::IExecutionProvider*>(provider);
|
|
|
|
auto allocator = execution_provider->GetAllocator(0, ::OrtMemType::OrtMemTypeDefault);
|
|
|
|
const auto& info = allocator->Info();
|
|
*memory_info = new (std::nothrow) OrtMemoryInfo(info.name, info.alloc_type, info.device, info.id, info.mem_type);
|
|
if (*memory_info == nullptr) {
|
|
return OrtApis::CreateStatus(ORT_FAIL, "Out of memory");
|
|
}
|
|
return nullptr;
|
|
API_IMPL_END
|
|
}
|
|
|
|
ORT_API_STATUS_IMPL(winmla::FreeProviderAllocator, _In_ OrtAllocator* allocator) {
|
|
API_IMPL_BEGIN
|
|
delete static_cast<OrtAllocatorWrapper*>(allocator);
|
|
return nullptr;
|
|
API_IMPL_END
|
|
} |