Skip to content

Commit

Permalink
Fix topdown build
Browse files Browse the repository at this point in the history
  • Loading branch information
daboehme committed Oct 28, 2024
1 parent b7139cc commit 05ce05a
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 65 deletions.
13 changes: 3 additions & 10 deletions src/services/papi/Papi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class PapiService

int num = static_cast<int>(p.second->codes.size());

if (!m_disable_multiplex && cpi
&& (num > 4 /* magic number for Intel counter support :-( */ || m_enable_multiplex)) {
if (m_enable_multiplex) {
if (Log::verbosity() >= 2)
Log(2).stream() << "papi: Initializing multiplex support for component " << p.first << " ("
<< cpi->name << ")" << std::endl;
Expand Down Expand Up @@ -498,15 +497,9 @@ const char* PapiService::s_spec = R"json(
},
{
"name": "enable_multiplexing",
"description": "Always enable multiplexing",
"description": "Enable multiplexing",
"type": "bool",
"value": "False"
},
{
"name": "disable_multiplexing",
"description": "Always disable multiplexing",
"type": "bool",
"value": "False"
"value": "false"
}
]
}
Expand Down
17 changes: 15 additions & 2 deletions src/services/topdown/HaswellTopdown.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "HaswellTopdown.h"

#include "../Services.h"

#include "caliper/common/Log.h"
#include "caliper/common/RuntimeConfig.h"

#include <algorithm>

namespace cali
Expand Down Expand Up @@ -53,9 +58,17 @@ HaswellTopdown::HaswellTopdown(IntelTopdownLevel level)
)
{}

bool HaswellTopdown::check_for_disabled_multiplex() const
bool HaswellTopdown::setup_config(Caliper& c, Channel& channel) const
{
return false;
channel.config().set("CALI_PAPI_COUNTERS", m_level == All ? m_all_counters : m_top_counters);
channel.config().set("CALI_PAPI_ENABLE_MULTIPLEXING", "true");
if (!cali::services::register_service(&c, &channel, "papi")) {
Log(0).stream() << channel.name() << ": topdown: Unable to register papi service, skipping topdown"
<< std::endl;
return false;
}

return true;
}

std::vector<Entry> HaswellTopdown::compute_toplevel(const std::vector<Entry>& rec)
Expand Down
11 changes: 1 addition & 10 deletions src/services/topdown/HaswellTopdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@ class HaswellTopdown : public TopdownCalculator

virtual ~HaswellTopdown() = default;

virtual bool check_for_disabled_multiplex() const override;
virtual bool setup_config(Caliper& c, Channel& channel) const override;

virtual std::vector<Entry> compute_toplevel(const std::vector<Entry>& rec) override;

virtual std::size_t get_num_expected_toplevel() const override;

virtual std::vector<Entry> compute_retiring(const std::vector<Entry>& rec) override;

virtual std::size_t get_num_expected_retiring() const override;

virtual std::vector<Entry> compute_backend_bound(const std::vector<Entry>& rec) override;

virtual std::size_t get_num_expected_backend_bound() const override;

virtual std::vector<Entry> compute_frontend_bound(const std::vector<Entry>& rec) override;

virtual std::size_t get_num_expected_frontend_bound() const override;

virtual std::vector<Entry> compute_bad_speculation(const std::vector<Entry>& rec) override;

virtual std::size_t get_num_expected_bad_speculation() const override;
};

Expand Down
69 changes: 32 additions & 37 deletions src/services/topdown/IntelTopdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../Services.h"

#include <algorithm>
#include <memory>
#include <sstream>

using namespace cali;
Expand All @@ -40,13 +41,18 @@ class IntelTopdown
unsigned num_ret_computed;
unsigned num_ret_skipped;

cali::topdown::IntelTopdownLevel m_level;
topdown::IntelTopdownLevel m_level;
std::shared_ptr<topdown::TopdownCalculator> m_calculator;

cali::topdown::TopdownCalculator* m_calculator;

bool find_counter_attrs(CaliperMetadataAccessInterface& db) { return m_calculator->find_counter_attrs(db); }
bool find_counter_attrs(CaliperMetadataAccessInterface& db)
{
return m_calculator->find_counter_attrs(db);
}

void make_result_attrs(CaliperMetadataAccessInterface& db) { m_calculator->make_result_attrs(db); }
void make_result_attrs(CaliperMetadataAccessInterface& db)
{
m_calculator->make_result_attrs(db);
}

void postprocess_snapshot_cb(std::vector<Entry>& rec)
{
Expand Down Expand Up @@ -122,7 +128,7 @@ class IntelTopdown
}
}

explicit IntelTopdown(cali::topdown::TopdownCalculator* calculator)
explicit IntelTopdown(std::shared_ptr<topdown::TopdownCalculator>& calculator)
: num_top_computed(0),
num_top_skipped(0),
num_be_computed(0),
Expand All @@ -133,17 +139,17 @@ class IntelTopdown
num_bsp_skipped(0),
m_level(calculator->get_level()),
m_calculator(calculator)
{}
{
}

~IntelTopdown()
{
if (m_calculator != nullptr) {
delete m_calculator;
}
}

public:

static const char* s_spec;

static void intel_topdown_register(Caliper* c, Channel* channel)
{
cali::topdown::IntelTopdownLevel level = cali::topdown::Top;
Expand All @@ -159,32 +165,18 @@ class IntelTopdown
return;
}

cali::topdown::TopdownCalculator* calculator;

std::shared_ptr<topdown::TopdownCalculator> calculator;
#if defined(CALIPER_HAVE_ARCH)
if (std::string(CALIPER_HAVE_ARCH) == "sapphirerapids") {
calculator = new cali::topdown::SapphireRapidsTopdown(level);
calculator = std::shared_ptr<topdown::TopdownCalculator>(new topdown::SapphireRapidsTopdown(level));
} else {
#endif
calculator = new cali::topdown::HaswellTopdown(level); // Default type of calculation
calculator = std::shared_ptr<topdown::TopdownCalculator>(new topdown::HaswellTopdown(level)); // Default type of calculation
#if defined(CALIPER_HAVE_ARCH)
}
#endif

channel->config().set("CALI_PAPI_COUNTERS", calculator->get_counters());
// Some PAPI counters for topdown (particularly on SPR) don't play nice
// with PAPI multiplexing. Ask the TopdownCalculator class whether we need
// to disable multiplexing for the corresponding architecture.
channel->config().set(
"CALI_PAPI_DISABLE_MULTIPLEXING",
calculator->check_for_disabled_multiplex() ? "true" : "false"
);

if (!cali::services::register_service(c, channel, "papi")) {
Log(0).stream() << channel->name() << ": topdown: Unable to register papi service, skipping topdown"
<< std::endl;
return;
}
calculator->setup_config(*c, *channel);

IntelTopdown* instance = new IntelTopdown(calculator);

Expand All @@ -207,15 +199,18 @@ class IntelTopdown
};

const char* IntelTopdown::s_spec = R"json(
{ "name": "topdown",
"description": "Record PAPI counters and compute top-down analysis for Intel CPUs",
"config": [
{ "name": "level",
"description": "Top-down analysis level to compute ('all' or 'top')",
"type": "string",
"value": "top"
}
]
{
"name": "topdown",
"description": "Record PAPI counters and compute top-down analysis for Intel CPUs",
"config":
[
{
"name": "level",
"description": "Top-down analysis level to compute ('all' or 'top')",
"type": "string",
"value": "top"
}
]
}
)json";

Expand Down
2 changes: 1 addition & 1 deletion src/services/topdown/SapphireRapidsTopdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SapphireRapidsTopdown : public TopdownCalculator

virtual ~SapphireRapidsTopdown() = default;

virtual bool check_for_disabled_multiplex() const override;
virtual bool setup_config(Caliper& c, Channel& channel) const override;

virtual std::vector<Entry> compute_toplevel(const std::vector<Entry>& rec) override;

Expand Down
16 changes: 15 additions & 1 deletion src/services/topdown/SapphireRapidsTopdown_rdpmc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "SapphireRapidsTopdown.h"

#include "../Services.h"

#include "caliper/common/Log.h"
#include "caliper/common/RuntimeConfig.h"

#include <algorithm>

#define RETIRING_OFFSET 0
Expand Down Expand Up @@ -49,8 +54,17 @@ SapphireRapidsTopdown::SapphireRapidsTopdown(IntelTopdownLevel level)
)
{}

bool SapphireRapidsTopdown::check_for_disabled_multiplex() const

bool SapphireRapidsTopdown::setup_config(Caliper& c, Channel& channel) const
{
channel.config().set("CALI_PAPI_COUNTERS", m_level == All ? m_all_counters : m_top_counters);

if (!cali::services::register_service(&c, &channel, "papi")) {
Log(0).stream() << channel.name() << ": topdown: Unable to register papi service, skipping topdown"
<< std::endl;
return false;
}

return true;
}

Expand Down
15 changes: 14 additions & 1 deletion src/services/topdown/SapphireRapidsTopdown_read.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "SapphireRapidsTopdown.h"

#include "../Services.h"

#include "caliper/common/Log.h"
#include "caliper/common/RuntimeConfig.h"

#include <algorithm>

namespace cali
Expand Down Expand Up @@ -46,8 +51,16 @@ SapphireRapidsTopdown::SapphireRapidsTopdown(IntelTopdownLevel level)
)
{}

bool SapphireRapidsTopdown::check_for_disabled_multiplex() const
bool SapphireRapidsTopdown::setup_config(Caliper& c, Channel& channel) const
{
channel.config().set("CALI_PAPI_COUNTERS", m_level == All ? m_all_counters : m_top_counters);

if (!cali::services::register_service(&c, &channel, "papi")) {
Log(0).stream() << channel.name() << ": topdown: Unable to register papi service, skipping topdown"
<< std::endl;
return false;
}

return true;
}

Expand Down
5 changes: 2 additions & 3 deletions src/services/topdown/TopdownCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class TopdownCalculator

virtual ~TopdownCalculator() = default;

// Returns true if PAPI multiplexing cannot be used for the
// counters and/or architecture needed for the subclass
virtual bool check_for_disabled_multiplex() const = 0;
// Setup the hardware counters. Returns "true" if successful.
virtual bool setup_config(Caliper& c, Channel& channel) const = 0;

// Computes the L1 topdown metrics using the counters contained
// in the Caliper Entries.
Expand Down

0 comments on commit 05ce05a

Please sign in to comment.