• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "device_discover.h"
17 #include "hdi_device_v1_0.h"
18 #include "common/log.h"
19 #include "common/utils.h"
20 
21 namespace OHOS {
22 namespace NeuralNetworkRuntime {
DiscoverHDIDevicesV1_0(std::string & deviceName,std::string & vendorName,std::string & version)23 std::shared_ptr<Device> DiscoverHDIDevicesV1_0(std::string& deviceName, std::string& vendorName, std::string& version)
24 {
25     // only one device from HDI now.
26     OHOS::sptr<V1_0::INnrtDevice> iDevice = V1_0::INnrtDevice::Get();
27     if (iDevice == nullptr) {
28         LOGW("Get HDI device failed.");
29         return nullptr;
30     }
31 
32     auto hdiRet = iDevice->GetDeviceName(deviceName);
33     if (hdiRet != HDF_SUCCESS) {
34         LOGW("Get device name failed. ErrorCode=%d", hdiRet);
35         return nullptr;
36     }
37     hdiRet = iDevice->GetVendorName(vendorName);
38     if (hdiRet != HDF_SUCCESS) {
39         LOGW("Get vendor name failed. ErrorCode=%d", hdiRet);
40         return nullptr;
41     }
42     std::pair<uint32_t, uint32_t> hdiVersion;
43     hdiRet = iDevice->GetVersion(hdiVersion.first, hdiVersion.second);
44     if (hdiRet != HDF_SUCCESS) {
45         LOGW("Get version failed. ErrorCode=%d", hdiRet);
46         return nullptr;
47     }
48     version = 'v' + std::to_string(hdiVersion.first) + '_' + std::to_string(hdiVersion.second);
49 
50     std::shared_ptr<Device> device = CreateSharedPtr<HDIDeviceV1_0>(iDevice);
51     if (device == nullptr) {
52         LOGW("Failed to register device, because fail to create device instance.");
53     }
54     return device;
55 }
56 } // namespace NeuralNetworkRuntime
57 } // namespace OHOS