Skip to content

Commit

Permalink
WIP: feature spaces are part of configuration spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed May 17, 2024
1 parent 79a6622 commit dfbeb0d
Show file tree
Hide file tree
Showing 66 changed files with 1,484 additions and 1,346 deletions.
50 changes: 21 additions & 29 deletions connectors/kokkos/ccs-kokkos-connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,7 @@ extract_value(

static std::map<
size_t,
std::tuple<
struct timespec,
ccs_features_tuner_t,
ccs_features_t,
ccs_configuration_t,
bool> >
std::tuple<struct timespec, ccs_features_tuner_t, ccs_configuration_t, bool> >
contexts;
static int regionCounter = 0;

Expand Down Expand Up @@ -509,13 +504,23 @@ kokkosp_request_values(
ccs_expression_t expression;
ccs_objective_type_t otype;

cs_parameters = new ccs_parameter_t[numContextVariables];
for (size_t i = 0; i < numContextVariables; i++)
cs_parameters[i] = parameters[contextValues[i].type_id];

CCS_CHECK(ccs_create_feature_space(
("fs (region: " + std::to_string(regionCounter) + ")").c_str(),
numContextVariables, cs_parameters, &fs));
delete[] cs_parameters;

cs_parameters = new ccs_parameter_t[numTuningVariables];
for (size_t i = 0; i < numTuningVariables; i++)
cs_parameters[i] = parameters[tuningValues[i].type_id];

CCS_CHECK(ccs_create_configuration_space(
("cs (region: " + std::to_string(regionCounter) + ")").c_str(),
numTuningVariables, cs_parameters, NULL, 0, NULL, NULL, &cs));
numTuningVariables, cs_parameters, NULL, 0, NULL, fs, NULL,
&cs));
delete[] cs_parameters;

#if CCS_DEBUG
Expand All @@ -525,15 +530,6 @@ kokkosp_request_values(
}
#endif

cs_parameters = new ccs_parameter_t[numContextVariables];
for (size_t i = 0; i < numContextVariables; i++)
cs_parameters[i] = parameters[contextValues[i].type_id];

CCS_CHECK(ccs_create_feature_space(
("fs (region: " + std::to_string(regionCounter) + ")").c_str(),
numContextVariables, cs_parameters, &fs));
delete[] cs_parameters;

ccs_int_t lower = 0;
ccs_int_t upper = CCS_INT_MAX;
ccs_int_t step = 0;
Expand All @@ -553,7 +549,7 @@ kokkosp_request_values(
("random tuner (region: " + std::to_string(regionCounter) +
")")
.c_str(),
fs, os, &tuner));
os, &tuner));
CCS_CHECK(ccs_release_object(cs));
CCS_CHECK(ccs_release_object(fs));
CCS_CHECK(ccs_release_object(os));
Expand Down Expand Up @@ -602,7 +598,7 @@ kokkosp_request_values(
else
CCS_CHECK(ccs_features_tuner_suggest(
tuner, feat, (ccs_search_configuration_t *)&configuration));

CCS_CHECK(ccs_release_object(feat));
CCS_CHECK(ccs_features_tuner_get_search_space(
tuner, (ccs_search_space_t *)&configuration_space));
{
Expand All @@ -628,8 +624,7 @@ kokkosp_request_values(
#endif

clock_gettime(CLOCK_MONOTONIC, &start);
contexts[contextId] =
std::make_tuple(start, tuner, feat, configuration, converged);
contexts[contextId] = std::make_tuple(start, tuner, configuration, converged);
}

extern "C" void
Expand All @@ -643,7 +638,6 @@ kokkosp_end_context(size_t contextId)
{
struct timespec start, stop;
ccs_features_tuner_t tuner;
ccs_features_t feat;
ccs_configuration_t configuration;
ccs_objective_space_t objective_space;
bool converged;
Expand All @@ -666,15 +660,14 @@ kokkosp_end_context(size_t contextId)
auto context = ctx->second;
start = std::get<0>(context);
tuner = std::get<1>(context);
feat = std::get<2>(context);
configuration = std::get<3>(context);
converged = std::get<4>(context);
configuration = std::get<2>(context);
converged = std::get<3>(context);
contexts.erase(contextId);

if (!converged) { // do not report if not fencing and already converged.
ccs_features_evaluation_t evaluation;
ccs_evaluation_t evaluation;
// elapsed time in nanosecond
ccs_datum_t elapsed = ccs_int(
ccs_datum_t elapsed = ccs_int(
((ccs_int_t)(stop.tv_sec) - (ccs_int_t)(start.tv_sec)) *
1000000000 +
(ccs_int_t)(stop.tv_nsec) - (ccs_int_t)(start.tv_nsec));
Expand All @@ -683,15 +676,14 @@ kokkosp_end_context(size_t contextId)

CCS_CHECK(ccs_features_tuner_get_objective_space(
tuner, &objective_space));
CCS_CHECK(ccs_create_features_evaluation(
CCS_CHECK(ccs_create_evaluation(
objective_space, (ccs_search_configuration_t)configuration,
feat, CCS_RESULT_SUCCESS, 1, &elapsed, &evaluation));
CCS_RESULT_SUCCESS, 1, &elapsed, &evaluation));

CCS_CHECK(ccs_features_tuner_tell(tuner, 1, &evaluation));
CCS_CHECK(ccs_release_object(evaluation));
}

CCS_CHECK(ccs_release_object(feat));
CCS_CHECK(ccs_release_object(configuration));

#if CCS_PROFILE
Expand Down
1 change: 0 additions & 1 deletion include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ include_ccs_HEADERS = \
cconfigspace/features.h \
cconfigspace/objective_space.h \
cconfigspace/evaluation.h \
cconfigspace/features_evaluation.h \
cconfigspace/tuner.h \
cconfigspace/features_tuner.h \
cconfigspace/map.h \
Expand Down
1 change: 0 additions & 1 deletion include/cconfigspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "cconfigspace/features.h"
#include "cconfigspace/objective_space.h"
#include "cconfigspace/evaluation.h"
#include "cconfigspace/features_evaluation.h"
#include "cconfigspace/tuner.h"
#include "cconfigspace/features_tuner.h"
#include "cconfigspace/map.h"
Expand Down
6 changes: 0 additions & 6 deletions include/cconfigspace/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ typedef struct _ccs_objective_space_s *ccs_objective_space_t;
* An opaque type defining a CCS evaluation.
*/
typedef struct _ccs_evaluation_s *ccs_evaluation_t;
/**
* An opaque type defining a CCS features evaluation.
*/
typedef struct _ccs_features_evaluation_s *ccs_features_evaluation_t;
/**
* An opaque type defining a CCS tuner.
*/
Expand Down Expand Up @@ -287,8 +283,6 @@ enum ccs_object_type_e {
CCS_OBJECT_TYPE_FEATURE_SPACE,
/** A set of features */
CCS_OBJECT_TYPE_FEATURES,
/** An evaluation of a configuration given specific features */
CCS_OBJECT_TYPE_FEATURES_EVALUATION,
/** A features aware tuner */
CCS_OBJECT_TYPE_FEATURES_TUNER,
/** A key value store */
Expand Down
27 changes: 26 additions & 1 deletion include/cconfigspace/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ extern "C" {
* Create a new instance of a configuration on a given configuration space. If
* no values are provided the values will be initialized to #CCS_DATA_TYPE_NONE.
* @param[in] configuration_space
* @param[in] features an optional features to use. If NULL and a feature space
* was provided at \p configuration_space creation, the
* deafult features of the feature space will be used.
* @param[in] num_values the number of provided values to initialize the
* configuration
* @param[in] values an optional array of values to initialize the configuration
* @param[out] configuration_ret a pointer to the variable that will hold the
* newly created configuration
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a
* valid CCS configuration space
* valid CCS configuration space; or if \p features is not NULL and is not a
* valid CCS features
* @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not
* the same as the feature space provided at \p configuration_space creation.
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configuration_ret is NULL; or
* if \p values is NULL and \p num_values is greater than 0; or if the number of
* values provided is not equal to the number of parameters in the configuration
Expand All @@ -36,6 +42,7 @@ extern "C" {
extern ccs_result_t
ccs_create_configuration(
ccs_configuration_space_t configuration_space,
ccs_features_t features,
size_t num_values,
ccs_datum_t *values,
ccs_configuration_t *configuration_ret);
Expand All @@ -57,6 +64,24 @@ ccs_configuration_get_configuration_space(
ccs_configuration_t configuration,
ccs_configuration_space_t *configuration_space_ret);

/**
* Get the associated features.
* @param[in] configuration
* @param[out] features_ret a pointer to the variable that will contain the
* returned features or NULL if none is associated
* to the configuration.
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration is not a valid
* CCS configuration
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p features_ret is NULL
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_get_feature(
ccs_configuration_t configuration,
ccs_features_t *features_ret);

/**
* Check that the configuration is a valid configuration for the configuration
* space.
Expand Down
62 changes: 52 additions & 10 deletions include/cconfigspace/configuration_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ extern "C" {
/**
* @file configuration_space.h
* A configuration space is a context (see context.h) defining a search
* space on a set of parameters. Configuration space also offer as
* constraints system to describe conditional parameter activation as
* well as forbidden parameter configurations.
* space on a set of parameters. Optionally configuration space can be
* attached a feature space (see feature_space.h). Configuration space
* also offer as constraints system to describe conditional parameter
* activation as well as forbidden parameter configurations.
*/

/**
Expand All @@ -27,6 +28,7 @@ extern "C" {
* @param[in] forbidden_clauses an array o \p num_forbidden_clauses expressions
* to add as forbidden clauses to the
* configuration space
* @param[in] feature_space an optional CCS feature space object
* @param[in] rng an optional CCS rng object
* @param[out] configuration_space_ret a pointer to the variable that will hold
* the newly created configuration space
Expand All @@ -36,15 +38,16 @@ extern "C" {
* num_parameters is NULL; or if \p forbidden_clauses is NULL and \p
* num_forbidden_clauses is greater than 0
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if a parameter is not a valid CCS
* parameter; or if an expression is not a valid CCS expression; or if \p
* rng is not NULL and is not a valid CCS rng
* parameter; or if an expression is not a valid CCS expression; or if \p rng
* is not NULL and is not a valid CCS rng; or it \p feature_space is not NULL
* and is not a valid CCS feature space
* @return #CCS_RESULT_ERROR_INVALID_PARAMETER if a parameter's type is
* CCS_PARAMETER_TYPE_STRING; or if a parameter appears more than once in \p
* parameters; or if two or more parameters share the same name; or if a
* paramater is already part of another context; or if an expression references
* a parameter that is not in the configuration space
* @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding one of the provided
* forbidden clause would render the default configuration invalid
* @return #CCS_RESULT_ERROR_INVALID_CONFIGURATION if adding one of the
* provided forbidden clause would render the default configuration invalid
* @return #CCS_RESULT_ERROR_INVALID_GRAPH if the addition of the conditions
* would cause the dependency graph to become invalid (cyclic)
* @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was a lack of memory to
Expand All @@ -60,6 +63,7 @@ ccs_create_configuration_space(
ccs_expression_t *conditions,
size_t num_forbidden_clauses,
ccs_expression_t *forbidden_clauses,
ccs_feature_space_t feature_space,
ccs_rng_t rng,
ccs_configuration_space_t *configuration_space_ret);

Expand All @@ -79,6 +83,23 @@ ccs_configuration_space_get_rng(
ccs_configuration_space_t configuration_space,
ccs_rng_t *rng_ret);

/**
* Get the feature space of the configuration space.
* @param[in] configuration_space
* @param[out] feature_space_ret a pointer to the variable that will contain
* the feature space
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a
* valid CCS configuration space
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p feature_space_ret is NULL
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_space_get_feature_space(
ccs_configuration_space_t configuration_space,
ccs_feature_space_t *feature_space_ret);

/**
* Get the active condition of a parameter in a configuration space given
* it's index.
Expand Down Expand Up @@ -213,11 +234,18 @@ ccs_configuration_space_check_configuration(
/**
* Get the default configuration of a configuration space
* @param[in] configuration_space
* @param[in] features an optional features to use. If NULL and a feature space
* was provided at \p configuration_space creation, the
* deafult features of the feature space will be used.
* @param[in] rng an optional rng to use
* @param[out] configuration_ret a pointer to the variable that will contain the
* returned default configuration
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a
* valid CCS configuration space
* valid CCS configuration space; or if \p features is not NULL and is not a
* valid CCS features
* @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not
* the same as the feature space provided at \p configuration_space creation.
* @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL
* @return #CCS_RESULT_ERROR_OUT_OF_MEMORY if there was not enough memory to
* allocate the new configuration
Expand All @@ -227,6 +255,7 @@ ccs_configuration_space_check_configuration(
extern ccs_result_t
ccs_configuration_space_get_default_configuration(
ccs_configuration_space_t configuration_space,
ccs_features_t features,
ccs_configuration_t *configuration_ret);

/**
Expand All @@ -236,13 +265,19 @@ ccs_configuration_space_get_default_configuration(
* will have the #ccs_inactive value. Returned configuration is valid.
* @param[in] configuration_space
* @param[in] distribution_space an optional distribution space to use
* @param[in] features an optional features to use. If NULL and a feature space
* was provided at \p configuration_space creation, the
* deafult features of the feature space will be used.
* @param[in] rng an optional rng to use
* @param[out] configuration_ret a pointer to the variable that will contain the
* returned configuration
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a
* valid CCS configuration space; or if \p distribution_space is not a valid
* CCS distribution space; or if \p rng is not a valid CCS rng
* CCS distribution space; or if \p rng is not NULL and is not a valid CCS rng;
* or if \p features is not NULL and is not a valid CCS features
* @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not
* the same as the feature space provided at \p configuration_space creation.
* @return #CCS_RESULT_ERROR_INVALID_VALUE if configuration_ret is NULL
* @return #CCS_RESULT_ERROR_SAMPLING_UNSUCCESSFUL if no valid configuration
* could be sampled
Expand All @@ -255,6 +290,7 @@ extern ccs_result_t
ccs_configuration_space_sample(
ccs_configuration_space_t configuration_space,
ccs_distribution_space_t distribution_space,
ccs_features_t features,
ccs_rng_t rng,
ccs_configuration_t *configuration_ret);

Expand All @@ -266,14 +302,19 @@ ccs_configuration_space_sample(
* valid.
* @param[in] configuration_space
* @param[in] distribution_space an optional distribution space to use
* @param[in] features an optional features to use. Required if a feature space
* was provided at \p configuration_space creation.
* @param[in] rng an optional rng to use
* @param[in] num_configurations the number of requested configurations
* @param[out] configurations an array of \p num_configurations that will
* contain the requested configurations
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration_space is not a
* valid CCS configuration space; or if \p distribution_space is not a valid
* CCS distribution space; or if \p rng is not a valid CCS rng
* CCS distribution space; or if \p rng is not NULL and is not a valid CCS rng;
* or if \p features is not NULL and is not a valid CCS features
* @return #CCS_RESULT_ERROR_INVALID_FEATURES if features feature space is not
* the same as the feature space provided at \p configuration_space creation.
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p configurations is NULL and \p
* num_configurations is greater than 0
* @return #CCS_RESULT_ERROR_SAMPLING_UNSUCCESSFUL if no or not enough valid
Expand All @@ -289,6 +330,7 @@ extern ccs_result_t
ccs_configuration_space_samples(
ccs_configuration_space_t configuration_space,
ccs_distribution_space_t distribution_space,
ccs_features_t features,
ccs_rng_t rng,
size_t num_configurations,
ccs_configuration_t *configurations);
Expand Down
Loading

0 comments on commit dfbeb0d

Please sign in to comment.