Skip to content

Commit

Permalink
test model with different name
Browse files Browse the repository at this point in the history
  • Loading branch information
DanLiu2Intel committed Nov 15, 2024
1 parent 1132087 commit edfdc39
Showing 1 changed file with 15 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,22 @@ namespace ov {
namespace test {
namespace behavior {

bool containsCacheStatus(const std::string& str, const std::string cmpstr);
void checkCacheDirectory();



//getConstantGraph(ov::element::f32)

inline std::shared_ptr<ov::Model> getConstantGraph(element::Type type) {
ResultVector results;
ParameterVector params;
auto op = std::make_shared<ov::op::v1::Add>(opset8::Constant::create(type, {1}, {1}),
opset8::Constant::create(type, {1}, {1}));
op->set_friendly_name("Add");
auto res = std::make_shared<ov::op::v0::Result>(op);
res->set_friendly_name("Result");
res->get_output_tensor(0).set_names({"tensor_output"});
results.push_back(res);
return std::make_shared<Model>(results, params);
}

inline std::shared_ptr<ov::Model> createModel1() {
inline std::shared_ptr<ov::Model> getConstantGraph() {
auto now = std::chrono::system_clock::now();
auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
std::printf("=========print now timestamp #%s#\n", timestamp);
std::printf("=========print now timestamp #%ld#\n", timestamp);
auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::PartialShape{1, 3, 2, 2});
param->set_friendly_name("input" + std::to_string(timestamp));
param->set_friendly_name("input");
auto const_value = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1, 1, 1, 1}, {1});
const_value->set_friendly_name("const_val" + std::to_string(timestamp));
const_value->set_friendly_name("const_val");
auto add = std::make_shared<ov::op::v1::Add>(param, const_value);
add->set_friendly_name("add" + std::to_string(timestamp));
return std::make_shared<ov::Model>(ov::OutputVector{add->output(0)}, ov::ParameterVector{param});
}

// inline std::shared_ptr<ov::Model> createModel2() {
// auto data1 = std::make_shared<op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 2, 2});
// data1->set_friendly_name("input1");
// data1->get_output_tensor(0).set_names({"tensor_input1"});
// auto op = std::make_shared<op::v0::Relu>(data1);
// op->set_friendly_name("Relu");
// op->get_output_tensor(0).set_names({"tensor_Relu"});
// auto res = std::make_shared<op::v0::Result>(op);
// res->set_friendly_name("Result1");
// res->get_output_tensor(0).set_names({"tensor_output1"});
// return std::make_shared<Model>(ResultVector{res}, ParameterVector{data1});
// }

// inline std::shared_ptr<ov::Model> createModel3() {
// auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::PartialShape{1, 3, 2, 2});
// param->set_friendly_name("input");
// auto const_value = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1, 1, 1, 1}, {1});
// const_value->set_friendly_name("const_val");
// auto add = std::make_shared<ov::op::v1::Add>(param, const_value);
// add->set_friendly_name("add");
// auto subtract = std::make_shared<ov::op::v1::Subtract>(add, const_value);
// subtract->set_friendly_name("sub");
// auto reshape_val = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1});
// reshape_val->set_friendly_name("reshape_val");
// auto reshape = std::make_shared<ov::op::v1::Reshape>(subtract, reshape_val, true);
// reshape->set_friendly_name("reshape");
// auto result = std::make_shared<ov::op::v0::Result>(reshape);
// result->set_friendly_name("res");
// return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});
// }

bool containsCacheStatus(const std::string& str, const std::string cmpstr) {
return str.find(cmpstr) != std::string::npos;
}
Expand Down Expand Up @@ -202,7 +156,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithEmptyConfig) {
std::string driverLogInitContent = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);

ov::CompiledModel execNet;
function = createModel1();
function = getConstantGraph();

//first compilation.
auto startFirst = std::chrono::high_resolution_clock::now();
Expand All @@ -214,6 +168,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithEmptyConfig) {
//To avoid problems with repeatedly calling functiontest
EXPECT_TRUE(containsCacheStatus(firstCompilationDriverLog, "cache_status_t::stored") || containsCacheStatus(firstCompilationDriverLog, "cache_status_t::found"));

checkCacheDirectory();
//second compilation
auto startSecond = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
Expand All @@ -224,6 +179,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithEmptyConfig) {
EXPECT_TRUE(containsCacheStatus(secondCompilationDriverLog, "cache_status_t::stored") || containsCacheStatus(secondCompilationDriverLog, "cache_status_t::found"));

std::printf("==[1.4]testsuit time (1): %f, (2): %f\n", durationFirst.count(), durationSecond.count());
checkCacheDirectory();
}

TEST_P(CompileAndDriverCaching, CompilationCacheWithOVCacheConfig) {
Expand All @@ -236,7 +192,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithOVCacheConfig) {
configuration[ov::cache_dir.name()] = "./testCacheDir";
m_cachedir = configuration[ov::cache_dir.name()].as<std::string>();
ov::CompiledModel execNet;
function = createModel2();
function = getConstantGraph();

//first compilation will long and will generate the model cache.
auto startFirst = std::chrono::high_resolution_clock::now();
Expand All @@ -247,6 +203,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithOVCacheConfig) {
std::string firstCompilationDriverLog = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
EXPECT_TRUE(firstCompilationDriverLog == driverLogInitContent);

checkCacheDirectory();
//second compilation
auto startSecond = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
Expand All @@ -257,6 +214,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithOVCacheConfig) {
EXPECT_TRUE(secondCompilationDriverLog == driverLogInitContent);

std::printf("==[2.4]testsuit time (1): %f, (2): %f\n", durationFirst.count(), durationSecond.count());
checkCacheDirectory();
}

TEST_P(CompileAndDriverCaching, CompilationCacheWithBypassConfig) {
Expand All @@ -267,7 +225,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithBypassConfig) {

configuration[ov::intel_npu::bypass_umd_caching.name()] = true;
ov::CompiledModel execNet;
function = createModel3();
function = getConstantGraph();

//first compilation will long and will generate the model cache.
auto startFirst = std::chrono::high_resolution_clock::now();
Expand All @@ -278,6 +236,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithBypassConfig) {
std::string firstCompilationDriverLog = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
EXPECT_TRUE(firstCompilationDriverLog == driverLogInitContent);

checkCacheDirectory();
//second compilation
auto startSecond = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
Expand All @@ -288,6 +247,7 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithBypassConfig) {
EXPECT_TRUE(secondCompilationDriverLog == driverLogInitContent);

std::printf("==[3.4]testsuit time (1): %f, (2): %f\n", durationFirst.count(), durationSecond.count());
checkCacheDirectory();
}

} // namespace behavior
Expand Down

0 comments on commit edfdc39

Please sign in to comment.