Skip to content

Commit 0860a0f

Browse files
committed
MueLu: Getting the finally working version of the KokkosTuning MueLu Driver
Signed-off-by: Chris Siefert <[email protected]>
1 parent 901344c commit 0860a0f

File tree

3 files changed

+38
-50
lines changed

3 files changed

+38
-50
lines changed

packages/muelu/src/Utils/MueLu_KokkosTuningInterface.cpp

+30-43
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ void KokkosTuningInterface::UnpackMueLuMapping() {
8989
const Teuchos::ParameterList& pL = params_.get<Teuchos::ParameterList>("kokkos tuning: muelu parameter mapping");
9090
namespace KTE = Kokkos::Tools::Experimental;
9191

92-
// FIXME: Remove
93-
std::cout<<"*** Params for Kokkos Tuning ***"<<pL<<"********************************"<<std::endl;
94-
9592
/********************************/
9693
/* Process the output variables */
9794
/********************************/
@@ -114,20 +111,16 @@ void KokkosTuningInterface::UnpackMueLuMapping() {
114111
const Teuchos::Array<int> & range = sublist.get<Teuchos::Array<int> >("discrete range");
115112
TEUCHOS_TEST_FOR_EXCEPTION(range.size() !=3, Exceptions::RuntimeError, "MueLu::KokkosTuningInterface: 'discrete range' needs to be (low, high, step)");
116113

117-
// Copy the range to int64_t because Kokkos
118-
std::vector<int64_t> range64(range.size());
119-
for(int j=0;j<(int)range.size(); j++)
120-
range64[j] = range[j];
121-
int64_ranges.push_back(range64);
122-
123-
124114
// Set the VariableInfo
125115
KTE::VariableInfo out_info;
126-
out_info.type = Kokkos::Tools::Experimental::ValueType::kokkos_value_int64;
127-
out_info.category = Kokkos::Tools::Experimental::StatisticalCategory::kokkos_value_ordinal;
128-
out_info.valueQuantity = Kokkos::Tools::Experimental::CandidateValueType::kokkos_value_set;
129-
out_info.candidates = Kokkos::Tools::Experimental::make_candidate_set(3,int64_ranges[int64_ranges.size()-1].data());
130-
size_t var_id = Kokkos::Tools::Experimental::declare_output_type(muelu_param,out_info);
116+
out_info.type = KTE::ValueType::kokkos_value_int64;
117+
out_info.category = KTE::StatisticalCategory::kokkos_value_interval;
118+
out_info.valueQuantity = KTE::CandidateValueType::kokkos_value_range;
119+
120+
// Unlike the ordinal lists, the ranges get copied into Kokkos
121+
// TODO: Add support for open/closed ranges
122+
out_info.candidates = KTE::make_candidate_range((int64_t)range[0],(int64_t)range[1],(int64_t)range[2],false,false);
123+
size_t var_id = KTE::declare_output_type(muelu_param,out_info);
131124
out_variables.push_back(KTE::make_variable_value(var_id,int64_t(guess)));
132125

133126
out_typenames.push_back("int");
@@ -138,32 +131,23 @@ void KokkosTuningInterface::UnpackMueLuMapping() {
138131
const Teuchos::Array<double> & range = sublist.get<Teuchos::Array<double> >("continuous range");
139132
TEUCHOS_TEST_FOR_EXCEPTION(range.size() !=3, Exceptions::RuntimeError, "MueLu::KokkosTuningInterface: 'continuous range' needs to be (low, high, step)");
140133

141-
142-
// Copy the range because Kokkos
143-
std::vector<double> rangeD(range.size());
144-
for(int j=0;j<(int)range.size(); j++)
145-
rangeD[j] = range[j];
146-
double_ranges.push_back(rangeD);
147-
148-
149134
// Set the VariableInfo
150135
KTE::VariableInfo out_info;
151-
out_info.type = Kokkos::Tools::Experimental::ValueType::kokkos_value_double;
152-
out_info.category = Kokkos::Tools::Experimental::StatisticalCategory::kokkos_value_ordinal;
153-
out_info.valueQuantity = Kokkos::Tools::Experimental::CandidateValueType::kokkos_value_set;
154-
// FIXME: This is a memory error waiting to happen
155-
out_info.candidates = Kokkos::Tools::Experimental::make_candidate_set(3,double_ranges[double_ranges.size()-1].data());
156-
size_t var_id = Kokkos::Tools::Experimental::declare_output_type(muelu_param,out_info);
136+
out_info.type = KTE::ValueType::kokkos_value_double;
137+
out_info.category = KTE::StatisticalCategory::kokkos_value_interval;
138+
out_info.valueQuantity = KTE::CandidateValueType::kokkos_value_range;
139+
140+
// Unlike the ordinal lists, the ranges get copied into Kokkos
141+
// TODO: Add support for open/closed ranges
142+
out_info.candidates = KTE::make_candidate_range(range[0],range[1],range[2],false,false);
143+
size_t var_id = KTE::declare_output_type(muelu_param,out_info);
157144
out_variables.push_back(KTE::make_variable_value(var_id,guess));
158145

159146
out_typenames.push_back("double");
160147
}
161-
/*else if(sublist.isType<std::string>("initial guess")) {
162-
// Categorical
163-
164-
}*/
148+
// TODO: Add support for categorical and set parameters
165149
else {
166-
TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::KokkosTuningInterface: Only handles int and double parameters");
150+
TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::KokkosTuningInterface: We currently only handle int and double ranges.");
167151
}
168152

169153
// Stash the parameter name
@@ -183,8 +167,13 @@ void KokkosTuningInterface::UnpackMueLuMapping() {
183167
in_variables.clear();
184168

185169
const Teuchos::Array<std::string> & inputs = pL.get<Teuchos::Array<std::string> >("input variables");
170+
186171
for (int i=0; i< (int)inputs.size(); i++) {
187-
in_variables.push_back(KTE::make_variable_value(i,inputs[i].c_str()));
172+
// NOTE: The string name is copied in here (unlike double/int) so we don't need to cache.
173+
KTE::VariableInfo in_info;
174+
in_info.type = KTE::ValueType::kokkos_value_string;
175+
size_t var_id = KTE::declare_input_type(inputs[i].c_str(),in_info);
176+
in_variables.push_back(KTE::make_variable_value(var_id,inputs[i].c_str()));
188177
}
189178

190179

@@ -219,6 +208,12 @@ void KokkosTuningInterface::SetMueLuParameters(size_t kokkos_context_id, Teuchos
219208
// Only Rank 0 calls KokkosTuning
220209
GetOStream(Runtime0) << "MueLu::KokkosTuningInterface: Tuning " << out_variables.size() << " parameters" <<std::endl;
221210

211+
// Set input variable
212+
if (IsPrint(Runtime1))
213+
GetOStream(Runtime1) <<"Adding "<<in_variables.size()<<" input variables"<<std::endl;
214+
215+
KTE::set_input_values(kokkos_context_id, in_variables.size(), in_variables.data());
216+
222217
// Start the tuning
223218
KTE::request_output_values(kokkos_context_id, out_variables.size(), out_variables.data());
224219

@@ -241,8 +236,6 @@ void KokkosTuningInterface::SetMueLuParameters(size_t kokkos_context_id, Teuchos
241236
Teuchos::ParameterList *activeList = &tunedParams;
242237
std::vector<std::string> treeWalk = SplitString(out_names[i],"||");
243238

244-
for(int j=0; j<(int) treeWalk.size(); j++)
245-
246239
// Walk down all but the last guy
247240
for(int j=0;j<(int) treeWalk.size()-1; j++) {
248241
activeList = &(activeList->sublist(treeWalk[j]));
@@ -259,14 +252,8 @@ void KokkosTuningInterface::SetMueLuParameters(size_t kokkos_context_id, Teuchos
259252
}
260253
}
261254
}
262-
#if 0
263-
std::cout<<"*** FINAL TUNED PARAMS ***"<<std::endl;
264-
std::cout<<tunedParams<<std::endl;
265-
std::cout<<"*************************"<<std::endl;
266-
#endif
267255

268256
Teuchos::updateParametersAndBroadcast(outArg(tunedParams), outArg(mueluParams), *comm_, 0, overwrite);
269-
270257
}
271258

272259

packages/muelu/src/Utils/MueLu_KokkosTuningInterface.hpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,11 @@ class KokkosTuningInterface : public BaseClass {
6363

6464

6565
// Tuning information
66-
std::vector<Kokkos::Tools::Experimental::VariableValue> in_variables;
66+
mutable std::vector<Kokkos::Tools::Experimental::VariableValue> in_variables;
6767
mutable std::vector<Kokkos::Tools::Experimental::VariableValue> out_variables;
6868
std::vector<std::string> out_names;
6969
std::vector<std::string> out_typenames;
7070

71-
// FIXME: Dealing with Kokkos grabbing the pointer
72-
std::vector<std::vector<int64_t> > int64_ranges;
73-
std::vector<std::vector<double> > double_ranges;
74-
7571

7672
};
7773

packages/muelu/test/scaling/Driver.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include <Xpetra_MultiVector.hpp>
3131
#include <Xpetra_IO.hpp>
3232

33+
// Tpetra
34+
#include <Tpetra_Details_Profiling.hpp>
35+
3336
// Galeri
3437
#include <Galeri_XpetraParameters.hpp>
3538
#include <Galeri_XpetraProblemFactory.hpp>
@@ -292,7 +295,7 @@ int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib& lib, int ar
292295

293296
bool kokkosTuning = false;
294297
#ifdef KOKKOS_ENABLE_TUNING
295-
clp.setOption("kokkos-tuning", "no-kokkos-tuning", &kokkosTuning, "enable Kokkos tuning inferface");
298+
clp.setOption("tuning-with-kokkos", "no-tuning-with-kokkos", &kokkosTuning, "enable Kokkos tuning inferface");
296299
#else
297300
#error "KokkosTuning not enabled"
298301
#endif
@@ -541,14 +544,16 @@ int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib& lib, int ar
541544
// Get a Kokkos context for tuning and setup the tuner
542545
size_t kokkos_context_id = 0;
543546
if(kokkosTuning) {
544-
kokkos_context_id = Kokkos::Tools::Experimental::get_new_context_id();
545547
KokkosTuner.SetParameterList(mueluList);
546548
}
547549

548550
// =========================================================================
549551
// Loop over the setup/solve pairs
550552
// =========================================================================
551553
for(int l=0; l<numLoops; l++) {
554+
#ifdef HAVE_MUELU_TPETRA
555+
Tpetra::Details::ProfilingRegion("MueLu Setup/Solve");
556+
#endif
552557

553558
// Use Kokkos tuning, if requested
554559
if(kokkosTuning) {

0 commit comments

Comments
 (0)