Files
rocm-systems/projects/rocprofiler-sdk/source/lib/rocprofiler/counters/metrics.cpp
T
Jonathan R. Madsen 1bf4cb0893 Agent information w/o using hsa-runtime (#100)
* Agent information w/o using hsa-runtime

- remove lib/rocprofiler/hsa/agent.{hpp,cpp}
- update include/rocprofiler/agent.h
  - basically all possible info from /sys/class/kfd/kfd/topology/nodes/*

* Print topology in rocprofiler_lib.agent test

- hack to help diagnose errors

* Update lib/rocprofiler/tests/details/agent.cpp

- use LOG_IF(WARNING, ...) instead of LOG_IF(FATAL, ...)

* Update lib/rocprofiler/tests/agent.cpp

- print rocminfo at beginning of test
- fix comparison of agent handle
- misc other checks

* Updte lib/rocprofiler/agent.cpp

- handle unreadable /sys/class/kfd/kfd/topology/nodes/<N>/properties file

* Update lib/tests/buffering/CMakeLists.txt

- increase timeout to 120
  - buffering.parallel will timeout when thread sanitizing is enabled

* Update cmake: rocprofiler-drm

- find drm headers and libraries

* Update include/rocprofiler/agent.h

- add family_id field

* Update lib/rocprofiler/agent.cpp

- parse /proc/cpuinfo for name, family, apicid, etc.
- read_topology uses unique pointers to cleanup memory allocations
- implement name and gfxip

* Update lib/rocprofiler/tests/agent.cpp

- improved failure message
- check name/gfxip
- remove check against hsa_agent_t.handle
  - this value is dependent on the address of C++ class

* Update lib/rocprofiler/tests/details/agent.cpp

- tweak gfxip_ variable which is broken for CPU

* Update lib/rocprofiler/agent.cpp

- update string handling for name and gfxip

* Update lib/rocprofiler/tests/agent.cpp

- minor output tweak

* Update lib/rocprofiler/registration.{hpp,cpp}

- registration::init_logging() function

* Update lib/rocprofiler/agent.cpp

- fix hex handling of GFX step version

* Update lib/rocprofiler/tests/details/agent.cpp

- fix format string when nearest CPUs not found

* Update lib/rocprofiler/tests/CMakeLists.txt

- exclude details/agent.cpp from being parsed for gtest tests

* Update include/rocprofiler/fwd.h

- add ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_ABI status

* Update lib/rocprofiler/tests/details/agent.{hpp,cpp}

- replace with slightly modified implementation of rocminfo
  - primary change was not printing

* Update lib/rocprofiler/tests/agent.cpp

- update test to use rocminfo data

* Update lib/rocprofiler/agent.cpp

- add pc_sampling_configs
- return error on incompatible ABI

* Update counters and counters tests

- rename test names for consistency
- fixed incorrect spelling of derived

* Add lib/rocprofiler/tests/{timestamp,version}.cpp

- add timestamp and version tests for rocprofiler_get_timestamp and rocprofiler_get_version, respectively

* Update lib/rocprofiler/tests/agent

- fix double free of name_str from isa_info_t

* Update include/rocprofiler/agent.h

- comments for rocprofiler_agent_mem_bank_t
- add rocprofiler_dim3_t
- comments for rocprofiler_agent_t
- add new fields to rocprofiler_agent_t
    - cu_count
    - workgroup_max_size
    - workgroup_max_dim
    - grid_max_size
    - grid_max_dim
    - vendor_name
    - product_name
- change prototype of rocprofiler_available_agents_cb_t to be const agent**

* Update lib/rocprofiler/agent.cpp

- set size field
- implement:
  - product_name
  - vendor_name
  - workgroup_max_size
  - workgroup_max_dim
  - grid_max_size
  - grid_max_dim
  - cu_count

* Update lib/rocprofiler/tests/agent.cpp

- changes for const agent*

* Update samples/pc_sampling

- updates for const agent*

* Update lib/rocprofiler/agent.cpp

- fix ABI compatibility check
  - return incompatible if tool agent is larger than our agent

* Update include/rocprofiler/agent.h

- doxygen comments
- make size field of rocprofiler_agent_t uint64_t for consistency
- add gpu_id via /sys/class/kfd/kfd/.../<idx>/gpu_id
- add model_name via /sys/class/kfd/kfd/.../<idx>/name

* Update lib/rocprofiler/agent.cpp

- add read_file function (vector of strings)
- support enum in read_property
- assign model_name and gpu_id fields
- remove unique_id

* Update lib/rocprofiler/tests/details/agent.*

- support family id, ucode_version, sdma_ucode_version

* Update lib/rocprofiler/tests/agent.cpp

- Add rocprofiler_lib.agent_abi test
- Verify family_id, ucode_version, sdma_ucode_version

[ROCm/rocprofiler-sdk commit: a798a26227]
2023-10-10 18:10:23 -05:00

119 строки
4.0 KiB
C++

/******************************************************************************
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in 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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
AUTHORS 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 IN
THE SOFTWARE.
*******************************************************************************/
#include "metrics.hpp"
#include <dlfcn.h> // for dladdr
#include <cstdlib>
#include <filesystem>
#include <optional>
#include "glog/logging.h"
#include "lib/common/xml.hpp"
#include "rocprofiler/rocprofiler.h"
namespace counters
{
namespace
{
MetricMap
loadXml(const std::string& filename)
{
MetricMap ret;
DLOG(INFO) << "Loading Counter Config: " << filename;
// todo: return unique_ptr....
auto xml = xml::Xml::Create(filename);
LOG_IF(FATAL, !xml)
<< "Could not open XML Counter Config File (set env ROCPROFILER_METRICS_PATH)";
for(const auto& [gfx_name, nodes] : xml->GetAllNodes())
{
/**
* "top." is used to designate the root encapsulation of all contained XML subroots (in our
* case "gfxX"). This is inserted by the parser so it will always be present. .metric
* denotes XML tags that are contained in the subroots. This will not change unless we
* respec the XML (which we should...).
*/
if(gfx_name.find("metric") == std::string::npos ||
gfx_name.find("top.") == std::string::npos)
continue;
auto& metricVec =
ret.emplace(gfx_name.substr(strlen("top."),
gfx_name.size() - strlen("top.") - strlen(".metric")),
std::vector<Metric>())
.first->second;
for(const auto& node : nodes)
{
metricVec.emplace_back(node->opts["name"],
node->opts["block"],
node->opts["event"],
node->opts["descr"],
node->opts["expr"]);
}
}
DLOG(INFO) << fmt::format("{}", ret);
return ret;
}
std::string
findViaInstallPath(const std::string& filename)
{
Dl_info dl_info;
DLOG(INFO) << filename << " is being looked up via install path";
if(dladdr(reinterpret_cast<const void*>(rocprofiler_query_available_agents), &dl_info) != 0)
{
return std::filesystem::path{dl_info.dli_fname}.remove_filename() /
fmt::format("../lib/{}", filename);
}
return filename;
}
std::string
findViaEnvironment(const std::string& filename)
{
if(getenv("ROCPROFILER_METRICS_PATH"))
{
DLOG(INFO) << filename << " is being looked up via env variable ROCPROFILER_METRICS_PATH";
return std::filesystem::path{std::string(getenv("ROCPROFILER_METRICS_PATH"))} / filename;
}
// No environment variable, lookup via install path
return findViaInstallPath(filename);
}
} // namespace
MetricMap
getDerivedHardwareMetrics()
{
return loadXml(findViaEnvironment("derived_counters.xml"));
}
MetricMap
getBaseHardwareMetrics()
{
return loadXml(findViaEnvironment("basic_counters.xml"));
}
}; // namespace counters