mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-01 03:45:06 +00:00
Make IExecutionProvider::Type return const std::string& instead of a new string. (#506)
Store the type string in IExecutionProvider so that Type() doesn't need to be a virtual.
This commit is contained in:
parent
d6a70470dd
commit
5171e8b129
10 changed files with 24 additions and 35 deletions
|
|
@ -91,6 +91,7 @@ file(GLOB onnxruntime_test_ir_src
|
|||
|
||||
set(onnxruntime_test_framework_src_patterns
|
||||
"${TEST_SRC_DIR}/framework/*.cc"
|
||||
"${TEST_SRC_DIR}/framework/*.h"
|
||||
"${TEST_SRC_DIR}/platform/*.cc"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,9 @@ struct NodeComputeInfo {
|
|||
};
|
||||
|
||||
class IExecutionProvider {
|
||||
protected:
|
||||
IExecutionProvider(const std::string& type) : type_{type} {}
|
||||
|
||||
public:
|
||||
virtual ~IExecutionProvider() = default;
|
||||
|
||||
|
|
@ -105,7 +108,7 @@ class IExecutionProvider {
|
|||
through the SetExecutionProvider API. Example valid return values are:
|
||||
kCpuExecutionProvider, kCudaExecutionProvider
|
||||
*/
|
||||
virtual std::string Type() const = 0;
|
||||
const std::string& Type() const { return type_; }
|
||||
|
||||
/**
|
||||
Blocks until the device has completed all preceding requested tasks.
|
||||
|
|
@ -149,6 +152,7 @@ class IExecutionProvider {
|
|||
std::string& dll_path);
|
||||
|
||||
private:
|
||||
const std::string type_;
|
||||
AllocatorMap allocators_;
|
||||
|
||||
// convenience list of the allocators so GetAllocatorList doesn't have to build a new vector each time
|
||||
|
|
|
|||
|
|
@ -15,16 +15,21 @@ struct CPUExecutionProviderInfo {
|
|||
|
||||
explicit CPUExecutionProviderInfo(bool use_arena)
|
||||
: create_arena(use_arena) {}
|
||||
|
||||
CPUExecutionProviderInfo() = default;
|
||||
};
|
||||
|
||||
using FuseRuleFn = std::function<void(const onnxruntime::GraphViewer&, std::vector<std::unique_ptr<ComputeCapability>>&)>;
|
||||
using FuseRuleFn = std::function<void(const onnxruntime::GraphViewer&,
|
||||
std::vector<std::unique_ptr<ComputeCapability>>&)>;
|
||||
|
||||
// Logical device representation.
|
||||
class CPUExecutionProvider : public IExecutionProvider {
|
||||
public:
|
||||
explicit CPUExecutionProvider(const CPUExecutionProviderInfo& info) {
|
||||
DeviceAllocatorRegistrationInfo device_info({OrtMemTypeDefault, [](int) { return std::make_unique<CPUAllocator>(); }, std::numeric_limits<size_t>::max()});
|
||||
explicit CPUExecutionProvider(const CPUExecutionProviderInfo& info)
|
||||
: IExecutionProvider{onnxruntime::kCpuExecutionProvider} {
|
||||
DeviceAllocatorRegistrationInfo device_info{OrtMemTypeDefault,
|
||||
[](int) { return std::make_unique<CPUAllocator>(); },
|
||||
std::numeric_limits<size_t>::max()};
|
||||
#ifdef USE_JEMALLOC
|
||||
ORT_UNUSED_PARAMETER(info);
|
||||
//JEMalloc already has memory pool, so just use device allocator.
|
||||
|
|
@ -41,10 +46,6 @@ class CPUExecutionProvider : public IExecutionProvider {
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string Type() const override {
|
||||
return onnxruntime::kCpuExecutionProvider;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<ComputeCapability>> GetCapability(
|
||||
const onnxruntime::GraphViewer& graph,
|
||||
const std::vector<const KernelRegistry*>& kernel_registries) const override;
|
||||
|
|
@ -63,7 +64,7 @@ class CPUExecutionProvider : public IExecutionProvider {
|
|||
|
||||
void InsertFusedRules(FuseRuleFn rule);
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::vector<FuseRuleFn> fuse_rules_;
|
||||
};
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ CUDAExecutionProvider::PerThreadContext::~PerThreadContext() {
|
|||
}
|
||||
|
||||
CUDAExecutionProvider::CUDAExecutionProvider(const CUDAExecutionProviderInfo& info)
|
||||
: device_id_(info.device_id) {
|
||||
: IExecutionProvider{onnxruntime::kCudaExecutionProvider}, device_id_(info.device_id) {
|
||||
CUDA_CALL_THROW(cudaSetDevice(device_id_));
|
||||
// create streams, default is nullptr
|
||||
streams_[kCudaStreamDefault] = nullptr;
|
||||
|
|
|
|||
|
|
@ -32,10 +32,6 @@ class CUDAExecutionProvider : public IExecutionProvider {
|
|||
|
||||
AllocatorPtr GetAllocator(int id, OrtMemType mem_type = OrtMemTypeDefault) const override;
|
||||
|
||||
std::string Type() const override {
|
||||
return onnxruntime::kCudaExecutionProvider;
|
||||
}
|
||||
|
||||
Status Sync() const override;
|
||||
|
||||
Status OnRunStart() override;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ ONNX_OPERATOR_KERNEL_EX(
|
|||
|
||||
} // namespace mkl_dnn
|
||||
|
||||
MKLDNNExecutionProvider::MKLDNNExecutionProvider(const MKLDNNExecutionProviderInfo& /*info*/) {
|
||||
MKLDNNExecutionProvider::MKLDNNExecutionProvider(const MKLDNNExecutionProviderInfo& /*info*/)
|
||||
: IExecutionProvider{onnxruntime::kMklDnnExecutionProvider} {
|
||||
DeviceAllocatorRegistrationInfo default_allocator_info({OrtMemTypeDefault,
|
||||
[](int) { return std::make_unique<CPUAllocator>(std::make_unique<OrtAllocatorInfo>(MKLDNN, OrtAllocatorType::OrtDeviceAllocator, 0, OrtMemTypeDefault)); }, std::numeric_limits<size_t>::max()});
|
||||
InsertAllocator(CreateAllocator(default_allocator_info));
|
||||
|
|
|
|||
|
|
@ -34,10 +34,6 @@ class MKLDNNExecutionProvider : public IExecutionProvider {
|
|||
explicit MKLDNNExecutionProvider(const MKLDNNExecutionProviderInfo& info);
|
||||
virtual ~MKLDNNExecutionProvider();
|
||||
|
||||
std::string Type() const override {
|
||||
return onnxruntime::kMklDnnExecutionProvider;
|
||||
}
|
||||
|
||||
Status CopyTensor(const Tensor& src, Tensor& dst) const override;
|
||||
|
||||
const void* GetExecutionHandle() const noexcept override {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,10 @@ class DummyExecutionProvider : public IExecutionProvider {
|
|||
static constexpr const char* kDummyExecutionProviderType = "DummyExecutionProvider";
|
||||
|
||||
public:
|
||||
DummyExecutionProvider() {
|
||||
DummyExecutionProvider() : IExecutionProvider{kDummyExecutionProviderType} {
|
||||
InsertAllocator(std::make_unique<DummyAllocator>());
|
||||
}
|
||||
|
||||
std::string Type() const override {
|
||||
return kDummyExecutionProviderType;
|
||||
}
|
||||
|
||||
Status CopyTensor(const Tensor& src, Tensor& dst) const override {
|
||||
// we can 'copy' from anything we allocated to/from CPU
|
||||
ORT_ENFORCE(strcmp(dst.Location().name, DummyAllocator::kDummyAllocator) == 0 ||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ std::shared_ptr<KernelRegistry> GetFusedKernelRegistry() {
|
|||
|
||||
class FuseExecutionProvider : public IExecutionProvider {
|
||||
public:
|
||||
explicit FuseExecutionProvider() {
|
||||
explicit FuseExecutionProvider() : IExecutionProvider{kFuseExecutionProvider} {
|
||||
DeviceAllocatorRegistrationInfo device_info({OrtMemTypeDefault,
|
||||
[](int) { return std::make_unique<CPUAllocator>(); },
|
||||
std::numeric_limits<size_t>::max()});
|
||||
|
|
@ -120,11 +120,8 @@ class FuseExecutionProvider : public IExecutionProvider {
|
|||
const void* GetExecutionHandle() const noexcept override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string Type() const override {
|
||||
return "FuseExecutionProvider";
|
||||
}
|
||||
};
|
||||
|
||||
namespace test {
|
||||
static void VerifyOutputs(const std::vector<MLValue>& fetches,
|
||||
const std::vector<int64_t>& expected_dims,
|
||||
|
|
|
|||
|
|
@ -12,18 +12,15 @@
|
|||
#include "test_utils.h"
|
||||
using namespace std;
|
||||
using namespace ONNX_NAMESPACE;
|
||||
using namespace ::onnxruntime::logging;
|
||||
|
||||
namespace onnxruntime {
|
||||
using namespace logging;
|
||||
|
||||
namespace test {
|
||||
|
||||
class XPUExecutionProvider : public IExecutionProvider {
|
||||
public:
|
||||
XPUExecutionProvider() = default;
|
||||
|
||||
std::string Type() const override {
|
||||
return onnxruntime::kCpuExecutionProvider;
|
||||
}
|
||||
XPUExecutionProvider() : IExecutionProvider{onnxruntime::kCpuExecutionProvider} {}
|
||||
|
||||
Status CopyTensor(const Tensor& src, Tensor& dst) const override {
|
||||
ORT_UNUSED_PARAMETER(src);
|
||||
|
|
|
|||
Loading…
Reference in a new issue