-
Notifications
You must be signed in to change notification settings - Fork 46
/
gpa_counter_scheduler_base.h
149 lines (109 loc) · 6.05 KB
/
gpa_counter_scheduler_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//==============================================================================
// Copyright (c) 2016-2023 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief Base Class for counter scheduling.
//==============================================================================
#ifndef GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_COUNTER_SCHEDULER_BASE_H_
#define GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_COUNTER_SCHEDULER_BASE_H_
#include "gpu_perf_api_counter_generator/gpa_counter_scheduler_interface.h"
#include "gpu_perf_api_counter_generator/gpa_split_counter_factory.h"
/// @brief Base Class for counter scheduling.
class GpaCounterSchedulerBase : public IGpaCounterScheduler
{
public:
/// @brief Constructor.
GpaCounterSchedulerBase();
/// @brief Destructor.
~GpaCounterSchedulerBase() = default;
/// @copydoc IGpaCounterScheduler::Reset()
void Reset() override;
/// @copydoc IGpaCounterScheduler::SetCounterAccessor()
GpaStatus SetCounterAccessor(IGpaCounterAccessor* counter_accessor, GpaUInt32 vendor_id, GpaUInt32 device_id, GpaUInt32 revision_id) override;
/// @copydoc IGpaCounterScheduler::GetNumEnabledCounters()
GpaUInt32 GetNumEnabledCounters() const override;
/// @copydoc IGpaCounterScheduler::EnableCounter()
GpaStatus EnableCounter(GpaUInt32 index) override;
/// @copydoc IGpaCounterScheduler::DisableCounter()
GpaStatus DisableCounter(GpaUInt32 index) override;
/// @copydoc IGpaCounterScheduler::DisableAllCounters()
void DisableAllCounters() override;
/// @copydoc IGpaCounterScheduler::GetEnabledIndex()
GpaStatus GetEnabledIndex(GpaUInt32 enabled_index, GpaUInt32* counter_at_index) const override;
/// @copydoc IGpaCounterScheduler::IsCounterEnabled()
GpaStatus IsCounterEnabled(GpaUInt32 counter_index) const override;
/// @copydoc IGpaCounterScheduler::GetNumRequiredPasses()
GpaStatus GetNumRequiredPasses(GpaUInt32* num_required_passes_out) override;
/// @copydoc IGpaCounterScheduler::GetCounterSelectionChanged()
bool GetCounterSelectionChanged() const override;
/// @copydoc IGpaCounterScheduler::BeginProfile()
GpaStatus BeginProfile() override;
/// @copydoc IGpaCounterScheduler::BeginPass()
void BeginPass() override;
/// @copydoc IGpaCounterScheduler::GetCountersForPass()
std::vector<unsigned int>* GetCountersForPass(GpaUInt32 pass_index) override;
/// @copydoc IGpaCounterScheduler::EndPass()
void EndPass() override;
/// @copydoc IGpaCounterScheduler::EndProfile()
GpaStatus EndProfile() override;
/// @copydoc IGpaCounterScheduler::GetCounterResultLocations()
CounterResultLocationMap* GetCounterResultLocations(unsigned int public_counter_index) override;
/// @copydoc IGpaCounterScheduler::SetDrawCallCounts()
void SetDrawCallCounts(int internal_counts) override;
protected:
/// @brief Gets the preferred counter splitting algorithm.
///
/// @return the preferred counter splitting algorithm.
virtual GpaCounterSplitterAlgorithm GetPreferredSplittingAlgorithm() const = 0;
/// @brief Helper function to disable a counter.
///
/// @param [in] index The index of the counter to disable.
///
/// @return kGpaStatusOk on success.
virtual GpaStatus DoDisableCounter(GpaUInt32 index);
/// @brief Helper function called when beginning a profile.
///
/// @return kGpaStatusOk on success.
virtual GpaStatus DoBeginProfile();
/// @brief Helper function called when ending a profile.
///
/// @return kGpaStatusOk on success.
virtual GpaStatus DoEndProfile();
/// @brief Helper function called when beginning a pass.
virtual void DoBeginPass();
/// @brief Helper function called when ending a pass.
virtual void DoEndPass();
/// @brief Helper function called when setting draw call counts.
///
/// @param [in] internal_count Draw call count per frame.
virtual void DoSetDrawCallCounts(int internal_count);
/// @brief A map between a public counter index and the set of hardware counters that compose the public counter.
///
/// For each hardware counter, there is a map from the hardware counter to the counter result location (pass and offset) for that specific counter.
/// Multiple public counters may be enabled which require the same hardware counter, but the hardware counter may be profiled in multiple passes so
/// that the public counters will be consistent. This complex set of maps allows us to find the correct pass and offset for the instance of a
/// hardware counter that is required for a specific public counter.
std::map<DerivedCounterIndex, CounterResultLocationMap> counter_result_location_map_;
/// The counter accessor used by the scheduler.
IGpaCounterAccessor* counter_accessor_;
/// The vendor id used by the scheduler.
GpaUInt32 vendor_id_;
/// The device id used by the scheduler.
GpaUInt32 device_id_;
/// The revision id used by the scheduler.
GpaUInt32 revision_id_;
/// This must be maintained in parallel with enabled_public_counter_bits_ - both are views of the list of active counters
/// enabled_public_indices_ as a list of indices, enabled_public_counter_bits_ as a random access bool array.
std::vector<GpaUInt32> enabled_public_indices_;
/// This must be maintained in parallel with enabled_public_indices_ - both are views of the list of active counters
/// enabled_public_counter_bits_ was added for performance reasons.
std::vector<bool> enabled_public_counter_bits_;
/// Records whether or not the counter selection changed since GPA_BeginSampling was last called.
bool counter_selection_changed_;
/// List of passes, which are identified by a list of counter indices which are in that pass.
/// Populated when GetNumRequiredPasses is called.
GpaCounterPassList pass_partitions_;
/// As the profile is happening, this tracks the current pass.
unsigned int pass_index_;
};
#endif // GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_COUNTER_SCHEDULER_BASE_H_