Skip to content

Commit

Permalink
Add UT to verify the status with code INVALID_GRAPH
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorSVC committed Nov 18, 2023
1 parent 4a761ec commit 4e7743d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ Status GetEpContextFromGraph(const onnxruntime::GraphViewer& graph_viewer,
std::filesystem::path folder_path = std::filesystem::path(ctx_onnx_model_path).parent_path();
std::filesystem::path context_binary_path = folder_path.append(external_qnn_context_binary_file_name);

//std::string context_binary_path(std::filesystem::path(ctx_onnx_model_path).parent_path().string() +
// "/" + external_qnn_context_binary_file_name);
size_t buffer_size{0};
std::ifstream cache_file(context_binary_path.string().c_str(), std::ifstream::binary);
ORT_RETURN_IF(!cache_file || !cache_file.good(), "Failed to open cache file.");
Expand Down
56 changes: 56 additions & 0 deletions onnxruntime/test/providers/qnn/simple_op_htp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,62 @@ TEST_F(QnnHTPBackendTests, ContextBinaryCacheNonEmbedModeTest) {
context_binary_file);
}

// Run QDQ model on HTP 2 times
// 1st run will generate the Onnx skeleton file + Qnn context cache binary file
// Then delete the context bin file to make the 2nd sesssion.Initialize() return the status with code INVALID_GRAPH
TEST_F(QnnHTPBackendTests, ContextBinaryCache_InvalidGraph) {
ProviderOptions provider_options;
#if defined(_WIN32)
provider_options["backend_path"] = "QnnHtp.dll";
#else
provider_options["backend_path"] = "libQnnHtp.so";
#endif
provider_options["qnn_context_cache_enable"] = "1";
const std::string context_binary_file = "./qnn_context_cache_non_embed.onnx";
provider_options["qnn_context_cache_path"] = context_binary_file;
provider_options["qnn_context_embed_mode"] = "0";

const TestInputDef<float> input_def({1, 2, 3}, false, -10.0f, 10.0f);
const std::string op_type = "Atan";

// Runs model with DQ-> Atan-> Q and compares the outputs of the CPU and QNN EPs.
// 1st run will generate the Onnx skeleton file + Qnn context cache binary file
TestQDQModelAccuracy(BuildOpTestCase<float>(op_type, {input_def}, {}, {}),
BuildQDQOpTestCase<uint8_t>(op_type, {input_def}, {}, {}),
provider_options,
14,
ExpectedEPNodeAssignment::All);

// Check the Onnx skeleton file is generated
EXPECT_TRUE(std::filesystem::exists(context_binary_file.c_str()));
// Check the Qnn context cache binary file is generated
std::filesystem::path context_bin = "qnn_context_cache_non_embed.onnx_QNNExecutionProvider_QNN_8283143575221199085_1_0.bin";

Check warning on line 838 in onnxruntime/test/providers/qnn/simple_op_htp_test.cc

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] onnxruntime/test/providers/qnn/simple_op_htp_test.cc#L838

Lines should be <= 120 characters long [whitespace/line_length] [2]
Raw output
onnxruntime/test/providers/qnn/simple_op_htp_test.cc:838:  Lines should be <= 120 characters long  [whitespace/line_length] [2]
EXPECT_TRUE(std::filesystem::exists(context_bin));
// Delete the Qnn context cache binary file
EXPECT_TRUE(std::filesystem::remove(context_bin));

// loads and run from Onnx skeleton file + Qnn context cache binary file
onnx::ModelProto model_proto;
onnxruntime::Model qnn_ctx_model;
// Load the QNN context cache model from path specified
ASSERT_STATUS_OK(qnn_ctx_model.Load(ToPathString(context_binary_file), model_proto));
std::string qnn_ctx_model_data;
model_proto.SerializeToString(&qnn_ctx_model_data);

SessionOptions so;
so.session_logid = "qnn_ctx_model_logger";
RunOptions run_options;
run_options.run_tag = so.session_logid;

InferenceSessionWrapper session_object{so, GetEnvironment()};

std::string provider_type = kCpuExecutionProvider;
ASSERT_STATUS_OK(session_object.RegisterExecutionProvider(QnnExecutionProviderWithOptions(provider_options)));
ASSERT_STATUS_OK(session_object.Load(qnn_ctx_model_data.data(), static_cast<int>(qnn_ctx_model_data.size())));
// Verify the return status with code INVALID_GRAPH
ASSERT_TRUE(session_object.Initialize().Code() == common::StatusCode::INVALID_GRAPH);
}

// Run QDQ model on HTP with 2 inputs
// 1st run will generate the Qnn context cache onnx file
// 2nd run will load and run from QDQ model + Qnn context cache model
Expand Down

0 comments on commit 4e7743d

Please sign in to comment.