[SWDEV-518071] Return HSA not loaded status (device counter collection) (#242)
* [SWDEV-518071] Return HSA not loaded status (device counter collection) This is a state that a caller would want to know about to understand if they got no counters because of a failure or if they were trying to collect counters too early (as is the case in the sample, which can attempt to collect counters before HSA is inited). * Minor edit * format * [SWDEV-518081] Simplify Metric Loading (#243) * [SWDEV-518071] Return HSA not loaded status (device counter collection) This is a state that a caller would want to know about to understand if they got no counters because of a failure or if they were trying to collect counters too early (as is the case in the sample, which can attempt to collect counters before HSA is inited). * [SWDEV-518324] Add AST update support Allows the ability for ASTs to be updated (instead of an unchangable static value). Adds a shared pointer return type to protect against static destructors/modifications from invalidating potentially in use AST definitions. No functionality/use changes in this PR. * [SWDEV-518593] Add updatable dimension cache + fix string issues (#252) * [SWDEV-518593] Add updatable dimension cache + fix string issues Updates dimension cache to use the same design pattern as AST/Metrics. Fixes the string scoping issue seen in ASTs, which appears here as well. * Add rocprofiler_create_counter Creates derived counters based on input from the API. This PR does three things: 1. Adds the API + test case 2. Validates that an AST can be constructed from the counter supplied. 3. Updates metrics, ast, and dimension caches to include the new metric. Metric should be available for use immediately after the call completes. Due to the regeneration of ASTs, this call should not be performed in performance sensitive code. * Suggestion fixes --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> * Minor tweak --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> Co-authored-by: Venkateshwar Reddy Kandula <vkandula@amd.com> --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> Co-authored-by: Venkateshwar Reddy Kandula <vkandula@amd.com> * Fixes for comments --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> Co-authored-by: Kandula, Venkateshwar reddy <Venkateshwarreddy.Kandula@amd.com> Co-authored-by: Venkateshwar Reddy Kandula <vkandula@amd.com> --------- Co-authored-by: Benjamin Welton <bewelton@amd.com> Co-authored-by: Kandula, Venkateshwar reddy <Venkateshwarreddy.Kandula@amd.com> Co-authored-by: Venkateshwar Reddy Kandula <vkandula@amd.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c30bb7cbda
Коммит
007285272b
@@ -44,7 +44,7 @@ namespace counters
|
||||
std::vector<MetricDimension>
|
||||
getBlockDimensions(std::string_view agent, const Metric& metric)
|
||||
{
|
||||
if(!metric.special().empty())
|
||||
if(!metric.constant().empty())
|
||||
{
|
||||
// Special non-hardware counters without dimension data
|
||||
return std::vector<MetricDimension>{{dimension_map().at(ROCPROFILER_DIMENSION_INSTANCE),
|
||||
@@ -95,34 +95,55 @@ getBlockDimensions(std::string_view agent, const Metric& metric)
|
||||
return ret;
|
||||
}
|
||||
|
||||
const std::unordered_map<uint64_t, std::vector<MetricDimension>>&
|
||||
get_dimension_cache()
|
||||
namespace
|
||||
{
|
||||
static auto*& cache =
|
||||
common::static_object<std::unordered_map<uint64_t, std::vector<MetricDimension>>>::
|
||||
construct([]() -> std::unordered_map<uint64_t, std::vector<MetricDimension>> {
|
||||
std::unordered_map<uint64_t, std::vector<MetricDimension>> dims;
|
||||
metric_dims
|
||||
generate_dimensions()
|
||||
{
|
||||
std::unordered_map<uint64_t, std::vector<MetricDimension>> dims;
|
||||
|
||||
const auto& asts = counters::get_ast_map();
|
||||
for(const auto& [gfx, metrics] : asts)
|
||||
{
|
||||
for(const auto& [metric, ast] : metrics)
|
||||
{
|
||||
auto ast_copy = ast;
|
||||
try
|
||||
{
|
||||
dims.emplace(ast.out_id().handle, ast_copy.set_dimensions());
|
||||
} catch(std::runtime_error& e)
|
||||
{
|
||||
ROCP_ERROR << metric << " has improper dimensions"
|
||||
<< " " << e.what();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dims;
|
||||
}());
|
||||
return *cache;
|
||||
const auto asts = counters::get_ast_map();
|
||||
for(const auto& [gfx, metrics] : asts->arch_to_counter_asts)
|
||||
{
|
||||
for(const auto& [metric, ast] : metrics)
|
||||
{
|
||||
auto ast_copy = ast;
|
||||
try
|
||||
{
|
||||
dims.emplace(ast.out_id().handle, ast_copy.set_dimensions());
|
||||
} catch(std::runtime_error& e)
|
||||
{
|
||||
ROCP_FATAL << metric << " has improper dimensions"
|
||||
<< " " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
return {.id_to_dim = dims};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::shared_ptr<const metric_dims>
|
||||
get_dimension_cache(bool reload)
|
||||
{
|
||||
using DimSync = common::Synchronized<std::shared_ptr<const metric_dims>>;
|
||||
static DimSync*& dim_data = common::static_object<DimSync>::construct(
|
||||
[&]() { return std::make_shared<const metric_dims>(generate_dimensions()); }());
|
||||
|
||||
if(!dim_data) return nullptr;
|
||||
|
||||
if(!reload)
|
||||
{
|
||||
return dim_data->rlock([](const auto& data) {
|
||||
CHECK(data);
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
return dim_data->wlock([&](auto& data) {
|
||||
data = std::make_shared<const metric_dims>(generate_dimensions());
|
||||
CHECK(data);
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace counters
|
||||
|
||||
Ссылка в новой задаче
Block a user