Skip to content

Commit

Permalink
clean up some not used code
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorSVC committed Jan 22, 2024
1 parent 8c55f19 commit e7c0827
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
85 changes: 0 additions & 85 deletions onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,6 @@ Status LoadQnnCtxFromOnnxGraph(const onnxruntime::GraphViewer& graph_viewer,
return Status::OK();
}

Status GetMetadataFromEpContextModel(const onnxruntime::PathString& ctx_onnx_model_path,
std::string& model_name,
std::string& model_description,
std::vector<std::string>& graph_partition_names,
std::string& cache_source,
const logging::Logger& logger) {
using namespace onnxruntime;
std::shared_ptr<Model> model;
ORT_RETURN_IF_ERROR(Model::Load(ctx_onnx_model_path, model, {}, logger));
const auto& graph = GraphViewer(model->MainGraph());
model_name = graph.Name();
model_description = graph.Description();

for (const auto& ep_context_node : graph.Nodes()) {
if (EPCONTEXT_OP != ep_context_node.OpType()) {
continue;
}
NodeAttrHelper node_helper(ep_context_node);
cache_source = node_helper.Get(SOURCE, "");
graph_partition_names.push_back(node_helper.Get(PARTITION_NAME, ""));
}

return Status::OK();
}

bool IsContextCacheFileExists(const std::string& customer_context_cache_path,
const onnxruntime::PathString& model_pathstring,
onnxruntime::PathString& context_cache_path) {
Expand All @@ -194,66 +169,6 @@ bool IsContextCacheFileExists(const std::string& customer_context_cache_path,
return std::filesystem::is_regular_file(context_cache_path) && std::filesystem::exists(context_cache_path);
}

Status ValidateWithContextFile(const std::vector<IExecutionProvider::FusedNodeAndGraph>& fused_nodes_and_graphs,
const onnxruntime::PathString& context_cache_path,
const std::string& model_name,
const std::string& model_description,
const logging::Logger& logger) {
std::string model_name_from_ctx_cache;
std::string model_description_from_ctx_cache;
std::vector<std::string> graph_partition_names;
std::string cache_source;

auto status = GetMetadataFromEpContextModel(context_cache_path,
model_name_from_ctx_cache,
model_description_from_ctx_cache,
graph_partition_names,
cache_source,
logger);
if (!status.IsOK()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_GRAPH, "Failed to get metadata from EpContext model.");
}

// The source attribute from the skeleton onnx file indicate whether it's generated from QNN toolchain or ORT
if (cache_source != kQnnExecutionProvider) {
LOGS(logger, VERBOSE) << "Context binary cache is not generated by Ort.";
return Status::OK();
}

bool partition_names_matched = true;
for (const auto& fused_node_graph : fused_nodes_and_graphs) {
const Node& fused_node = fused_node_graph.fused_node;
const std::string& graph_meta_id = fused_node.Name();
bool name_found = false;
for (auto partition_name_from_ctx : graph_partition_names) {
if (partition_name_from_ctx == graph_meta_id) {
name_found = true;
break;
}
}

if (!name_found) {
LOGS(logger, ERROR) << "Partition meta_id not found from any EPContext node: " << graph_meta_id;
partition_names_matched = false;
break;
}
}

if (model_name != model_name_from_ctx_cache ||
model_description != model_description_from_ctx_cache ||
!partition_names_matched) {
std::string message = onnxruntime::MakeString("Metadata mismatch. onnx: ",
model_name, " ", model_description,
" vs epcontext: ",
model_name_from_ctx_cache, " ",
model_description_from_ctx_cache,
" or the partition name not match.");
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_GRAPH, message);
}

return Status::OK();
}

Status GenerateCtxCacheOnnxModel(Model* model,
unsigned char* buffer,
uint64_t buffer_size,
Expand Down
13 changes: 0 additions & 13 deletions onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ Status LoadQnnCtxFromOnnxGraph(const onnxruntime::GraphViewer& graph_viewer,
QnnBackendManager* qnn_backend_manager,
std::unordered_map<std::string, std::unique_ptr<qnn::QnnModel>>& qnn_models);

Status ValidateWithContextFile(const std::vector<IExecutionProvider::FusedNodeAndGraph>& fused_nodes_and_graphs,
const onnxruntime::PathString& context_cache_path,
const std::string& model_name,
const std::string& model_description,
const logging::Logger& logger);

Status GetMetadataFromEpContextModel(const onnxruntime::PathString& ctx_onnx_model_path,
std::string& model_name,
std::string& model_description,
std::vector<std::string>& graph_partition_names,
std::string& cache_source,
const logging::Logger& logger);

Status GenerateCtxCacheOnnxModel(Model* model,
unsigned char* buffer,
uint64_t buffer_size,
Expand Down

0 comments on commit e7c0827

Please sign in to comment.