-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GetSizeFromTensorTypeProo Wire in accounting Make CUDA EP resource aware and account on assignment Fix missing accountant for Ort format Remove redundant functions Remove unnecessary interface Fix DML issue, minor fixes Fix alert DEMO changes Implement node memory stats collection Place container in the session. Support nested graphs Add synchronization Update stats for the max consumption. Introduce input sizes computation.
- Loading branch information
1 parent
80f686e
commit cb2277d
Showing
72 changed files
with
1,362 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
include/onnxruntime/core/framework/resource_accountant.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
Check warning on line 6 in include/onnxruntime/core/framework/resource_accountant.h
|
||
#include <iosfwd> | ||
#include <optional> | ||
#include <string> | ||
#include <variant> | ||
|
||
#include "core/common/common.h" | ||
|
||
namespace onnxruntime { | ||
|
||
// Common holder for potentially different resource accounting | ||
// for different EPs | ||
using ResourceCount = std::variant<size_t, std::monostate>; | ||
|
||
/// <summary> | ||
/// This class is used for graph partitioning by EPs | ||
/// It stores the cumulative amount of the resource such as | ||
/// memory that would be consumed by the graph nodes if it is assigned to the EP. | ||
/// | ||
/// It provides interfaces to add, remove and query the resource consumption. | ||
/// | ||
/// Each provider may assign its own meaning to the resource according to its constraints. | ||
/// </summary> | ||
class IResourceAccountant { | ||
protected: | ||
IResourceAccountant() = default; | ||
IResourceAccountant(const ResourceCount& threshold) : threshold_(threshold) {} | ||
Check warning on line 32 in include/onnxruntime/core/framework/resource_accountant.h
|
||
|
||
public: | ||
virtual ~IResourceAccountant() = default; | ||
virtual ResourceCount GetConsumedAmount() const = 0; | ||
virtual void AddConsumedAmount(const ResourceCount& amount) = 0; | ||
virtual void RemoveConsumedAmount(const ResourceCount& amount) = 0; | ||
virtual ResourceCount ComputeResourceCount(const std::string& node_name) const = 0; | ||
|
||
std::optional<ResourceCount> GetThreshold() const { | ||
return threshold_; | ||
} | ||
|
||
void SetStopAssignment() noexcept { | ||
stop_assignment_ = true; | ||
} | ||
|
||
bool IsStopIssued() const noexcept { return stop_assignment_; } | ||
|
||
private: | ||
bool stop_assignment_ = false; | ||
std::optional<ResourceCount> threshold_; | ||
}; | ||
|
||
// This struct keeps accounting of the memory allocation stats | ||
// for a kernel during runtime if enabled. | ||
struct NodeAllocationStats { | ||
size_t input_sizes = 0; | ||
size_t initializers_sizes = 0; | ||
size_t total_dynamic_sizes = 0; | ||
size_t total_temp_allocations = 0; | ||
|
||
NodeAllocationStats& operator+=(const NodeAllocationStats& other) { | ||
input_sizes += other.input_sizes; | ||
initializers_sizes += other.initializers_sizes; | ||
total_dynamic_sizes += other.total_dynamic_sizes; | ||
total_temp_allocations += other.total_temp_allocations; | ||
return *this; | ||
} | ||
|
||
void UpdateIfGreater(const NodeAllocationStats& other) { | ||
input_sizes = std::max(input_sizes, other.input_sizes); | ||
initializers_sizes = std::max(initializers_sizes, other.initializers_sizes); | ||
total_dynamic_sizes = std::max(total_dynamic_sizes, other.total_dynamic_sizes); | ||
total_temp_allocations = std::max(total_temp_allocations, other.total_temp_allocations); | ||
Check warning on line 76 in include/onnxruntime/core/framework/resource_accountant.h
|
||
} | ||
}; | ||
|
||
class NodeStatsRecorder { | ||
public: | ||
explicit NodeStatsRecorder(const std::filesystem::path& stats_file_name); | ||
~NodeStatsRecorder(); | ||
|
||
ORT_DISALLOW_COPY_ASSIGNMENT_AND_MOVE(NodeStatsRecorder); | ||
|
||
const std::filesystem::path& GetNodeStatsFileName() const noexcept; | ||
|
||
void ReportNodeStats(const std::string& node_name, const NodeAllocationStats& stats); | ||
|
||
void DumpStats(std::ostream& os) const; | ||
|
||
private: | ||
// We would like to hide certain things that may not compile | ||
// with some device compilers | ||
struct Impl; | ||
std::unique_ptr<Impl> impl_; | ||
Check warning on line 97 in include/onnxruntime/core/framework/resource_accountant.h
|
||
}; | ||
|
||
} // namespace onnxruntime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.