From 2302504bdc6f20db5e143a027eeda8a20192aa8b Mon Sep 17 00:00:00 2001 From: liujiaxin25 Date: Fri, 12 Apr 2024 16:25:32 +0800 Subject: [PATCH] =?UTF-8?q?AI=E5=9F=BA=E7=A1=80=E8=83=BD=E5=8A=9B=EF=BC=9A?= =?UTF-8?q?=E6=96=B0=E5=A2=9Ennrt=20host=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nnrt/bundle.json | 44 +++++ nnrt/v2_0/BUILD.gn | 61 ++++++ nnrt/v2_0/include/innrt_device_vdi.h | 69 +++++++ nnrt/v2_0/include/nnrt_common.h | 122 ++++++++++++ nnrt/v2_0/include/nnrt_device_service.h | 67 +++++++ nnrt/v2_0/src/nnrt_device_driver.cpp | 117 ++++++++++++ nnrt/v2_0/src/nnrt_device_service.cpp | 234 ++++++++++++++++++++++++ 7 files changed, 714 insertions(+) create mode 100644 nnrt/bundle.json create mode 100644 nnrt/v2_0/BUILD.gn create mode 100644 nnrt/v2_0/include/innrt_device_vdi.h create mode 100644 nnrt/v2_0/include/nnrt_common.h create mode 100644 nnrt/v2_0/include/nnrt_device_service.h create mode 100644 nnrt/v2_0/src/nnrt_device_driver.cpp create mode 100644 nnrt/v2_0/src/nnrt_device_service.cpp diff --git a/nnrt/bundle.json b/nnrt/bundle.json new file mode 100644 index 0000000..17e7348 --- /dev/null +++ b/nnrt/bundle.json @@ -0,0 +1,44 @@ +{ + "name": "@ohos/drivers_peripheral_nnrt", + "description": "Neural network runtime device driver", + "version": "4.0", + "license": "Apache License 2.0", + "publishAs": "code-segment", + "segment": { + "destPath": "drivers/peripheral/nnrt" + }, + "dirs": {}, + "scripts": {}, + "component": { + "name": "drivers_peripheral_nnrt", + "subsystem": "hdf", + "syscap": [""], + "adapter_system_type": ["standard"], + "rom": "1024KB", + "ram": "2048KB", + "deps": { + "components": [ + "init", + "hitrace", + "hilog", + "ipc", + "hdf_core", + "c_utils", + "drivers_interface_nnrt", + "mindspore" + ], + "third_part": [ + "bounds_checking_function" + ] + }, + "build": { + "sub_component": [ + "//drivers/peripheral/nnrt/v2_0:hdf_nnrt_service" + ], + "test": [ + ], + "inner_kits": [ + ] + } + } + } \ No newline at end of file diff --git a/nnrt/v2_0/BUILD.gn b/nnrt/v2_0/BUILD.gn new file mode 100644 index 0000000..fd3309b --- /dev/null +++ b/nnrt/v2_0/BUILD.gn @@ -0,0 +1,61 @@ +import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") + +ohos_shared_library("libnnrt_device_service_2.0") { + sources = [ + "src/nnrt_device_service.cpp", + ] + + include_dirs = [ + "include", + "//drivers/peripheral/base", + ] + + external_deps = [ + "c_utils:utils", + "drivers_interface_nnrt:libnnrt_stub_2.0", + "hdf_core:libhdf_utils", + "hilog:libhilog", + "ipc:ipc_core", + "hdf_core:libhdi", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_peripheral_nnrt" +} + +ohos_shared_library("libnnrt_driver") { + include_dirs = [ + "include", + "//drivers/peripheral/base", + ] + sources = [ "src/nnrt_device_driver.cpp" ] + deps = [ ] + + external_deps = [ + "c_utils:utils", + "hdf_core:libhdf_host", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdf_utils", + "hdf_core:libhdi", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_single", + "hitrace:hitrace_meter", + "drivers_interface_nnrt:nnrt_idl_headers", + "drivers_interface_nnrt:libnnrt_stub_2.0", + ] + + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_peripheral_nnrt" +} + +group("hdf_nnrt_service") { + deps = [ + ":libnnrt_driver", + ":libnnrt_device_service_2.0", + ] +} \ No newline at end of file diff --git a/nnrt/v2_0/include/innrt_device_vdi.h b/nnrt/v2_0/include/innrt_device_vdi.h new file mode 100644 index 0000000..67426ef --- /dev/null +++ b/nnrt/v2_0/include/innrt_device_vdi.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_NNRT_V2_0_INNRT_DEVICES_VDI_H +#define OHOS_HDI_NNRT_V2_0_INNRT_DEVICES_VDI_H + +#include "nnrt/v2_0/innrt_device.h" +#include "nnrt/v2_0/iprepared_model.h" +#include "nnrt/v2_0/model_types.h" +#include "nnrt/v2_0/nnrt_types.h" +#include "nnrt/v2_0/nnrt_device_stub.h" + +#include + +namespace OHOS { +namespace HDI { +namespace Nnrt { +namespace V2_0 { +using namespace OHOS::HDI::Nnrt::V2_0; + +#define NNRT_DEVICE_VDI_LIBRARY "libnnrt_vdi_impl.z.so" + +class INnrtDeviceVdi { +public: + virtual ~INnrtDeviceVdi() = default; + + virtual int32_t GetDeviceName(std::string& name) = 0; + virtual int32_t GetVendorName(std::string& name) = 0; + virtual int32_t GetDeviceType(DeviceType& deviceType) = 0; + virtual int32_t GetDeviceStatus(DeviceStatus& status) = 0; + virtual int32_t GetSupportedOperation(const Model& model, std::vector& ops) = 0; + virtual int32_t IsFloat16PrecisionSupported(bool& isSupported) = 0; + virtual int32_t IsPerformanceModeSupported(bool& isSupported) = 0; + virtual int32_t IsPrioritySupported(bool& isSupported) = 0; + virtual int32_t IsDynamicInputSupported(bool& isSupported) = 0; + virtual int32_t PrepareModel(const Model& model, const ModelConfig& config, + sptr& preparedModel) = 0; + virtual int32_t IsModelCacheSupported(bool& isSupported) = 0; + virtual int32_t PrepareModelFromModelCache(const std::vector& modelCache, const ModelConfig& config, + sptr& preparedModel) = 0; + virtual int32_t PrepareOfflineModel(const std::vector& offlineModels, const ModelConfig& config, + sptr& preparedModel) = 0; + virtual int32_t AllocateBuffer(uint32_t length, SharedBuffer& buffer) = 0; + virtual int32_t ReleaseBuffer(const SharedBuffer& buffer) = 0; +}; + +using CreateNnrtDeviceVdiFunc = INnrtDeviceVdi* (*)(); +using DestroyNnrtDeviceVdiFunc = void (*)(INnrtDeviceVdi* vdi); +extern "C" INnrtDeviceVdi* CreateNnrtDeviceVdi(); +extern "C" void DestroyNnrtDeviceVdi(INnrtDeviceVdi* vdi); + +} // V2_0 +} // Nnrt +} // HDI +} // OHOS + +#endif // OHOS_HDI_NNRT_V2_0_INNRT_DEVICES_VDI_H diff --git a/nnrt/v2_0/include/nnrt_common.h b/nnrt/v2_0/include/nnrt_common.h new file mode 100644 index 0000000..0cdbf8f --- /dev/null +++ b/nnrt/v2_0/include/nnrt_common.h @@ -0,0 +1,122 @@ +#ifndef OHOS_HDI_NNRT_V2_0_COMMON_H +#define OHOS_HDI_NNRT_V2_0_COMMON_H + +#include +#include +#include "hilog/log.h" +#include "stdio.h" + +#ifdef HDF_LOG_TAG +#undef HDF_LOG_TAG +#endif + + +#if defined(__cplusplus) +extern "C" { +#endif + +#undef LOG_TAG +#undef LOG_DOMAIN +#define LOG_TAG "NNRT" +#define LOG_DOMAIN 0xD002600 + +#ifndef NNRT_UNUSED +#define NNRT_UNUSED(x) (void)x +#endif + +#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__) + +#ifndef NNRT_DEBUG_ENABLE +#define NNRT_DEBUG_ENABLE 0 +#endif + +#ifndef NNRT_LOGD +#define NNRT_LOGD(format, ...) \ + do { \ + if (NNRT_DEBUG_ENABLE) { \ + HILOG_DEBUG(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } \ + } while (0) +#endif + + +#ifndef NNRT_LOGI +#define NNRT_LOGI(format, ...) \ + do { \ + HILOG_INFO(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + + +#ifndef NNRT_LOGW +#define NNRT_LOGW(format, ...) \ + do { \ + HILOG_WARN(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } while (0) +#endif + + +#ifndef NNRT_LOGE +#define NNRT_LOGE(format, ...) \ + do { \ + HILOG_ERROR(LOG_CORE, \ + "\033[0;32;31m" \ + "[%{public}s@%{public}s:%{public}d] " format "\033[m" \ + "\n", \ + __FUNCTION__, __FILENAME__, __LINE__, ##__VA_ARGS__); \ + } while (0) +#endif + + +#ifndef CHECK_NULLPOINTER_RETURN_VALUE +#define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret) \ + do { \ + if ((pointer) == NULL) { \ + NNRT_LOGE("pointer is null and return ret\n"); \ + return (ret); \ + } \ + } while (0) +#endif + + +#ifndef CHECK_NULLPOINTER_RETURN +#define CHECK_NULLPOINTER_RETURN(pointer) \ + do { \ + if ((pointer) == NULL) { \ + NNRT_LOGE("pointer is null and return\n"); \ + return; \ + } \ + } while (0) +#endif + + +#ifndef NNRT_CHK_RETURN +#define NNRT_CHK_RETURN(val, ret, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return (ret); \ + } \ + } while (0) +#endif + + +#ifndef NNRT_CHK_RETURN_NOT_VALUE +#define NNRT_CHK_RETURN_NOT_VALUE(val, ...) \ + do { \ + if (val) { \ + __VA_ARGS__; \ + return; \ + } \ + } while (0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* OHOS_HDI_NNRT_V2_0_COMMON_H */ \ No newline at end of file diff --git a/nnrt/v2_0/include/nnrt_device_service.h b/nnrt/v2_0/include/nnrt_device_service.h new file mode 100644 index 0000000..298b5b0 --- /dev/null +++ b/nnrt/v2_0/include/nnrt_device_service.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_HDI_NNRT_V2_0_NNRTDEVICESERVICE_H +#define OHOS_HDI_NNRT_V2_0_NNRTDEVICESERVICE_H + +#include "v2_0/innrt_device.h" +#include "innrt_device_vdi.h" +#include "nnrt_common.h" + +namespace OHOS { +namespace HDI { +namespace Nnrt { +namespace V2_0 { +using namespace OHOS::HDI::Nnrt::V2_0; + +class NnrtDeviceService : public INnrtDevice { +public: + NnrtDeviceService(); + virtual ~NnrtDeviceService(); + + int32_t GetDeviceName(std::string& name) override; + int32_t GetVendorName(std::string& name) override; + int32_t GetDeviceType(DeviceType& deviceType) override; + int32_t GetDeviceStatus(DeviceStatus& status) override; + int32_t GetSupportedOperation(const Model& model, std::vector& ops) override; + int32_t IsFloat16PrecisionSupported(bool& isSupported) override; + int32_t IsPerformanceModeSupported(bool& isSupported) override; + int32_t IsPrioritySupported(bool& isSupported) override; + int32_t IsDynamicInputSupported(bool& isSupported) override; + int32_t PrepareModel(const Model& model, const ModelConfig& config, + sptr& preparedModel) override; + int32_t IsModelCacheSupported(bool& isSupported) override; + int32_t PrepareModelFromModelCache(const std::vector& modelCache, const ModelConfig& config, + sptr& preparedModel) override; + int32_t PrepareOfflineModel(const std::vector& offlineModels, const ModelConfig& config, + sptr& preparedModel) override; + int32_t AllocateBuffer(uint32_t length, SharedBuffer& buffer) override; + int32_t ReleaseBuffer(const SharedBuffer& buffer) override; + +private: + int32_t LoadVdi(); + +private: + void* libHandle_; + CreateNnrtDeviceVdiFunc createVdiFunc_; + DestroyNnrtDeviceVdiFunc destroyVdiFunc_; + INnrtDeviceVdi* vdiImpl_; +}; +} // V2_0 +} // Nnrt +} // HDI +} // OHOS + +#endif // OHOS_HDI_NNRT_V2_0_NNRTDEVICESERVICE_H \ No newline at end of file diff --git a/nnrt/v2_0/src/nnrt_device_driver.cpp b/nnrt/v2_0/src/nnrt_device_driver.cpp new file mode 100644 index 0000000..0cfe768 --- /dev/null +++ b/nnrt/v2_0/src/nnrt_device_driver.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "v2_0/nnrt_device_stub.h" + +#define HDF_LOG_TAG nnrt_device_driver + +using namespace OHOS::HDI::Nnrt::V2_0; + +struct HdfNnrtDeviceHost { + struct IDeviceIoService ioService; + OHOS::sptr stub; +}; + +static int32_t NnrtDeviceDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, + struct HdfSBuf *reply) +{ + auto *hdfNnrtDeviceHost = CONTAINER_OF(client->device->service, struct HdfNnrtDeviceHost, ioService); + + OHOS::MessageParcel *dataParcel = nullptr; + OHOS::MessageParcel *replyParcel = nullptr; + OHOS::MessageOption option; + + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: invalid data sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s: invalid reply sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return hdfNnrtDeviceHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); +} + +static int HdfNnrtDeviceDriverInit(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%{public}s: driver init start", __func__); + return HDF_SUCCESS; +} + +static int HdfNnrtDeviceDriverBind(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%{public}s: driver bind start", __func__); + auto *hdfNnrtDeviceHost = new (std::nothrow) HdfNnrtDeviceHost; + if (hdfNnrtDeviceHost == nullptr) { + HDF_LOGE("%{public}s: failed to create create HdfNnrtDeviceHost object", __func__); + return HDF_FAILURE; + } + + hdfNnrtDeviceHost->ioService.Dispatch = NnrtDeviceDriverDispatch; + hdfNnrtDeviceHost->ioService.Open = NULL; + hdfNnrtDeviceHost->ioService.Release = NULL; + + auto serviceImpl = OHOS::HDI::Nnrt::V2_0::INnrtDevice::Get(true); + if (serviceImpl == nullptr) { + HDF_LOGE("%{public}s: failed to get of implement service", __func__); + delete hdfNnrtDeviceHost; + return HDF_FAILURE; + } + + hdfNnrtDeviceHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, + OHOS::HDI::Nnrt::V2_0::INnrtDevice::GetDescriptor()); + if (hdfNnrtDeviceHost->stub == nullptr) { + HDF_LOGE("%{public}s: failed to get stub object", __func__); + delete hdfNnrtDeviceHost; + return HDF_FAILURE; + } + + deviceObject->service = &hdfNnrtDeviceHost->ioService; + return HDF_SUCCESS; +} + +static void HdfNnrtDeviceDriverRelease(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("%{public}s: driver release start", __func__); + if (deviceObject->service == nullptr) { + return; + } + + auto *hdfNnrtDeviceHost = CONTAINER_OF(deviceObject->service, struct HdfNnrtDeviceHost, ioService); + if (hdfNnrtDeviceHost != nullptr) { + delete hdfNnrtDeviceHost; + } +} + +struct HdfDriverEntry g_nnrtdeviceDriverEntry = { + .moduleVersion = 1, + .moduleName = "nnrt", + .Bind = HdfNnrtDeviceDriverBind, + .Init = HdfNnrtDeviceDriverInit, + .Release = HdfNnrtDeviceDriverRelease, +}; + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +HDF_INIT(g_nnrtdeviceDriverEntry); +#ifdef __cplusplus +} +#endif /* __cplusplus */ diff --git a/nnrt/v2_0/src/nnrt_device_service.cpp b/nnrt/v2_0/src/nnrt_device_service.cpp new file mode 100644 index 0000000..99dc843 --- /dev/null +++ b/nnrt/v2_0/src/nnrt_device_service.cpp @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "nnrt_device_service.h" +#include +#include +#include + +#define HDF_LOG_TAG nnrt_device_service + +namespace OHOS { +namespace HDI { +namespace Nnrt { +namespace V2_0 { +extern "C" INnrtDevice *NnrtDeviceImplGetInstance(void) +{ + return new (std::nothrow) NnrtDeviceService(); +} + +NnrtDeviceService::NnrtDeviceService() + : libHandle_(nullptr), + createVdiFunc_(nullptr), + destroyVdiFunc_(nullptr), + vdiImpl_(nullptr) +{ + int32_t ret = LoadVdi(); + if (ret == HDF_SUCCESS) { + vdiImpl_ = createVdiFunc_(); + CHECK_NULLPOINTER_RETURN(vdiImpl_); + } else { + HDF_LOGE("Load nnrt device VDI failed, lib: %{public}s", NNRT_DEVICE_VDI_LIBRARY); + } +} + +NnrtDeviceService::~NnrtDeviceService() +{ + if ((destroyVdiFunc_ != nullptr) && (vdiImpl_ != nullptr)) { + destroyVdiFunc_(vdiImpl_); + } + if (libHandle_ != nullptr) { + dlclose(libHandle_); + } +} + +int32_t NnrtDeviceService::LoadVdi() +{ + const char* errStr = dlerror(); + if (errStr != nullptr) { + HDF_LOGE("nnrt loadvdi, clear earlier dlerror: %{public}s", errStr); + } + libHandle_ = dlopen(NNRT_DEVICE_VDI_LIBRARY, RTLD_LAZY); + if (libHandle_ == nullptr) { + errStr = dlerror(); + HDF_LOGE("opendl failed, error:%{public}s\n", errStr); + } + CHECK_NULLPOINTER_RETURN_VALUE(libHandle_, HDF_FAILURE); + + createVdiFunc_ = reinterpret_cast(dlsym(libHandle_, "CreateNnrtDeviceVdi")); + if (createVdiFunc_ == nullptr) { + errStr = dlerror(); + if (errStr != nullptr) { + HDF_LOGE("nnrt CreateNnrtDeviceVdi dlsym error: %{public}s", errStr); + } + dlclose(libHandle_); + return HDF_FAILURE; + } + + destroyVdiFunc_ = reinterpret_cast(dlsym(libHandle_, "DestroyNnrtDeviceVdi")); + if (destroyVdiFunc_ == nullptr) { + errStr = dlerror(); + if (errStr != nullptr) { + HDF_LOGE("composer DestroyNnrtDeviceVdi dlsym error: %{public}s", errStr); + } + dlclose(libHandle_); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::GetDeviceName(std::string& name) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->GetDeviceName(name); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::GetVendorName(std::string& name) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->GetVendorName(name); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::GetDeviceType(DeviceType& deviceType) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->GetDeviceType(deviceType); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::GetDeviceStatus(DeviceStatus& status) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->GetDeviceStatus(status); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::GetSupportedOperation(const Model& model, std::vector& ops) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->GetSupportedOperation(model, ops); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::IsFloat16PrecisionSupported(bool& isSupported) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->IsFloat16PrecisionSupported(isSupported); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::IsPerformanceModeSupported(bool& isSupported) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->IsPerformanceModeSupported(isSupported); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::IsPrioritySupported(bool& isSupported) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->IsPrioritySupported(isSupported); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::IsDynamicInputSupported(bool& isSupported) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->IsDynamicInputSupported(isSupported); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::PrepareModel(const Model& model, const ModelConfig& config, + sptr& preparedModel) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->PrepareModel(model, config, preparedModel); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::IsModelCacheSupported(bool& isSupported) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->IsModelCacheSupported(isSupported); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::PrepareModelFromModelCache(const std::vector& modelCache, + const ModelConfig& config, sptr& preparedModel) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->PrepareModelFromModelCache(modelCache, config, preparedModel); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::PrepareOfflineModel(const std::vector& offlineModels, + const ModelConfig& config, sptr& preparedModel) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->PrepareOfflineModel(offlineModels, config, preparedModel); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::AllocateBuffer(uint32_t length, SharedBuffer& buffer) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->AllocateBuffer(length, buffer); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +int32_t NnrtDeviceService::ReleaseBuffer(const SharedBuffer& buffer) +{ + CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE); + int32_t ret = vdiImpl_->ReleaseBuffer(buffer); + NNRT_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, HDF_LOGE(" fail")); + + return HDF_SUCCESS; +} + +} // V2_0 +} // Nnrt +} // HDI +} // OHOS -- Gitee