Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,25 @@ void fuse_mean_scale(ov::preprocess::PrePostProcessor& preproc, const benchmark_
}
} // namespace

/**
* Sentry class to ensure the resource releasing from CompiledModel.
* Release static global oneDNN cache used for inference with release_memory
* method. To be called once at the end of inference.
*/
class ModelSentry {
public:
ModelSentry(ov::CompiledModel& compiledModel) : _model(compiledModel) {}

~ModelSentry() {
if (_model) {
_model.release_memory();
}
}

private:
ov::CompiledModel _model;
};

/**
* @brief The entry point of the benchmark application
*/
Expand All @@ -337,6 +356,8 @@ int main(int argc, char* argv[]) {
try {
ov::CompiledModel compiledModel;

ModelSentry releaser(compiledModel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually capture the model? Since _model is a copy now, there's a risk that ModelSentry does nothing. main() should use _model instead of compiledModel to fix that


// ----------------- 1. Parsing and validating input arguments
// -------------------------------------------------
next_step();
Expand Down
Loading