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 160ef10
Show file tree
Hide file tree
Showing 72 changed files with 1,784 additions and 3,323 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
2 changes: 0 additions & 2 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ 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 \
cconfigspace/tree.h \
cconfigspace/tree_space.h \
Expand Down
2 changes: 0 additions & 2 deletions include/cconfigspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#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"
#include "cconfigspace/tree.h"
#include "cconfigspace/tree_space.h"
Expand Down
36 changes: 10 additions & 26 deletions include/cconfigspace/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,10 @@ 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.
*/
typedef struct _ccs_tuner_s *ccs_tuner_t;
/**
* An opaque type defining a CCS features tuner.
*/
typedef struct _ccs_features_tuner_s *ccs_features_tuner_t;
/**
* An opaque type defining a CCS key-value store.
*/
Expand Down Expand Up @@ -225,28 +217,26 @@ enum ccs_result_e {
CCS_RESULT_ERROR_INVALID_EVALUATION = -19,
/** The provided features is invalid */
CCS_RESULT_ERROR_INVALID_FEATURES = -20,
/** The provided features tuner is invalid */
CCS_RESULT_ERROR_INVALID_FEATURES_TUNER = -21,
/** The provided file path is invalid */
CCS_RESULT_ERROR_INVALID_FILE_PATH = -22,
CCS_RESULT_ERROR_INVALID_FILE_PATH = -21,
/** The provided buffer or file is too short */
CCS_RESULT_ERROR_NOT_ENOUGH_DATA = -23,
CCS_RESULT_ERROR_NOT_ENOUGH_DATA = -22,
/** The handle was a duplicate */
CCS_RESULT_ERROR_DUPLICATE_HANDLE = -24,
CCS_RESULT_ERROR_DUPLICATE_HANDLE = -23,
/** The handle was not found */
CCS_RESULT_ERROR_INVALID_HANDLE = -25,
CCS_RESULT_ERROR_INVALID_HANDLE = -24,
/** A system error occurred */
CCS_RESULT_ERROR_SYSTEM = -26,
CCS_RESULT_ERROR_SYSTEM = -25,
/** External error occurred (binding?) */
CCS_RESULT_ERROR_EXTERNAL = -27,
CCS_RESULT_ERROR_EXTERNAL = -26,
/** The provided tree is invalid */
CCS_RESULT_ERROR_INVALID_TREE = -28,
CCS_RESULT_ERROR_INVALID_TREE = -27,
/** The provided tree space is invalid */
CCS_RESULT_ERROR_INVALID_TREE_SPACE = -29,
CCS_RESULT_ERROR_INVALID_TREE_SPACE = -28,
/** The provided tree tuner is invalid */
CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE = -30,
CCS_RESULT_ERROR_INVALID_DISTRIBUTION_SPACE = -29,
/** Guard */
CCS_RESULT_MIN = -31,
CCS_RESULT_MIN = -30,
/** Try forcing 32 bits value for bindings */
CCS_RESULT_FORCE_32BIT = INT32_MAX
};
Expand Down Expand Up @@ -287,10 +277,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 */
CCS_OBJECT_TYPE_MAP,
/** An error stack */
Expand All @@ -301,8 +287,6 @@ enum ccs_object_type_e {
CCS_OBJECT_TYPE_TREE_SPACE,
/** A configuration on a tree space */
CCS_OBJECT_TYPE_TREE_CONFIGURATION,
/** A tree tuner */
CCS_OBJECT_TYPE_TREE_TUNER,
/** A distribution space */
CCS_OBJECT_TYPE_DISTRIBUTION_SPACE,
/** Guard */
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
Loading

0 comments on commit 160ef10

Please sign in to comment.