Skip to content

Commit

Permalink
test12
Browse files Browse the repository at this point in the history
  • Loading branch information
DanLiu2Intel committed Nov 12, 2024
1 parent cdbe7da commit 16e2c39
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,248 @@ TEST_P(CompileAndDriverCaching, CompilationCacheWithBypassConfig2NewOVCore) {
EXPECT_TRUE( (!containsCacheStatus(driverLogContent4, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent4, "cache_status_t::found")));
}




//test class2
class CompileAndDriverCachingOVcacheDIR : public testing::WithParamInterface<CompileAndModelCachingParams>,
public OVPluginTestBase {
public:
static std::string getTestCaseName(testing::TestParamInfo<CompileAndModelCachingParams> obj) {
std::shared_ptr<ov::Model> model;
std::string targetDevice;
ov::AnyMap configuration;
std::tie(model, targetDevice, configuration) = obj.param;
std::replace(targetDevice.begin(), targetDevice.end(), ':', '.');
std::ostringstream result;
result << "targetDevice=" << targetDevice << "_";
if (!configuration.empty()) {
// using namespace ov::test::utils;
for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_";
configItem.second.print(result);
}
}
return result.str();
}

void SetUp() override {
std::printf("----setup2\n");
std::tie(function, target_device, configuration) = this->GetParam();
SKIP_IF_CURRENT_TEST_IS_DISABLED()

initStruct = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
if (!initStruct) {
GTEST_SKIP() << "ZeroInitStructsHolder init failed, ZeroInitStructsHolder is a nullptr";
}
APIBaseTest::SetUp();

//remove system cache. contain and remove ? to prevent contine build and make failed.
checkSystemCacheDirectory();
}

void TearDown() override {
std::printf("----teardown2\n");
if (!m_cachedir.empty()) {
std::printf(" printf m_cachedir2:#%s# \n", m_cachedir.c_str());
core->set_property({ov::cache_dir()});
core.reset();
ov::test::utils::removeFilesWithExt(m_cachedir, "blob");
ov::test::utils::removeDir(m_cachedir);
}
if(core) {
std::printf(" core is not empty2\n");
} else {
std::printf(" core is empty2\n");
}
ov::test::utils::PluginCache::get().reset();
if(core) {
std::printf(" core is not empty2\n");
} else {
std::printf(" core is empty2\n");
}

checkSystemCacheDirectory();
APIBaseTest::TearDown();
}

protected:
std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
ov::AnyMap configuration;
std::shared_ptr<ov::Model> function;
std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct;
std::string m_cachedir;
};

TEST_P(CompileAndDriverCachingOVcacheDIR, CompilationCacheWithBypassConfig) {
checkCacheDirectory();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext = initStruct->getGraphDdiTable();

std::string driverLogContent = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("==[]2[]]printf testsuit content1 : #%s#\n", driverLogContent.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent, "cache_status_t::found")));

configuration[ov::intel_npu::bypass_umd_caching.name()] = true;
ov::CompiledModel execNet;
//first run time will long and will generate the model cache.
auto startFirst = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
auto endFirst = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> durationFirst = endFirst - startFirst;

std::string driverLogContent2 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("[]2[]]first compile testsuit content2 : #%s#\n", driverLogContent2.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent2, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent2, "cache_status_t::found")));

//second time compilation
auto startSecond = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));
auto endSecond = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> durationSecond = endSecond - startSecond;

std::string driverLogContent3 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("[]2[]]second compile testsuit content3 : #%s#\n", driverLogContent3.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent3, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent3, "cache_status_t::found")));

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

std::shared_ptr<ov::Core> core2 = utils::PluginCache::get().core();
ov::CompiledModel execNet2;
auto startThird = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet2 = core2->compile_model(function, target_device, configuration));
auto endThird = std::chrono::high_resolution_clock::now();

std::string driverLogContent4 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("[]2[]]second compile testsuit content4 : ##%s##, time:%f\n", driverLogContent4.c_str(), (endThird - startThird).count());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent4, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent4, "cache_status_t::found")));
}

//test class3
class CompileAndDriverCachingBypass : public testing::WithParamInterface<CompileAndModelCachingParams>,
public OVPluginTestBase {
public:
static std::string getTestCaseName(testing::TestParamInfo<CompileAndModelCachingParams> obj) {
std::shared_ptr<ov::Model> model;
std::string targetDevice;
ov::AnyMap configuration;
std::tie(model, targetDevice, configuration) = obj.param;
std::replace(targetDevice.begin(), targetDevice.end(), ':', '.');
std::ostringstream result;
result << "targetDevice=" << targetDevice << "_";
if (!configuration.empty()) {
// using namespace ov::test::utils;
for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_";
configItem.second.print(result);
}
}
return result.str();
}

void SetUp() override {
std::printf("----setup3\n");
std::tie(function, target_device, configuration) = this->GetParam();
SKIP_IF_CURRENT_TEST_IS_DISABLED()

initStruct = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
if (!initStruct) {
GTEST_SKIP() << "ZeroInitStructsHolder init failed, ZeroInitStructsHolder is a nullptr";
}
APIBaseTest::SetUp();

//remove system cache. contain and remove ? to prevent contine build and make failed.
checkSystemCacheDirectory();
}

void TearDown() override {
std::printf("----teardown3\n");
if (!m_cachedir.empty()) {
std::printf(" printf m_cachedir3:#%s# \n", m_cachedir.c_str());
core->set_property({ov::cache_dir()});
core.reset();
ov::test::utils::removeFilesWithExt(m_cachedir, "blob");
ov::test::utils::removeDir(m_cachedir);
}
if(core) {
std::printf(" core is not empty3\n");
} else {
std::printf(" core is empty3\n");
}
ov::test::utils::PluginCache::get().reset();
if(core) {
std::printf(" core is not empty3\n");
} else {
std::printf(" core is empty3\n");
}

checkSystemCacheDirectory();
APIBaseTest::TearDown();
}

protected:
std::shared_ptr<ov::Core> core = utils::PluginCache::get().core();
ov::AnyMap configuration;
std::shared_ptr<ov::Model> function;
std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct;
std::string m_cachedir;
};



TEST_P(CompileAndDriverCachingBypass, CompilationCacheWithBypassConfig2NewOVCore) {
checkCacheDirectory();
std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct2 = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext = initStruct2->getGraphDdiTable();

std::string driverLogContent = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("==[[3]]]printf testsuit content1 : #%s#\n", driverLogContent.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent, "cache_status_t::found")));

configuration[ov::intel_npu::bypass_umd_caching.name()] = true;
ov::CompiledModel execNet;
ov::Core core;
//first run time will long and will generate the model cache.
auto startFirst = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet = core.compile_model(function, target_device, configuration));
auto endFirst = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> durationFirst = endFirst - startFirst;


std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct3 = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext3 = initStruct3->getGraphDdiTable();
std::string driverLogContent2 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext3);
std::printf("[[3]]]first compile testsuit content2 : #%s#\n", driverLogContent2.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent2, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent2, "cache_status_t::found")));

//second time compilation
ov::Core core2;
ov::CompiledModel execNet2;
auto startSecond = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet2 = core2.compile_model(function, target_device, configuration));
auto endSecond = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> durationSecond = endSecond - startSecond;

std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct4 = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext4 = initStruct4->getGraphDdiTable();
std::string driverLogContent3 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext4);
std::printf("[[3]]]second compile testsuit content3 : #%s#\n", driverLogContent3.c_str());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent3, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent3, "cache_status_t::found")));

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

std::shared_ptr<ov::Core> core3 = utils::PluginCache::get().core();
ov::CompiledModel execNet3;
auto startThird = std::chrono::high_resolution_clock::now();
OV_ASSERT_NO_THROW(execNet3 = core3->compile_model(function, target_device, configuration));
auto endThird = std::chrono::high_resolution_clock::now();

std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStruct5 = std::make_shared<::intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext5 = initStruct5->getGraphDdiTable();
std::string driverLogContent4 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext5);
std::printf("[[3]]]second compile testsuit content4 : ##%s##, time:%f\n", driverLogContent4.c_str(), (endThird - startThird).count());
EXPECT_TRUE( (!containsCacheStatus(driverLogContent4, "cache_status_t::found")) && (!containsCacheStatus(driverLogContent4, "cache_status_t::found")));
}

} // namespace behavior
} // namespace test
} // namespace ov
1 change: 1 addition & 0 deletions src/plugins/intel_npu/tools/compile_tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ov_add_target(ADD_CPPLINT
ROOT ${CMAKE_CURRENT_SOURCE_DIR}
LINK_LIBRARIES
PRIVATE
${OPTIONAL_FUNC_TESTS_LIBS}
openvino::runtime
gflags
Threads::Threads
Expand Down
28 changes: 28 additions & 0 deletions src/plugins/intel_npu/tools/compile_tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#include "tools_helpers.hpp"

#include "intel_npu/utils/zero/zero_init.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"


static constexpr char help_message[] = "Optional. Print the usage message.";

Expand Down Expand Up @@ -462,10 +465,35 @@ int main(int argc, char* argv[]) {
std::cout << "Parsing configuration file" << std::endl;
auto configs = parseConfigFile();

std::printf("----------------------1------------------------\n");
std::shared_ptr<intel_npu::ZeroInitStructsHolder> initStruct = std::make_shared<intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext = initStruct->getGraphDdiTable();
std::string driverLogContent1 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("[!!!] compile_tool before first compile testsuit content : #%s#\n", driverLogContent1.c_str());

std::cout << "Compiling model" << std::endl;
auto compiledModel = core.compile_model(model, FLAGS_d, {configs.begin(), configs.end()});
loadNetworkTimeElapsed =
std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);

std::string driverLogContent2 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext);
std::printf("[!!!] compile_tool after first compile testsuit content : #%s#\n", driverLogContent2.c_str());
std::printf("-----------------------2-----------------------\n");

std::shared_ptr<intel_npu::ZeroInitStructsHolder> initStruct4 = std::make_shared<intel_npu::ZeroInitStructsHolder>();
ze_graph_dditable_ext_decorator& graph_ddi_table_ext4 = initStruct4->getGraphDdiTable();
std::string driverLogContent11 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext4);
std::printf("[!!!] compile_tool before first compile testsuit content : #%s#\n", driverLogContent11.c_str());

std::cout << "Compiling model" << std::endl;
auto compiledModel2 = core.compile_model(model, FLAGS_d, {configs.begin(), configs.end()});

std::string driverLogContent22 = ::intel_npu::zeroUtils::getLatestBuildError(graph_ddi_table_ext4);
std::printf("[!!!] compile_tool after first compile testsuit content : #%s#\n", driverLogContent22.c_str());
std::printf("-----------------------3-----------------------\n");



std::string outputName = FLAGS_o;
if (outputName.empty()) {
outputName = getFileNameFromPath(fileNameNoExt(FLAGS_m)) + ".blob";
Expand Down

0 comments on commit 16e2c39

Please sign in to comment.