From 18e6b496306de7949dfea2177e22a72db5d851b2 Mon Sep 17 00:00:00 2001 From: zhengyuanhua Date: Tue, 30 Nov 2021 10:20:13 +0800 Subject: [PATCH] modify external api impl for ABI --- include/api/context.h | 18 ++++++++++++++---- mindspore/lite/src/cxx_api/context.cc | 22 ++++++++++++---------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/include/api/context.h b/include/api/context.h index 4dc67879886..a0e4c1b2f69 100644 --- a/include/api/context.h +++ b/include/api/context.h @@ -138,21 +138,21 @@ class MS_API DeviceInfoContext : public std::enable_shared_from_this GetAllocator() const; protected: + std::vector GetProviderChar() const; + void SetProvider(const std::vector &provider); + std::vector GetProviderDeviceChar() const; + void SetProviderDevice(const std::vector &device); + std::shared_ptr data_; }; +std::string DeviceInfoContext::GetProvider() const { return CharToString(GetProviderChar()); } +void DeviceInfoContext::SetProvider(const std::string &provider) { SetProvider(StringToChar(provider)); } +std::string DeviceInfoContext::GetProviderDevice() const { return CharToString(GetProviderDeviceChar()); } +void DeviceInfoContext::SetProviderDevice(const std::string &device) { SetProviderDevice(StringToChar(device)); } + /// \brief Derived from DeviceInfoContext, The configuration of the model running on the CPU. This option is only valid /// for MindSpore Lite. class MS_API CPUDeviceInfo : public DeviceInfoContext { diff --git a/mindspore/lite/src/cxx_api/context.cc b/mindspore/lite/src/cxx_api/context.cc index 95f1d9a6799..7e1ba01086e 100644 --- a/mindspore/lite/src/cxx_api/context.cc +++ b/mindspore/lite/src/cxx_api/context.cc @@ -164,36 +164,38 @@ std::vector> &Context::MutableDeviceInfo() { DeviceInfoContext::DeviceInfoContext() : data_(std::make_shared()) {} -std::string DeviceInfoContext::GetProvider() const { +std::vector DeviceInfoContext::GetProviderChar() const { if (data_ == nullptr) { MS_LOG(ERROR) << "Invalid context."; - return ""; + return std::vector(); } - return GetValue(data_, kModelOptionProvider); + const std::string &ref = GetValue(data_, kModelOptionProvider); + return StringToChar(ref); } -void DeviceInfoContext::SetProvider(const std::string &provider) { +void DeviceInfoContext::SetProvider(const std::vector &provider) { if (data_ == nullptr) { MS_LOG(ERROR) << "Invalid context."; return; } - data_->params[kModelOptionProvider] = provider; + data_->params[kModelOptionProvider] = CharToString(provider); } -std::string DeviceInfoContext::GetProviderDevice() const { +std::vector DeviceInfoContext::GetProviderDeviceChar() const { if (data_ == nullptr) { MS_LOG(ERROR) << "Invalid context."; - return ""; + return std::vector(); } - return GetValue(data_, kModelOptionProviderDevice); + const std::string &ref = GetValue(data_, kModelOptionProviderDevice); + return StringToChar(ref); } -void DeviceInfoContext::SetProviderDevice(const std::string &device) { +void DeviceInfoContext::SetProviderDevice(const std::vector &device) { if (data_ == nullptr) { MS_LOG(ERROR) << "Invalid context."; return; } - data_->params[kModelOptionProviderDevice] = device; + data_->params[kModelOptionProviderDevice] = CharToString(device); } void DeviceInfoContext::SetAllocator(const std::shared_ptr &allocator) {