From 91936864ce823b16207e9c3dad5958c8adcea73f Mon Sep 17 00:00:00 2001 From: Ankur Verma <31362771+ankurverma85@users.noreply.github.com> Date: Mon, 26 Jul 2021 18:03:12 -0700 Subject: [PATCH] Expose additional shared_provider APIs (#8478) --- .../providers/shared_library/provider_interfaces.h | 10 ++++++---- onnxruntime/core/session/provider_bridge_ort.cc | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/onnxruntime/core/providers/shared_library/provider_interfaces.h b/onnxruntime/core/providers/shared_library/provider_interfaces.h index 2971099383..bc60bfbc86 100644 --- a/onnxruntime/core/providers/shared_library/provider_interfaces.h +++ b/onnxruntime/core/providers/shared_library/provider_interfaces.h @@ -113,6 +113,8 @@ struct Node__EdgeIterator { // calls the virtual function (which will lead to infinite recursion in the bridge). There is no known way to get the non virtual member // function pointer implementation in this case. struct ProviderHost { + virtual const OrtApiBase* OrtGetApiBase() = 0; + virtual void* HeapAllocate(size_t size) = 0; virtual void HeapFree(void*) = 0; @@ -726,14 +728,14 @@ struct ProviderHost { virtual void AllocatorManager__InsertAllocator(AllocatorManager* p, AllocatorPtr allocator) = 0; virtual AllocatorPtr AllocatorManager__GetAllocator(const AllocatorManager* p, int id, OrtMemType mem_type) = 0; -#ifdef USE_CUDA - - virtual PhiloxGenerator& PhiloxGenerator__Default() = 0; - #if defined(ENABLE_TRAINING) && defined(ORT_USE_NCCL) virtual training::DistributedRunContext& GetDistributedRunContextInstance() = 0; #endif +#ifdef USE_CUDA + + virtual PhiloxGenerator& PhiloxGenerator__Default() = 0; + #ifdef ENABLE_TRAINING_TORCH_INTEROP virtual void contrib__PythonOpBase__Init(contrib::PythonOpBase* p, const OpKernelInfo& info) = 0; virtual void contrib__PythonOpBase__Clear(contrib::PythonOpBase* p) = 0; diff --git a/onnxruntime/core/session/provider_bridge_ort.cc b/onnxruntime/core/session/provider_bridge_ort.cc index 1f9749009b..b3753f4fde 100644 --- a/onnxruntime/core/session/provider_bridge_ort.cc +++ b/onnxruntime/core/session/provider_bridge_ort.cc @@ -33,7 +33,7 @@ #include "orttraining/core/framework/torch/refcount_tracker.h" #endif #endif -#if defined(USE_CUDA) && defined(ORT_USE_NCCL) +#if defined(ORT_USE_NCCL) #include "orttraining/training_ops/cuda/communication/nccl_service.h" #include "orttraining/core/framework/distributed_run_context.h" #endif @@ -135,6 +135,8 @@ struct Node__EdgeIterator_Impl : Node__EdgeIterator { // wrapped = The internal object is exposed as an opaque pointer, so we wrap it in a class that forwards every call to the real calls. No members are ever directly accessed // direct = Same implementation is used for shared providers & core code, but some of the methods need to be routed through here to make the linker happy struct ProviderHostImpl : ProviderHost { + const OrtApiBase* OrtGetApiBase() override { return ::OrtGetApiBase(); } + void* HeapAllocate(size_t size) override { return new uint8_t[size]; } void HeapFree(void* p) override { delete[] reinterpret_cast(p); } @@ -809,14 +811,14 @@ struct ProviderHostImpl : ProviderHost { void AllocatorManager__InsertAllocator(AllocatorManager* p, AllocatorPtr allocator) override { p->AllocatorManager::InsertAllocator(allocator); } AllocatorPtr AllocatorManager__GetAllocator(const AllocatorManager* p, int id, OrtMemType mem_type) override { return p->AllocatorManager::GetAllocator(id, mem_type); }; -#ifdef USE_CUDA - - PhiloxGenerator& PhiloxGenerator__Default() override { return PhiloxGenerator::Default(); } - #if defined(ENABLE_TRAINING) && defined(ORT_USE_NCCL) training::DistributedRunContext& GetDistributedRunContextInstance() override { return training::DistributedRunContext::GetInstance(); } #endif +#ifdef USE_CUDA + + PhiloxGenerator& PhiloxGenerator__Default() override { return PhiloxGenerator::Default(); } + #ifdef ENABLE_TRAINING_TORCH_INTEROP void contrib__PythonOpBase__Init(contrib::PythonOpBase* p, const OpKernelInfo& info) override { p->PythonOpBase::Init(info); } void contrib__PythonOpBase__Clear(contrib::PythonOpBase* p) override { p->PythonOpBase::Clear(); }