|
9 | 9 |
|
10 | 10 | #include <Teuchos_UnitTestHarness.hpp>
|
11 | 11 | #include <Teuchos_Array.hpp>
|
| 12 | +#include <Kokkos_Core.hpp> |
12 | 13 |
|
13 | 14 | #include <MueLu_config.hpp>
|
14 | 15 |
|
@@ -64,23 +65,161 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(KokkosTuningInterface, Basic, Scalar, LocalOrd
|
64 | 65 | }
|
65 | 66 |
|
66 | 67 |
|
| 68 | +namespace TestUtilities { |
| 69 | + std::vector<Kokkos::Tools::Experimental::VariableInfo*> output_info; |
| 70 | + std::vector<Kokkos::Tools::Experimental::VariableInfo*> input_info; |
| 71 | + |
| 72 | + const char* str_type(Kokkos_Tools_VariableInfo_ValueType x){ |
| 73 | + if(x == Kokkos_Tools_VariableInfo_ValueType::kokkos_value_double) |
| 74 | + return "double"; |
| 75 | + else if(x == Kokkos_Tools_VariableInfo_ValueType::kokkos_value_int64) |
| 76 | + return "int64"; |
| 77 | + else if(x == Kokkos_Tools_VariableInfo_ValueType::kokkos_value_string) |
| 78 | + return "string"; |
| 79 | + else |
| 80 | + return "unknown"; |
| 81 | + } |
| 82 | + |
| 83 | + const char* str_category(const enum Kokkos_Tools_VariableInfo_StatisticalCategory x){ |
| 84 | + if(x == Kokkos_Tools_VariableInfo_StatisticalCategory::kokkos_value_categorical) |
| 85 | + return "categorical"; |
| 86 | + else if(x == Kokkos_Tools_VariableInfo_StatisticalCategory::kokkos_value_ordinal) |
| 87 | + return "ordinal"; |
| 88 | + else if(x == Kokkos_Tools_VariableInfo_StatisticalCategory::kokkos_value_interval) |
| 89 | + return "interval"; |
| 90 | + else |
| 91 | + return "unknown"; |
| 92 | + } |
| 93 | + |
| 94 | + const char* str_candidatevalue(const enum Kokkos_Tools_VariableInfo_CandidateValueType x){ |
| 95 | + if(x == Kokkos_Tools_VariableInfo_CandidateValueType::kokkos_value_set) |
| 96 | + return "set"; |
| 97 | + else if(x == Kokkos_Tools_VariableInfo_CandidateValueType::kokkos_value_range) |
| 98 | + return "range"; |
| 99 | + else if (x == Kokkos_Tools_VariableInfo_CandidateValueType::kokkos_value_unbounded) |
| 100 | + return "unbounded"; |
| 101 | + else |
| 102 | + return "unknown"; |
| 103 | + } |
| 104 | + |
| 105 | + void declare_input_type(const char* name, const size_t id, |
| 106 | + Kokkos::Tools::Experimental::VariableInfo* info) { |
| 107 | + // Yeah, we're aliasing the pointer. This is a test. Deal. |
| 108 | + input_info.push_back(info); |
| 109 | + } |
| 110 | + |
| 111 | + void declare_output_type(const char* name, const size_t id, |
| 112 | + Kokkos::Tools::Experimental::VariableInfo* info) { |
| 113 | + // Yeah, we're aliasing the pointer. This is a test. Deal. |
| 114 | + output_info.push_back(info); |
| 115 | + } |
| 116 | + |
| 117 | + void request_output_values(const size_t context, const size_t num_inputs, |
| 118 | + const Kokkos::Tools::Experimental::VariableValue* inputs_in, |
| 119 | + const size_t num_outputs, |
| 120 | + Kokkos::Tools::Experimental::VariableValue* outputs_in) { |
| 121 | + // This dummy callback will set the output value to one step more than the bottom guy in the rang |
| 122 | + std::cout<<"\nDEBUG: request_ouput_values called with "<<num_outputs<<" outputs"<<std::endl; |
| 123 | + for(int i=0; i<(int)num_outputs; i++) { |
| 124 | + Kokkos::Tools::Experimental::VariableInfo* info = output_info[i]; |
| 125 | + |
| 126 | + // We only suport ranges in this test |
| 127 | + if (info->category == Kokkos_Tools_VariableInfo_StatisticalCategory::kokkos_value_interval && |
| 128 | + info->valueQuantity == Kokkos_Tools_VariableInfo_CandidateValueType::kokkos_value_range) { |
| 129 | + auto range = info->candidates.range; |
| 130 | + |
| 131 | + if(info->type == Kokkos_Tools_VariableInfo_ValueType::kokkos_value_int64) { |
| 132 | + outputs_in[i].value.int_value = (int) (range.lower.int_value + range.step.int_value); |
| 133 | + std::cout<<"Setting parameter "<<i<<" to value = " <<outputs_in[i].value.int_value<<std::endl; |
| 134 | + } |
| 135 | + else if (info->type == Kokkos_Tools_VariableInfo_ValueType::kokkos_value_double){ |
| 136 | + outputs_in[i].value.double_value = range.lower.double_value + range.step.double_value; |
| 137 | + std::cout<<"Setting parameter "<<i<<" to value = " <<outputs_in[i].value.double_value<<std::endl; |
| 138 | + } |
| 139 | + else { |
| 140 | + std::cout<<"["<<i<<"] Unknown info->type = "<<str_type(info->type)<<std::endl; |
| 141 | + } |
| 142 | + } |
| 143 | + else { |
| 144 | + std::cout<<"["<<i<<"] Not an interval/range = "<<str_type(info->type)<<","<<str_category(info->category)<<","<<str_candidatevalue(info->valueQuantity)<<std::endl; |
| 145 | + } |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | +}//end namespace |
| 153 | + |
| 154 | + |
67 | 155 | TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(KokkosTuningInterface, Advanced, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
|
68 | 156 | #include <MueLu_UseShortNames.hpp>
|
69 | 157 | MUELU_TESTING_SET_OSTREAM;
|
70 | 158 | MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
|
71 | 159 | out << "version: " << MueLu::Version() << std::endl;
|
72 | 160 |
|
73 |
| - RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm(); |
| 161 | + MUELU_TESTING_SET_OSTREAM; |
| 162 | + MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 163 | + out << "version: " << MueLu::Version() << std::endl; |
| 164 | + RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm(); |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + // Driver parameters (like you'd actually use) |
| 169 | + Teuchos::ParameterList baseList; |
| 170 | + Teuchos::ParameterList & pL = baseList.sublist("kokkos tuning: muelu parameter mapping"); |
| 171 | + Teuchos::Array<std::string> input_vars(1); input_vars[0] = "Parameter List Item"; |
| 172 | + Teuchos::Array<int> i_range{1,6,1}; |
| 173 | + Teuchos::Array<double> d_range{5.0,50.0,5.0}; |
| 174 | + pL.set("input variables",input_vars); |
| 175 | + pL.sublist("param0").set("muelu parameter","smoother: params||chebyshev: degree"); |
| 176 | + pL.sublist("param0").set("discrete range",i_range); |
| 177 | + pL.sublist("param0").set("initial guess",(int) 1); |
| 178 | + pL.sublist("param1").set("muelu parameter","smoother: params||chebyshev: ratio eigenvalue"); |
| 179 | + pL.sublist("param1").set("continuous range",d_range); |
| 180 | + pL.sublist("param1").set("initial guess",(double) 5.0); |
| 181 | + |
| 182 | + |
| 183 | + // Set the callbacks |
| 184 | + Kokkos::Tools::Experimental::set_declare_input_type_callback(TestUtilities::declare_input_type); |
| 185 | + Kokkos::Tools::Experimental::set_declare_output_type_callback(TestUtilities::declare_output_type); |
| 186 | + Kokkos::Tools::Experimental::set_request_output_values_callback(TestUtilities::request_output_values); |
| 187 | + |
| 188 | + // Actually make the interface |
| 189 | + MueLu::KokkosTuningInterface interface(comm); |
| 190 | + interface.SetParameterList(baseList); |
| 191 | + |
| 192 | + // Call the tuner |
| 193 | + size_t kokkos_context_id; |
| 194 | + Kokkos::Tools::Experimental::begin_context(kokkos_context_id); |
| 195 | + Teuchos::ParameterList outputList; |
| 196 | + interface.SetMueLuParameters(kokkos_context_id,outputList); |
| 197 | + Kokkos::Tools::Experimental::end_context(kokkos_context_id); |
| 198 | + |
| 199 | + // Check that the output has the varables set to something |
| 200 | + TEST_EQUALITY(outputList.isSublist("smoother: params"),true); |
| 201 | + TEST_EQUALITY(outputList.sublist("smoother: params").isParameter("chebyshev: degree"),true); |
| 202 | + TEST_EQUALITY(outputList.sublist("smoother: params").isParameter("chebyshev: ratio eigenvalue"),true); |
74 | 203 |
|
75 |
| - RCP<MueLu::KokkosTuningInterface> interface = rcp(new MueLu::KokkosTuningInterface(comm)); |
76 | 204 |
|
77 |
| - TEST_INEQUALITY(interface, Teuchos::null); |
| 205 | +#ifdef KOKKOS_ENABLE_TUNING |
| 206 | + // Check that the variables are set to one step off the bottom |
| 207 | + int degree = 2; |
| 208 | + double ratio = 10.0; |
| 209 | +#else |
| 210 | + // Expect the default values |
| 211 | + int degree = 1; |
| 212 | + double ratio = 5.0; |
| 213 | +#endif |
| 214 | + TEST_EQUALITY(outputList.sublist("smoother: params").get<int>("chebyshev: degree"),degree); |
| 215 | + TEST_FLOATING_EQUALITY(outputList.sublist("smoother: params").get<double>("chebyshev: ratio eigenvalue"),ratio,1e-10); |
78 | 216 | }
|
79 | 217 |
|
80 | 218 |
|
81 | 219 | #define MUELU_ETI_GROUP(Scalar, LO, GO, Node) \
|
82 |
| - TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(KokkosTuningInterface, Basic, Scalar, LO, GO, Node) \ |
83 |
| - TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(KokkosTuningInterface, Advanced, Scalar, LO, GO, Node) |
| 220 | + TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(KokkosTuningInterface, Basic, Scalar, LO, GO, Node) |
| 221 | + |
| 222 | + //TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(KokkosTuningInterface, Advanced, Scalar, LO, GO, Node) |
84 | 223 |
|
85 | 224 |
|
86 | 225 | #include <MueLu_ETI_4arg.hpp>
|
|
0 commit comments