-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathgpa_context.h
More file actions
123 lines (95 loc) · 4.8 KB
/
Copy pathgpa_context.h
File metadata and controls
123 lines (95 loc) · 4.8 KB
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
//==============================================================================
// Copyright Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief GPA Common Context class.
//==============================================================================
#ifndef GPU_PERF_API_COMMON_GPA_CONTEXT_H_
#define GPU_PERF_API_COMMON_GPA_CONTEXT_H_
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <numeric>
#include "gpu_performance_api/gpu_perf_api_types.h"
#include "gpu_perf_api_common/gpa_common_defs.h"
#include "gpu_perf_api_common/gpa_context_interface.h"
#include "gpu_perf_api_common/gpa_session_interface.h"
/// @brief Type alias for list of IGpaSession objects.
using GpaSessionList = std::list<std::unique_ptr<IGpaSession>>;
/// @brief Abstract GPAContext for common context code.
class GpaContext : public IGpaContext
{
public:
/// @brief Delete default constructor.
GpaContext() = delete;
/// @brief Virtual Destructor.
virtual ~GpaContext() = default;
/// @copydoc IGpaContext::GetSupportedSampleTypes()
[[nodiscard]] std::optional<GpaContextSampleTypeFlags> GetSupportedSampleTypes() const override;
/// @copydoc IGpaContext::GetHwInfo()
const GpaHwInfo& GetHwInfo() const override;
/// @copydoc IGpaContext::UpdateHwInfo()
void UpdateHwInfo(GpaUInt32 num_shader_engines, GpaUInt32 num_compute_units, GpaUInt32 num_simds, GpaUInt32 num_waves_per_simd) override;
/// @copydoc IGpaContext::IsOpen()
bool IsOpen() const override;
/// @copydoc IGpaContext::GetDeviceClockMode()
DeviceClockMode GetDeviceClockMode() const override;
/// @copydoc IGpaInterfaceTrait::ObjectType()
GpaObjectType ObjectType() const override;
/// @copydoc IGpaContext::DoesSessionExist()
bool DoesSessionExist(GpaSessionId gpa_session_id) const override;
/// @copydoc IGpaContext::BeginSession()
GpaStatus BeginSession(IGpaSession* gpa_session) override;
/// @copydoc IGpaContext::EndSession()
GpaStatus EndSession(IGpaSession* gpa_session, bool force_end) override;
/// @copydoc IGpaContext::GetShaderEngineCount()
uint32_t GetShaderEngineCount() const override;
/// @copydoc IGpaContext::GetContextFlags()
GpaOpenContextFlags GetContextFlags() const override
{
return context_flags_;
}
/// @copydoc IGpaContext::GetActiveSession()
const IGpaSession* GetActiveSession() const override;
protected:
/// @brief Protected constructor.
///
/// @param [in] hw_info The hardware info for the context.
/// @param [in] flags Creation flags for context.
GpaContext(const GpaHwInfo& hw_info, GpaOpenContextFlags flags);
/// @brief Marks the context to be opened.
///
/// @param [in] open Flag indicating context to be marked open or closed.
void SetAsOpened(bool open);
/// @brief Adds the GPA session to the session list.
///
/// @param [in] gpa_session GPA session object pointer. Ownership is transferred to the context.
GPA_THREAD_SAFE_FUNCTION void AddGpaSession(std::unique_ptr<IGpaSession> gpa_session);
/// @brief Removes the GPA session from the session list, which destroys the session.
///
/// @param [in] gpa_session GPA session object pointer.
GPA_THREAD_SAFE_FUNCTION void RemoveGpaSession(IGpaSession* gpa_session);
/// @brief Iterate over GPA session list for the passed function.
///
/// @param [in] function Function to be executed for each object in the list. The function may return false to terminate iteration.
GPA_THREAD_SAFE_FUNCTION void IterateGpaSessionList(const std::function<bool(IGpaSession* gpa_session)>& function) const;
/// @brief Clears the list of the GPA session.
GPA_THREAD_SAFE_FUNCTION void ClearSessionList();
/// @brief Returns the index of the GPA session if it exists.
///
/// @param [in] gpa_session GPA session.
/// @param [out] index Index of the the GPA session in the list.
///
/// @return True if the index was found, false otherwise.
bool GetIndex(IGpaSession* gpa_session, unsigned int* index = nullptr) const;
private:
GpaOpenContextFlags context_flags_; ///< Context flags.
GpaHwInfo hw_info_; ///< Hw info.
bool is_open_; ///< Flag indicating context is open or not.
GpaSessionList gpa_session_list_; ///< List of GPA sessions in the context.
mutable std::mutex gpa_session_list_mutex_; ///< Mutex for GPA session list.
IGpaSession* active_session_; ///< Gpa session to keep track of active session.
mutable std::mutex active_session_mutex_; ///< Mutex for the active session.
};
#endif