美文网首页
使用OpenVINO获取计算设备的全部属性

使用OpenVINO获取计算设备的全部属性

作者: LabVIEW_Python | 来源:发表于2022-12-28 05:13 被阅读0次

    OpenVINO给计算设备定义了Device properties

    使用下面的范例程序,可以获取目标计算设备的全部属性:

    #include <string>
    #include <vector>
    
    #include "openvino/openvino.hpp"
    
    using namespace std;
    
    void print_any_value(const ov::Any& value) {
        if (value.empty()) {
            cout << "EMPTY VALUE" << endl;
        }
        else {
            std::string stringValue = value.as<std::string>();
            cout << (stringValue.empty() ? "\"\"" : stringValue) << endl;
        }
    }
    
    int main(void) {
    
        cout << ov::get_openvino_version() << endl;
    
        // -------- Step 1. Initialize OpenVINO Runtime Core --------
        ov::Core core;
    
        // -------- Step 2. Get list of available devices --------
        std::vector<std::string> availableDevices = core.get_available_devices();
    
        // -------- Step 3. Query and print supported metrics and config keys --------
        cout << "Available devices: " << endl;
        for (auto&& device : availableDevices) {
            cout << device << endl;
            if (device.find("CPU") != string::npos || device.find("GPU") != string::npos) {
                // ONLY Query supported properties of CPU or GPU
                cout << "\tSUPPORTED_PROPERTIES: " << endl;
                auto supported_properties = core.get_property(device, ov::supported_properties);
                for (auto&& property : supported_properties) {
                    if (property != ov::supported_properties.name()) {
                        cout << "\t\t" << (property.is_mutable() ? "Mutable: " : "Immutable: ") << property << " : "
                            << flush;
                        print_any_value(core.get_property(device, property));
                    }
                }
                cout << endl;
            }        
        }
        return 0;
    }
    
    运行结果如下: Device properties

    相关文章

      网友评论

          本文标题:使用OpenVINO获取计算设备的全部属性

          本文链接:https://www.haomeiwen.com/subject/gcjoqdtx.html