Skip to content

Commit f6a48f8

Browse files
authored
Implement LET clause for ConfigManager options (LLNL#282)
* Add LET first() operator * Remove ConfigManager 'serial' query level * Implement LET clause for ConfigManager options * Update mem.highwatermark option * Update add_option_spec() doc * Add test for mem.highwatermark option
1 parent 217ce8a commit f6a48f8

11 files changed

+256
-124
lines changed

include/caliper/ConfigManager.h

+13-8
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ConfigManager
111111

112112
/// \brief Returns a CalQL SELECT expression to compute metrics
113113
/// in the option list.
114-
/// \param level The aggregation level ('serial', 'local', or 'cross')
114+
/// \param level The aggregation level ('local' or 'cross')
115115
/// \param in Base SELECT expression as required by the controller
116116
/// \param use_alias Wether to add aliases to the expression
117117
/// (as in SELECT x AS y)
@@ -122,13 +122,22 @@ class ConfigManager
122122

123123
/// \brief Returns a CalQL GROUP BY list for metrics in the option
124124
/// list.
125-
/// \param level The aggregation level ('serial', 'local', or 'cross')
125+
/// \param level The aggregation level ('local' or 'cross')
126126
/// \param in Base GROUP BY list as required by the controller
127127
/// \return The GROUP BY list (comma-separated string), but without the
128128
/// 'GROUP BY' keyword
129129
std::string
130130
query_groupby(const char* level, const std::string& in) const;
131131

132+
/// \brief Returns a CalQL LET list for metrics in the option
133+
/// list.
134+
/// \param level The aggregation level ('local' or 'cross')
135+
/// \param in Base LET list as required by the controller
136+
/// \return The LET clause ('LET' + comma-separated list of definitions),
137+
/// or an empty string if there is no LET input
138+
std::string
139+
query_let(const char* level, const std::string& in) const;
140+
132141
friend class ConfigManager;
133142
};
134143

@@ -275,9 +284,6 @@ class ConfigManager
275284
/// " \"config\" : { \"CALI_PAPI_COUNTERS\": \"PAPI_TOT_INS\" },"
276285
/// " \"query_args\" : "
277286
/// " ["
278-
/// " { \"level\": \"serial\", \"select\":"
279-
/// " [ { \"expr\": \"sum(sum#papi.PAPI_TOT_INS)\", \"as\": \"Instructions\" } ]"
280-
/// " },"
281287
/// " { \"level\": \"local\", \"select\":"
282288
/// " [ { \"expr\": \"sum(sum#papi.PAPI_TOT_INS)\" } ]"
283289
/// " },"
@@ -316,9 +322,8 @@ class ConfigManager
316322
/// added automatically based on the \a services entry.
317323
/// \li \a query_args: Defines aggregation operations to compute
318324
/// performance metrics. Specific to "metric" options. There are
319-
/// three aggregation levels: \e serial computes metrics for
320-
/// non-MPI programs, \e local computes process-local intermediate
321-
/// metrics in MPI programs, and \e cross computes cross-process
325+
/// two aggregation levels: \e local computes process-local
326+
/// metrics, and \e cross computes cross-process
322327
/// metrics in MPI programs. For each level, specify metrics
323328
/// using a list of "select" definitions, where \e expr defines an
324329
/// aggregation using a CalQL expression, and \e as provides a

src/caliper/ConfigManager.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ class ConfigManager::OptionSpec
132132
{
133133
struct query_arg_t {
134134
std::vector< std::pair<std::string, std::string> > select;
135-
std::vector< std::string> groupby;
135+
std::vector< std::string > groupby;
136+
std::vector< std::string > let;
136137
};
137138

138139
struct option_spec_t {
@@ -173,6 +174,10 @@ class ConfigManager::OptionSpec
173174
if (it != dict.end())
174175
qarg.groupby = ::to_stringlist(it->second.rec_list());
175176

177+
it = dict.find("let");
178+
if (it != dict.end())
179+
qarg.let = ::to_stringlist(it->second.rec_list());
180+
176181
it = dict.find("select");
177182
if (it != dict.end())
178183
parse_select(it->second.rec_list(), qarg);
@@ -477,6 +482,32 @@ struct ConfigManager::Options::OptionsImpl
477482
return ret;
478483
}
479484

485+
std::string
486+
query_let(const std::string& level, const std::string& in) const {
487+
std::string ret = in;
488+
489+
for (const std::string& opt : enabled_options) {
490+
auto s_it = spec.data.find(opt); // find option description
491+
if (s_it == spec.data.end())
492+
continue;
493+
494+
auto l_it = s_it->second.query_args.find(level); // find query level
495+
if (l_it == s_it->second.query_args.end())
496+
continue;
497+
498+
for (const auto &s : l_it->second.let) {
499+
if (!ret.empty())
500+
ret.append(",");
501+
ret.append(s);
502+
}
503+
}
504+
505+
if (!ret.empty())
506+
ret = std::string(" let ") + ret;
507+
508+
return ret;
509+
}
510+
480511
std::vector<std::string>
481512
get_inherited_specs(const std::string& name) {
482513
std::vector<std::string> ret;
@@ -626,6 +657,11 @@ ConfigManager::Options::query_groupby(const char* level, const std::string& in)
626657
return mP->query_groupby(level, in);
627658
}
628659

660+
std::string
661+
ConfigManager::Options::query_let(const char* level, const std::string& in) const
662+
{
663+
return mP->query_let(level, in);
664+
}
629665

630666
//
631667
// --- ConfigManager

src/caliper/controllers/CudaActivityController.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ class CudaActivityController : public cali::ChannelController
4747
config()["CALI_MPIREPORT_FILENAME"] = opts.get("output", "stderr").to_string();
4848
config()["CALI_MPIREPORT_WRITE_ON_FINALIZE"] = "false";
4949
config()["CALI_MPIREPORT_LOCAL_CONFIG"] =
50-
std::string("select ")
50+
opts.query_let("local", "")
51+
+ " select "
5152
+ opts.query_select("local", local_select)
5253
+ " group by "
5354
+ opts.query_groupby("local", "prop:nested");
5455
config()["CALI_MPIREPORT_CONFIG" ] =
55-
std::string("select ")
56+
opts.query_let("cross", "")
57+
+ " select "
5658
+ opts.query_select("cross", cross_select)
5759
+ " group by "
5860
+ opts.query_groupby("cross", "prop:nested")
@@ -61,10 +63,11 @@ class CudaActivityController : public cali::ChannelController
6163
config()["CALI_SERVICES_ENABLE" ].append(",report");
6264
config()["CALI_REPORT_FILENAME" ] = opts.get("output", "stderr").to_string();
6365
config()["CALI_REPORT_CONFIG" ] =
64-
std::string("select ")
65-
+ opts.query_select("serial", serial_select)
66+
opts.query_let("local", "")
67+
+ " select "
68+
+ opts.query_select("local", serial_select)
6669
+ " group by "
67-
+ opts.query_groupby("serial", "prop:nested")
70+
+ opts.query_groupby("local", "prop:nested")
6871
+ " format tree";
6972
}
7073

src/caliper/controllers/HatchetRegionProfileController.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class HatchetRegionProfileController : public cali::ChannelController
5757
config()["CALI_MPIREPORT_FILENAME"] = output;
5858
config()["CALI_MPIREPORT_WRITE_ON_FINALIZE"] = "false";
5959
config()["CALI_MPIREPORT_CONFIG" ] =
60-
std::string("select ")
60+
opts.query_let("local", "")
61+
+ " select "
6162
+ opts.query_select("local", "*,sum(sum#time.duration) as time")
6263
+ " group by "
6364
+ opts.query_groupby("local", "prop:nested,mpi.rank")
@@ -66,10 +67,11 @@ class HatchetRegionProfileController : public cali::ChannelController
6667
config()["CALI_SERVICES_ENABLE" ].append(",report");
6768
config()["CALI_REPORT_FILENAME" ] = output;
6869
config()["CALI_REPORT_CONFIG" ] =
69-
std::string("select ")
70-
+ opts.query_select("serial", "*,sum(sum#time.duration) as time")
70+
opts.query_let("local", "")
71+
+ " select "
72+
+ opts.query_select("local", "*,sum(sum#time.duration) as time")
7173
+ " group by "
72-
+ opts.query_groupby("serial", "prop:nested")
74+
+ opts.query_groupby("local", "prop:nested")
7375
+ " format " + format;
7476
}
7577

src/caliper/controllers/HatchetSampleProfileController.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class HatchetSampleProfileController : public cali::ChannelController
6363
config()["CALI_MPIREPORT_FILENAME"] = output;
6464
config()["CALI_MPIREPORT_WRITE_ON_FINALIZE"] = "false";
6565
config()["CALI_MPIREPORT_CONFIG" ] =
66-
std::string("select ")
66+
opts.query_let("local", "")
67+
+ " select "
6768
+ opts.query_select("local", "*,count()")
6869
+ " group by "
6970
+ opts.query_groupby("local", "prop:nested,mpi.rank")
@@ -72,7 +73,8 @@ class HatchetSampleProfileController : public cali::ChannelController
7273
config()["CALI_SERVICES_ENABLE" ].append(",report");
7374
config()["CALI_REPORT_FILENAME" ] = output;
7475
config()["CALI_REPORT_CONFIG" ] =
75-
std::string("select ")
76+
opts.query_let("local", "")
77+
+ " select "
7678
+ opts.query_select("local", "*,count()")
7779
+ " group by "
7880
+ opts.query_groupby("local", "prop:nested")

src/caliper/controllers/RuntimeReportController.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ class RuntimeReportController : public cali::ChannelController
6363
config()["CALI_MPIREPORT_FILENAME"] = opts.get("output", "stderr").to_string();
6464
config()["CALI_MPIREPORT_WRITE_ON_FINALIZE"] = "false";
6565
config()["CALI_MPIREPORT_LOCAL_CONFIG"] =
66-
std::string("select ")
66+
opts.query_let("local", "")
67+
+ " select "
6768
+ opts.query_select("local", local_select)
6869
+ " group by "
6970
+ opts.query_groupby("local", "prop:nested");
7071
config()["CALI_MPIREPORT_CONFIG" ] =
71-
std::string("select ")
72+
opts.query_let("cross", "")
73+
+ " select "
7274
+ opts.query_select("cross", cross_select)
7375
+ " group by "
7476
+ opts.query_groupby("cross", "prop:nested")
@@ -78,10 +80,11 @@ class RuntimeReportController : public cali::ChannelController
7880
config()["CALI_SERVICES_ENABLE" ].append(",report");
7981
config()["CALI_REPORT_FILENAME" ] = opts.get("output", "stderr").to_string();
8082
config()["CALI_REPORT_CONFIG" ] =
81-
std::string("select ")
82-
+ opts.query_select("serial", serial_select)
83+
opts.query_let("local", "")
84+
+ " select "
85+
+ opts.query_select("local", serial_select)
8386
+ " group by "
84-
+ opts.query_groupby("serial", "prop:nested")
87+
+ opts.query_groupby("local", "prop:nested")
8588
+ " format tree"
8689
+ formatarg;
8790
}

0 commit comments

Comments
 (0)