Skip to content

Commit

Permalink
test1-2
Browse files Browse the repository at this point in the history
  • Loading branch information
DanLiu2Intel committed Aug 2, 2024
1 parent d5ebdd4 commit f7031aa
Showing 1 changed file with 368 additions and 5 deletions.
373 changes: 368 additions & 5 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,375 @@ Plugin::Plugin(bool flag)
: _options(std::make_shared<OptionsDesc>()),
_globalConfig(_options),
_logger("NPUPlugin", Logger::global().level()) {
std::printf(" <add here is the test plugin(bool flag)\n");
std::printf(" <add here is the test plugin(bool flag)\n");

if(flag)
std::printf("<first test successfully!!!>\n");
else
std::printf("flag is false! not change to true.\n");
if(flag)
std::printf("<first test successfully!!!>\n");
else
std::printf("flag is false! not change to true.\n");

OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "Plugin::Plugin");
set_device_name("NPU");

registerCommonOptions(*_options);
registerCompilerOptions(*_options);
registerRunTimeOptions(*_options);

// parse env_variables to get LOG_LEVEL if needed
_globalConfig.parseEnvVars();
Logger::global().setLevel(_globalConfig.get<LOG_LEVEL>());

// TODO: generation of available backends list can be done during execution of CMake scripts
std::vector<AvailableBackends> backendRegistry;

#if defined(OPENVINO_STATIC_LIBRARY)
backendRegistry.push_back(AvailableBackends::LEVEL_ZERO);
#else
# if defined(ENABLE_IMD_BACKEND)
if (const auto* envVar = std::getenv("IE_NPU_USE_IMD_BACKEND")) {
if (envVarStrToBool("IE_NPU_USE_IMD_BACKEND", envVar)) {
backendRegistry.push_back(AvailableBackends::IMD);
}
}
# endif

# if defined(_WIN32) || defined(_WIN64) || (defined(__linux__) && defined(__x86_64__))
backendRegistry.push_back(AvailableBackends::LEVEL_ZERO);
# endif
#endif

OV_ITT_TASK_CHAIN(PLUGIN, itt::domains::NPUPlugin, "Plugin::Plugin", "NPUBackends");
_backends = std::make_shared<NPUBackends>(backendRegistry, _globalConfig);
OV_ITT_TASK_NEXT(PLUGIN, "registerOptions");
_backends->registerOptions(*_options);

OV_ITT_TASK_NEXT(PLUGIN, "Metrics");
_metrics = std::make_unique<Metrics>(_backends);

// parse again env_variables after backend is initialized to get backend proprieties
_globalConfig.parseEnvVars();

// initialize properties which have device-tied default values in global config
// *only if there is a driver available
if (_metrics->GetAvailableDevicesNames().size() > 0) {
_globalConfig.update({{ov::intel_npu::stepping.name(),
std::to_string(_metrics->GetSteppingNumber(get_specified_device_name(_globalConfig)))}});
_globalConfig.update({{ov::intel_npu::max_tiles.name(),
std::to_string(_metrics->GetMaxTiles(get_specified_device_name(_globalConfig)))}});
}

// Map from name to function {Config -> ov::Any}
// Note that some properties are RW before network is loaded, and become RO after network is loaded
_properties = {
// OV Public
// =========
{ov::supported_properties.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config&) {
return _supportedProperties;
}}},
{ov::enable_profiling.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<PERF_COUNT>();
}}},
{ov::hint::performance_mode.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<PERFORMANCE_HINT>();
}}},
{ov::hint::execution_mode.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<EXECUTION_MODE_HINT>();
}}},
{ov::hint::num_requests.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<PERFORMANCE_HINT_NUM_REQUESTS>();
}}},
{ov::hint::inference_precision.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<INFERENCE_PRECISION_HINT>();
}}},
{ov::hint::enable_cpu_pinning.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<ENABLE_CPU_PINNING>();
}}},
{ov::log::level.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<LOG_LEVEL>();
}}},
{ov::cache_dir.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<CACHE_DIR>();
}}},
{ov::device::id.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<DEVICE_ID>();
}}},
{ov::compilation_num_threads.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<COMPILATION_NUM_THREADS>();
}}},
{ov::available_devices.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetAvailableDevicesNames();
}}},
{ov::device::capabilities.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetOptimizationCapabilities();
}}},
{ov::optimal_number_of_infer_requests.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return static_cast<uint32_t>(getOptimalNumberOfInferRequestsInParallel(add_platform_to_the_config(
config,
_backends->getCompilationPlatform(config.get<PLATFORM>(), config.get<DEVICE_ID>()))));
}}},
{ov::range_for_async_infer_requests.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetRangeForAsyncInferRequest();
}}},
{ov::range_for_streams.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetRangeForStreams();
}}},
{ov::num_streams.name(),
{true,
ov::PropertyMutability::RO,
[](const Config& config) {
return config.get<NUM_STREAMS>();
}}},
{ov::device::uuid.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
const auto specifiedDeviceName = get_specified_device_name(config);
auto devUuid = _metrics->GetDeviceUuid(specifiedDeviceName);
return decltype(ov::device::uuid)::value_type{devUuid};
}}},
// Add FULL_DEVICE_NAME and DEVICE_ARCHITECTURE in supported
// properties list only in case of non-empty device list (#1424144d)
{ov::device::architecture.name(),
{!_metrics->GetAvailableDevicesNames().empty(),
ov::PropertyMutability::RO,
[&](const Config& config) {
const auto specifiedDeviceName = get_specified_device_name(config);
return _metrics->GetDeviceArchitecture(specifiedDeviceName);
}}},
{ov::device::full_name.name(),
{!_metrics->GetAvailableDevicesNames().empty(),
ov::PropertyMutability::RO,
[&](const Config& config) {
const auto specifiedDeviceName = get_specified_device_name(config);
return _metrics->GetFullDeviceName(specifiedDeviceName);
}}},
{ov::hint::model_priority.name(),
{true,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<MODEL_PRIORITY>();
}}},
{ov::device::pci_info.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetPciInfo(get_specified_device_name(config));
}}},
{ov::device::gops.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetGops(get_specified_device_name(config));
}}},
{ov::device::type.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetDeviceType(get_specified_device_name(config));
}}},
{ov::execution_devices.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
if (_metrics->GetAvailableDevicesNames().size() > 1) {
return std::string("NPU." + config.get<DEVICE_ID>());
} else {
return std::string("NPU");
}
}}},
// OV Internals
// =========
{ov::internal::caching_properties.name(),
{false,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetCachingProperties();
}}},
{ov::internal::exclusive_async_requests.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<EXCLUSIVE_ASYNC_REQUESTS>();
}}},
{ov::internal::supported_properties.name(),
{false,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetInternalSupportedProperties();
}}},
// NPU Public
// =========
{ov::intel_npu::device_alloc_mem_size.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetDeviceAllocMemSize(get_specified_device_name(config));
}}},
{ov::intel_npu::device_total_mem_size.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetDeviceTotalMemSize(get_specified_device_name(config));
}}},
{ov::intel_npu::driver_version.name(),
{true,
ov::PropertyMutability::RO,
[&](const Config& config) {
return _metrics->GetDriverVersion();
}}},
// NPU Private
// =========
{ov::intel_npu::dma_engines.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<DMA_ENGINES>();
}}},
{ov::intel_npu::tiles.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<TILES>();
}}},
{ov::intel_npu::dpu_groups.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<DPU_GROUPS>();
}}},
{ov::intel_npu::stepping.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<STEPPING>();
}}},
{ov::intel_npu::max_tiles.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<MAX_TILES>();
}}},
{ov::intel_npu::compilation_mode.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<COMPILATION_MODE>();
}}},
{ov::intel_npu::compilation_mode_params.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<COMPILATION_MODE_PARAMS>();
}}},
{ov::intel_npu::compiler_type.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<COMPILER_TYPE>();
}}},
{ov::intel_npu::platform.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<PLATFORM>();
}}},
{ov::intel_npu::backend_name.name(),
{false,
ov::PropertyMutability::RO,
[&](const Config&) {
return _metrics->GetBackendName();
}}},
{ov::intel_npu::use_elf_compiler_backend.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<USE_ELF_COMPILER_BACKEND>();
}}},
{ov::intel_npu::create_executor.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<CREATE_EXECUTOR>();
}}},
{ov::intel_npu::dynamic_shape_to_static.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<DYNAMIC_SHAPE_TO_STATIC>();
}}},
{ov::intel_npu::profiling_type.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.get<PROFILING_TYPE>();
}}},
{ov::intel_npu::backend_compilation_params.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<BACKEND_COMPILATION_PARAMS>();
}}},
{ov::intel_npu::batch_mode.name(),
{false,
ov::PropertyMutability::RW,
[](const Config& config) {
return config.getString<BATCH_MODE>();
}}}
};

for (auto& property : _properties) {
if (std::get<0>(property.second)) {
_supportedProperties.emplace_back(ov::PropertyName(property.first, std::get<1>(property.second)));
}
}
}

Plugin::Plugin()
Expand Down

0 comments on commit f7031aa

Please sign in to comment.