Skip to content

Commit 213b344

Browse files
adding time measurements for the model serializer
1 parent fd9894c commit 213b344

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/plugins/intel_npu/src/compiler_adapter/src/model_serializer.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "model_serializer.hpp"
66

7+
#include <chrono>
78
#include <cstdint>
89
#include <istream>
910
#include <regex>
@@ -578,26 +579,41 @@ SerializedIR serializeIR(
578579
const std::function<bool(const std::string&, const std::optional<std::string>&)>& isOptionValueSupportedByCompiler,
579580
const bool computeModelHash,
580581
const bool storeWeightlessCacheAttributeFlag) {
582+
const Logger& logger = Logger("serializeIR", Logger::global().level());
583+
std::chrono::steady_clock::time_point start_time;
584+
if (logger.level() >= ov::log::Level::INFO) {
585+
start_time = std::chrono::steady_clock::now();
586+
}
587+
581588
// The current instance is already a clone (or should be one), we are not modifying the original model
582589
const std::shared_ptr<ov::Model> nonConstantModel = std::const_pointer_cast<ov::Model>(model);
583-
const Logger& logger = Logger("serializeIR", Logger::global().level());
584590
const ov::intel_npu::ModelSerializerVersion version =
585591
determineModelSerializerVersion(serializerVersion, isOptionValueSupportedByCompiler, nonConstantModel, logger);
586592

587593
logger.info("Model serializer version chosen by the NPU plugin: %s",
588594
MODEL_SERIALIZER_VERSION::toString(version).c_str());
589595

596+
SerializedIR serializedIR;
590597
switch (version) {
591598
case ov::intel_npu::ModelSerializerVersion::NO_WEIGHTS_COPY:
592-
return VCLSerializerWithoutWeightsCopy(compilerVersion, supportedOpsetVersion)
593-
.serialize(nonConstantModel, computeModelHash, storeWeightlessCacheAttributeFlag);
599+
serializedIR = VCLSerializerWithoutWeightsCopy(compilerVersion, supportedOpsetVersion)
600+
.serialize(nonConstantModel, computeModelHash, storeWeightlessCacheAttributeFlag);
601+
break;
594602
case ov::intel_npu::ModelSerializerVersion::ALL_WEIGHTS_COPY:
595-
return VCLSerializerWithWeightsCopy(compilerVersion, supportedOpsetVersion)
596-
.serialize(nonConstantModel, computeModelHash, storeWeightlessCacheAttributeFlag);
603+
serializedIR = VCLSerializerWithWeightsCopy(compilerVersion, supportedOpsetVersion)
604+
.serialize(nonConstantModel, computeModelHash, storeWeightlessCacheAttributeFlag);
605+
break;
597606
default:
598607
OPENVINO_THROW("Invalid version of model serializer determined by the utility function. Obtained the version: ",
599608
MODEL_SERIALIZER_VERSION::toString(version));
600609
}
610+
611+
logger.info(
612+
"Model serialization duration: %.2f ms",
613+
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start_time).count() /
614+
1000.0);
615+
616+
return serializedIR;
601617
}
602618

603619
std::string serializeIOInfo(const std::shared_ptr<const ov::Model>& model, const bool useIndices) {

0 commit comments

Comments
 (0)