Files
rocm-systems/projects/rocprofiler-systems/source/lib/rocprof-sys/library/amd_smi.hpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 строки
6.1 KiB
C++
Исходник Обычный вид История

2025-01-15 13:06:12 -05:00
// Copyright (c) 2018-2025 Advanced Micro Devices, Inc. All Rights Reserved.
2022-02-08 17:42:17 -06:00
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// with the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimers.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimers in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the names of Advanced Micro Devices, Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this Software without specific prior written permission.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
// THE SOFTWARE.
#pragma once
#include "core/common.hpp"
#include "core/components/fwd.hpp"
#include "core/defines.hpp"
#include "core/gpu_metrics.hpp"
#include "core/state.hpp"
2022-02-08 17:42:17 -06:00
#include "library/thread_data.hpp"
#if ROCPROFSYS_USE_ROCM > 0
# include <amd_smi/amdsmi.h>
#endif
2022-02-08 17:42:17 -06:00
#include <chrono>
#include <cstdint>
#include <deque>
#include <future>
#include <limits>
#include <memory>
#include <ratio>
#include <thread>
#include <tuple>
#include <type_traits>
namespace rocprofsys
2022-02-08 17:42:17 -06:00
{
namespace amd_smi
2022-02-08 17:42:17 -06:00
{
void
setup();
2022-02-19 02:00:59 -06:00
void
config();
void
sample();
2022-02-08 17:42:17 -06:00
void
shutdown();
2022-02-19 02:00:59 -06:00
void
post_process();
void set_state(State);
2024-02-08 07:06:23 -06:00
struct settings
{
2025-02-21 10:25:01 -05:00
bool busy = true;
bool temp = true;
bool power = true;
bool mem_usage = true;
bool vcn_activity = true;
bool jpeg_activity = true;
bool xgmi = true;
bool pcie = true;
2024-02-08 07:06:23 -06:00
};
2022-02-08 17:42:17 -06:00
struct data
{
using msec_t = std::chrono::milliseconds;
using usec_t = std::chrono::microseconds;
using nsec_t = std::chrono::nanoseconds;
using promise_t = std::promise<void>;
using timestamp_t = int64_t;
using power_t = uint32_t;
2022-02-08 17:42:17 -06:00
using busy_perc_t = uint32_t;
using mem_usage_t = uint64_t;
using temp_t = int64_t;
// Use the shared gpu_metrics_t from core/gpu_metrics.hpp
using gpu_metrics_t = rocprofsys::gpu::gpu_metrics_t;
ROCPROFSYS_DEFAULT_OBJECT(data)
2022-02-08 17:42:17 -06:00
explicit data(uint32_t _dev_id);
void sample(uint32_t _dev_id);
void print(std::ostream& _os) const;
static void post_process(uint32_t _dev_id);
uint32_t m_dev_id = std::numeric_limits<uint32_t>::max();
timestamp_t m_ts = 0;
temp_t m_temp = 0;
mem_usage_t m_mem_usage = 0;
std::vector<gpu_metrics_t> m_gpu_metrics = {};
#if ROCPROFSYS_USE_ROCM > 0
amdsmi_engine_usage_t m_busy_perc = {};
amdsmi_power_info_t m_power = {};
#else
std::vector<busy_perc_t> m_busy_perc = {};
std::vector<power_t> m_power = {};
#endif
2022-02-08 17:42:17 -06:00
friend std::ostream& operator<<(std::ostream& _os, const data& _v)
{
_v.print(_os);
return _os;
}
private:
friend void rocprofsys::amd_smi::setup();
friend void rocprofsys::amd_smi::config();
friend void rocprofsys::amd_smi::sample();
friend void rocprofsys::amd_smi::shutdown();
friend void rocprofsys::amd_smi::post_process();
2022-02-08 17:42:17 -06:00
static size_t device_count;
static std::set<uint32_t> device_list;
static std::unique_ptr<promise_t> polling_finished;
static std::vector<data>& get_initial();
static std::unique_ptr<std::thread>& get_thread();
static bool setup();
static bool shutdown();
};
2024-12-13 18:48:39 -05:00
#if !defined(ROCPROFSYS_USE_ROCM) || ROCPROFSYS_USE_ROCM == 0
2022-02-08 17:42:17 -06:00
inline void
setup()
{}
2022-02-19 02:00:59 -06:00
inline void
config()
{}
inline void
sample()
{}
2022-02-08 17:42:17 -06:00
inline void
shutdown()
{}
2022-02-19 02:00:59 -06:00
inline void
post_process()
{}
inline void
set_state(State)
{}
2022-02-08 17:42:17 -06:00
#endif
} // namespace amd_smi
} // namespace rocprofsys
2022-02-08 17:42:17 -06:00
2024-12-13 18:48:39 -05:00
#if defined(ROCPROFSYS_USE_ROCM) && ROCPROFSYS_USE_ROCM > 0
# if !defined(ROCPROFSYS_EXTERN_COMPONENTS) || \
(defined(ROCPROFSYS_EXTERN_COMPONENTS) && ROCPROFSYS_EXTERN_COMPONENTS > 0)
2022-02-08 17:42:17 -06:00
# include <timemory/components/base.hpp>
# include <timemory/components/data_tracker/components.hpp>
# include <timemory/operations.hpp>
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_busy_gfx>),
true, double)
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_busy_umc>),
true, double)
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_busy_mm>),
true, double)
2022-02-08 17:42:17 -06:00
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_temp>), true,
2022-02-08 17:42:17 -06:00
double)
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_power>), true,
2022-02-08 17:42:17 -06:00
double)
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_memory>), true,
2022-02-08 17:42:17 -06:00
double)
2024-12-18 15:56:48 -05:00
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_vcn>), true,
double)
2025-02-21 10:25:01 -05:00
ROCPROFSYS_DECLARE_EXTERN_COMPONENT(
TIMEMORY_ESC(data_tracker<double, rocprofsys::component::backtrace_gpu_jpeg>), true,
double)
2022-02-08 17:42:17 -06:00
# endif
#endif