Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the functions in tensorprotoutils.h to use std::filesystem::path instead #20920

Merged
merged 70 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
abfc344
a
snnn Jun 4, 2024
35ed41d
update
snnn Jun 4, 2024
a7fa253
update
snnn Jun 4, 2024
70209c0
udpate
snnn Jun 4, 2024
751de26
Fix bug
snnn Jun 4, 2024
1168d5a
update
snnn Jun 4, 2024
66f00dd
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 4, 2024
39ccb76
update
snnn Jun 4, 2024
6e4e440
update
snnn Jun 4, 2024
042a90e
revert
snnn Jun 4, 2024
80872ce
update
snnn Jun 4, 2024
cf98d38
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 4, 2024
cdb0ee3
Merge remote-tracking branch 'origin/snnn/filesystem' into snnn/files…
snnn Jun 4, 2024
eff3480
update
snnn Jun 5, 2024
802a3b8
update
snnn Jun 5, 2024
9ed5dd6
update
snnn Jun 5, 2024
26f9193
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 5, 2024
e3c90d4
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 6, 2024
7e2e9cb
update
snnn Jun 6, 2024
f402772
Update onnxruntime/core/framework/model_metadef_id_generator.cc
snnn Jun 6, 2024
a71751f
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 6, 2024
8f88a65
Update onnxruntime/core/graph/graph.cc
snnn Jun 6, 2024
2af9b4a
Merge remote-tracking branch 'origin/snnn/filesystem' into snnn/files…
snnn Jun 6, 2024
6964a70
update
snnn Jun 6, 2024
5f3080e
update
snnn Jun 6, 2024
4da5229
update
snnn Jun 6, 2024
e787172
update
snnn Jun 6, 2024
72eb1e1
update
snnn Jun 6, 2024
f5b9abf
update
snnn Jun 7, 2024
7e6c67b
update
snnn Jun 7, 2024
0d77607
update
snnn Jun 7, 2024
2039f95
update
snnn Jun 7, 2024
f5e362b
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 10, 2024
86751d1
Add filesystem header
snnn Jun 10, 2024
9074a9b
update
snnn Jun 10, 2024
0d142ab
Add line wrapping
snnn Jun 10, 2024
ac3c3a1
Line wrapping
snnn Jun 10, 2024
b8a314c
Update graph_partitioner.cc
snnn Jun 10, 2024
1ecc42d
Update tensorprotoutils.cc
snnn Jun 10, 2024
27388d6
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 11, 2024
2c6c2c1
Update onnxruntime/core/framework/tensorprotoutils.cc
snnn Jun 11, 2024
dce865d
update
snnn Jun 11, 2024
85608e0
Merge branch 'snnn/filesystem' of https://github.com/microsoft/onnxru…
snnn Jun 11, 2024
7ecb8e7
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 12, 2024
fb70965
revert
snnn Jun 12, 2024
ee284cb
update
snnn Jun 12, 2024
75d75ef
update
snnn Jun 12, 2024
a704d4a
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 12, 2024
f5524d8
update
snnn Jun 12, 2024
191053f
update
snnn Jun 13, 2024
076d569
update
snnn Jun 13, 2024
69d7485
fix
snnn Jun 13, 2024
d0b8d4e
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 13, 2024
8f68f88
update
snnn Jun 13, 2024
d2785d8
update
snnn Jun 14, 2024
69868e5
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 14, 2024
b2d57da
Revert "update"
snnn Jun 14, 2024
148d94a
update
snnn Jun 14, 2024
2572653
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 14, 2024
9d2135b
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 20, 2024
b9e280f
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 24, 2024
0bace1a
update
snnn Jun 24, 2024
5827bdd
Update onnxruntime/core/framework/tensorprotoutils.cc
snnn Jun 25, 2024
a6b6147
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 25, 2024
e9fad36
update
snnn Jun 25, 2024
01423c4
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 26, 2024
514ea8c
update
snnn Jun 26, 2024
0f7edb0
Update onnxruntime/core/graph/graph.cc
snnn Jun 27, 2024
19009ce
Update onnxruntime/core/graph/graph.cc
snnn Jun 27, 2024
2f399b6
Merge remote-tracking branch 'origin/main' into snnn/filesystem
snnn Jun 27, 2024
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
1 change: 0 additions & 1 deletion cmake/onnxruntime_providers_tensorrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(PROTOBUF_LIBRARY ${PROTOBUF_LIB})
if (WIN32)
add_definitions(-D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING=1)
set(OLD_CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4099 /wd4551 /wd4505 /wd4515 /wd4706 /wd4456 /wd4324 /wd4701 /wd4804 /wd4702 /wd4458 /wd4703")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
22 changes: 7 additions & 15 deletions include/onnxruntime/core/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

#ifdef _WIN32
#pragma warning(push)
// disable some warnings from protobuf to pass Windows build
#pragma warning(disable : 4244)
#endif

#ifdef _WIN32
#pragma warning(pop)
#endif
#include <filesystem>

#include "core/common/flatbuffers.h"

Expand Down Expand Up @@ -147,7 +138,7 @@ class Node {
const std::string& Domain() const noexcept { return domain_; }

/** Gets the path of the owning model if any. */
const Path& ModelPath() const noexcept;
const std::filesystem::path& ModelPath() const noexcept;

/** Gets the Node's execution priority.
@remarks Lower value means higher priority */
Expand Down Expand Up @@ -693,7 +684,7 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
const std::string& Description() const noexcept;

/** Gets the path of the owning model, if any. */
const Path& ModelPath() const;
const std::filesystem::path& ModelPath() const;

/** Returns true if this is a subgraph or false if it is a high-level graph. */
bool IsSubgraph() const { return parent_graph_ != nullptr; }
Expand Down Expand Up @@ -1149,13 +1140,14 @@ class Graph { // NOLINT(clang-analyzer-optin.performance.Padding): preserve exi
ONNX_NAMESPACE::GraphProto ToGraphProto() const;

/** Gets the GraphProto representation of this Graph
@params external_file_name name of the binary file to use for initializers
@param external_file_path File path of the binary file to use for initializers.
@param model_file_path path of the model file.
@param initializer_size_threshold initializers larger or equal to this threshold (in bytes) are saved
in the external file. Initializer smaller than this threshold are included in the onnx file.
@returns GraphProto serialization of the graph.
*/
ONNX_NAMESPACE::GraphProto ToGraphProtoWithExternalInitializers(const std::string& external_file_name,
const PathString& file_path,
ONNX_NAMESPACE::GraphProto ToGraphProtoWithExternalInitializers(const std::filesystem::path& external_file_path,
const std::filesystem::path& model_file_path,
size_t initializer_size_threshold) const;

/** Gets the ISchemaRegistry instances being used with this Graph. */
Expand Down
5 changes: 3 additions & 2 deletions include/onnxruntime/core/graph/graph_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Licensed under the MIT License.

#pragma once
#include <unordered_set>
#include <filesystem>

#include "core/graph/graph.h"
#include "core/framework/session_options.h"
#include <unordered_set>

namespace onnxruntime {
class Function;
Expand Down Expand Up @@ -43,7 +44,7 @@ class GraphViewer {
const std::string& Description() const noexcept;

/** Gets the path of the owning model if any **/
const Path& ModelPath() const noexcept { return graph_->ModelPath(); }
const std::filesystem::path& ModelPath() const noexcept { return graph_->ModelPath(); }

/**
Gets a tensor created from an initializer.
Expand Down
24 changes: 11 additions & 13 deletions onnxruntime/core/framework/graph_partitioner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ static Status InlineFunctionsAOTImpl(const ExecutionProviders& execution_provide

static Status CreateEpContextModel(const ExecutionProviders& execution_providers,
const Graph& graph,
const std::string& ep_context_path,
const std::filesystem::path& ep_context_path,
const logging::Logger& logger) {
InlinedVector<const Node*> all_ep_context_nodes;
for (const auto& ep : execution_providers) {
Expand All @@ -658,22 +658,20 @@ static Status CreateEpContextModel(const ExecutionProviders& execution_providers
return std::make_pair(false, static_cast<const Node*>(nullptr));
};

onnxruntime::PathString context_cache_path;
PathString model_pathstring = graph.ModelPath().ToPathString();
std::filesystem::path context_cache_path;
const std::filesystem::path& model_path = graph.ModelPath();

if (!ep_context_path.empty()) {
context_cache_path = ToPathString(ep_context_path);
} else if (!model_pathstring.empty()) {
context_cache_path = model_pathstring + ToPathString("_ctx.onnx");
context_cache_path = ep_context_path;
} else if (!model_path.empty()) {
context_cache_path = model_path.native() + ORT_TSTR("_ctx.onnx");
} else {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Both ep_context_path and model_path are empty");
}

{
#ifdef _WIN32
std::wifstream fs(context_cache_path);
#else
std::ifstream fs(context_cache_path);
#endif
ORT_RETURN_IF(fs.good(), "Failed to generate EP context model since the file exist already.");
if (std::filesystem::exists(context_cache_path)) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Failed to generate EP context model since the file '",
context_cache_path, "' exist already.");
}

Model ep_context_model(graph.Name(), false, ModelMetaData(), PathString(), IOnnxRuntimeOpSchemaRegistryList(),
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/framework/model_metadef_id_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int ModelMetadefIdGenerator::GenerateId(const onnxruntime::GraphViewer& graph_vi

// prefer path the model was loaded from
// this may not be available if the model was loaded from a stream or in-memory bytes
const auto& model_path_str = main_graph.ModelPath().ToPathString();
const auto model_path_str = main_graph.ModelPath().string();
snnn marked this conversation as resolved.
Show resolved Hide resolved
if (!model_path_str.empty()) {
MurmurHash3::x86_128(model_path_str.data(), gsl::narrow_cast<int32_t>(model_path_str.size()), hash[0], &hash);
} else {
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/framework/node_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const std::string& NodeUnit::OpType() const noexcept { return target_node_.OpTyp
const std::string& NodeUnit::Name() const noexcept { return target_node_.Name(); }
int NodeUnit::SinceVersion() const noexcept { return target_node_.SinceVersion(); }
NodeIndex NodeUnit::Index() const noexcept { return target_node_.Index(); }
const Path& NodeUnit::ModelPath() const noexcept { return target_node_.ModelPath(); }
const std::filesystem::path& NodeUnit::ModelPath() const noexcept { return target_node_.ModelPath(); }
ProviderType NodeUnit::GetExecutionProviderType() const noexcept { return target_node_.GetExecutionProviderType(); }

void NodeUnit::InitForSingleNode() {
Expand Down
3 changes: 2 additions & 1 deletion onnxruntime/core/framework/node_unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <optional>
#include <vector>
#include <filesystem>

#include "core/graph/basic_types.h"
#include "core/graph/graph.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ class NodeUnit {
const std::string& Name() const noexcept;
int SinceVersion() const noexcept;
NodeIndex Index() const noexcept;
const Path& ModelPath() const noexcept;
const std::filesystem::path& ModelPath() const noexcept;
ProviderType GetExecutionProviderType() const noexcept;

const Node& GetNode() const noexcept { return target_node_; }
Expand Down
3 changes: 2 additions & 1 deletion onnxruntime/core/framework/session_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>
#include <iostream>
#include <codecvt>
#include <filesystem>
#include "core/common/gsl.h"
#include "core/common/inlined_containers.h"
#include "core/framework/config_options.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ struct SessionOptions {
//
// If session config value is not set, it will be assumed to be ONNX
// unless the filepath ends in '.ort' (case insensitive).
std::basic_string<ORTCHAR_T> optimized_model_filepath;
std::filesystem::path optimized_model_filepath;
edgchen1 marked this conversation as resolved.
Show resolved Hide resolved

// enable the memory pattern optimization.
// The idea is if the input shapes are the same, we could trace the internal memory allocation
Expand Down
Loading
Loading