Skip to content

Commit

Permalink
Fixing initial values for search strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Sep 25, 2024
1 parent bcede4e commit 8c84988
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,9 @@ if(APEX_WITH_KOKKOS)
if(APEX_BUILD_TESTS)
# Just for testing
SET(Kokkos_LIBRARY kokkoscore)
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE)
if(NOT APPLE)
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE)
endif(NOT APPLE)
set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE)
set(Kokkos_ARCH_NATIVE ON CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_TUNING ON CACHE BOOL "" FORCE)
Expand Down
24 changes: 12 additions & 12 deletions src/apex/apex_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ inline int __sa_setup(shared_ptr<apex_tuning_session>
v.lvalues.push_back(lvalue);
lvalue = lvalue + param_long->step;
} while (lvalue <= param_long->max);
v.set_init();
v.set_init(param_long->init);
tuning_session->sa_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1579,7 +1579,7 @@ inline int __sa_setup(shared_ptr<apex_tuning_session>
v.dvalues.push_back(dvalue);
dvalue = dvalue + param_double->step;
} while (dvalue <= param_double->max);
v.set_init();
v.set_init(param_double->init);
tuning_session->sa_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1591,7 +1591,7 @@ inline int __sa_setup(shared_ptr<apex_tuning_session>
param_enum->possible_values) {
v.svalues.push_back(possible_value);
}
v.set_init();
v.set_init(param_enum->init_value);
tuning_session->sa_session.add_var(param_name, std::move(v));
}
break;
Expand Down Expand Up @@ -1627,7 +1627,7 @@ inline int __nelder_mead_setup(shared_ptr<apex_tuning_session>
v.lvalues.push_back(lvalue);
lvalue = lvalue + param_long->step;
} while (lvalue <= param_long->max);
v.set_init();
v.set_init(param_long->init);
tuning_session->nelder_mead_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1640,7 +1640,7 @@ inline int __nelder_mead_setup(shared_ptr<apex_tuning_session>
v.dvalues.push_back(dvalue);
dvalue = dvalue + param_double->step;
} while (dvalue <= param_double->max);
v.set_init();
v.set_init(param_double->init);
tuning_session->nelder_mead_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1652,7 +1652,7 @@ inline int __nelder_mead_setup(shared_ptr<apex_tuning_session>
param_enum->possible_values) {
v.svalues.push_back(possible_value);
}
v.set_init();
v.set_init(param_enum->init_value);
tuning_session->nelder_mead_session.add_var(param_name, std::move(v));
}
break;
Expand Down Expand Up @@ -1688,7 +1688,7 @@ inline int __genetic_setup(shared_ptr<apex_tuning_session>
v.lvalues.push_back(lvalue);
lvalue = lvalue + param_long->step;
} while (lvalue <= param_long->max);
v.set_init();
v.set_init(param_long->init);
tuning_session->genetic_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1701,7 +1701,7 @@ inline int __genetic_setup(shared_ptr<apex_tuning_session>
v.dvalues.push_back(dvalue);
dvalue = dvalue + param_double->step;
} while (dvalue <= param_double->max);
v.set_init();
v.set_init(param_double->init);
tuning_session->genetic_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1713,7 +1713,7 @@ inline int __genetic_setup(shared_ptr<apex_tuning_session>
param_enum->possible_values) {
v.svalues.push_back(possible_value);
}
v.set_init();
v.set_init(param_enum->init_value);
tuning_session->genetic_session.add_var(param_name, std::move(v));
}
break;
Expand Down Expand Up @@ -1810,7 +1810,7 @@ inline int __random_setup(shared_ptr<apex_tuning_session>
v.lvalues.push_back(lvalue);
lvalue = lvalue + param_long->step;
} while (lvalue <= param_long->max);
v.set_init();
v.set_init(param_long->init);
tuning_session->random_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1823,7 +1823,7 @@ inline int __random_setup(shared_ptr<apex_tuning_session>
v.dvalues.push_back(dvalue);
dvalue = dvalue + param_double->step;
} while (dvalue <= param_double->max);
v.set_init();
v.set_init(param_double->init);
tuning_session->random_session.add_var(param_name, std::move(v));
}
break;
Expand All @@ -1835,7 +1835,7 @@ inline int __random_setup(shared_ptr<apex_tuning_session>
param_enum->possible_values) {
v.svalues.push_back(possible_value);
}
v.set_init();
v.set_init(param_enum->init_value);
tuning_session->random_session.add_var(param_name, std::move(v));
}
break;
Expand Down
17 changes: 13 additions & 4 deletions src/apex/genetic_search.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ class Variable {
return current_index;
}
void save_best() { best_index = current_index; }
void set_init() {
maxlen = (std::max(std::max(dvalues.size(),
lvalues.size()), svalues.size()));
current_index = 0;
void set_init(double init_value) {
auto it = std::find(dvalues.begin(), dvalues.end(), init_value);
current_index = distance(dvalues.begin(), it);
set_current_value();
}
void set_init(long init_value) {
auto it = std::find(lvalues.begin(), lvalues.end(), init_value);
current_index = distance(lvalues.begin(), it);
set_current_value();
}
void set_init(std::string init_value) {
auto it = std::find(svalues.begin(), svalues.end(), init_value);
current_index = distance(svalues.begin(), it);
set_current_value();
}
std::string getBest() {
Expand Down
21 changes: 16 additions & 5 deletions src/apex/nelder_mead.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@ class Variable {
best_index = current_index;
}
}
void set_init() {
maxlen = (std::max(std::max(dvalues.size(),
lvalues.size()), svalues.size()));
current_index = 0;
void set_init(double init_value) {
auto it = std::find(dvalues.begin(), dvalues.end(), init_value);
current_index = distance(dvalues.begin(), it);
set_current_value();
}
void set_init(long init_value) {
auto it = std::find(lvalues.begin(), lvalues.end(), init_value);
current_index = distance(lvalues.begin(), it);
set_current_value();
}
void set_init(std::string init_value) {
auto it = std::find(svalues.begin(), svalues.end(), init_value);
current_index = distance(svalues.begin(), it);
set_current_value();
}
std::string getBest() {
Expand Down Expand Up @@ -100,7 +109,9 @@ class Variable {
}
// otherwise, choose an index somewhere in the middle
//return ((double)maxlen / 2.0);
return 0.5;
//return 0.5;
// otherwise, choose the "index" of the initial value
return (double)(current_value) / (double)(maxlen);
}
const std::vector<double>& get_limits(void) {
limits.reserve(2);
Expand Down
17 changes: 13 additions & 4 deletions src/apex/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ class Variable {
return current_index;
}
void save_best() { best_index = current_index; }
void set_init() {
maxlen = (std::max(std::max(dvalues.size(),
lvalues.size()), svalues.size()));
current_index = 0;
void set_init(double init_value) {
auto it = std::find(dvalues.begin(), dvalues.end(), init_value);
current_index = distance(dvalues.begin(), it);
set_current_value();
}
void set_init(long init_value) {
auto it = std::find(lvalues.begin(), lvalues.end(), init_value);
current_index = distance(lvalues.begin(), it);
set_current_value();
}
void set_init(std::string init_value) {
auto it = std::find(svalues.begin(), svalues.end(), init_value);
current_index = distance(svalues.begin(), it);
set_current_value();
}
std::string getBest() {
Expand Down
19 changes: 11 additions & 8 deletions src/apex/simulated_annealing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,17 @@ class Variable {
void save_best() { best_index = current_index; }
void restore_best() { current_index = best_index; }
/* For initializing in the center of the space */
void set_init() {
maxlen = (std::max(std::max(dvalues.size(),
lvalues.size()), svalues.size())) - 1;
half = maxlen/2;
// we need a minimum value of 2 to get movement at all
quarter = (double)(std::max((half/2), size_t(2)));
current_index = neighbor_index = best_index = half;
//std::cout << "Initialized to " << current_index << std::endl;
void set_init(double init_value) {
auto it = std::find(dvalues.begin(), dvalues.end(), init_value);
current_index = distance(dvalues.begin(), it);
}
void set_init(long init_value) {
auto it = std::find(lvalues.begin(), lvalues.end(), init_value);
current_index = distance(lvalues.begin(), it);
}
void set_init(std::string init_value) {
auto it = std::find(svalues.begin(), svalues.end(), init_value);
current_index = distance(svalues.begin(), it);
}
std::string getBest() {
if (vtype == VariableType::doubletype) {
Expand Down
6 changes: 5 additions & 1 deletion src/unit_tests/Kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ include_directories (${APEX_SOURCE_DIR}/src/unit_tests/Kokkos)
link_directories (${APEX_BINARY_DIR}/src/apex)
#link_directories (${APEX_BINARY_DIR}/src/apex_pthread_wrapper)

if(NOT APPLE)
set(openmp_programs mm2d_tiling)
endif(NOT APPLE)

set(example_programs
simple
two_var
mm2d_tiling
${openmp_programs}
)

foreach(example_program ${example_programs})
Expand Down
2 changes: 0 additions & 2 deletions src/unit_tests/Kokkos/mm2d_tiling.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <tuning_playground.hpp>

#include <omp.h>

#include <chrono>
#include <cmath> // cbrt
#include <cstdlib>
Expand Down

0 comments on commit 8c84988

Please sign in to comment.