Skip to content

Commit

Permalink
Remove duplicated functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed Mar 22, 2024
1 parent 40ad86c commit cfa3a22
Show file tree
Hide file tree
Showing 45 changed files with 389 additions and 2,178 deletions.
4 changes: 2 additions & 2 deletions bindings/python/cconfigspace/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ccs_binding_get_context = _ccs_get_function("ccs_binding_get_context", [ccs_binding, ct.POINTER(ccs_context)])
ccs_binding_get_value = _ccs_get_function("ccs_binding_get_value", [ccs_binding, ct.c_size_t, ct.POINTER(Datum)])
ccs_binding_get_values = _ccs_get_function("ccs_binding_get_values", [ccs_binding, ct.c_size_t, ct.POINTER(Datum), ct.POINTER(ct.c_size_t)])
ccs_binding_get_value_by_name = _ccs_get_function("ccs_binding_get_value_by_name", [ccs_binding, ct.c_char_p, ct.POINTER(Datum)])
ccs_binding_get_value_by_name = _ccs_get_function("ccs_binding_get_value_by_name", [ccs_binding, ct.c_char_p, ct.POINTER(ccs_bool), ct.POINTER(Datum)])
ccs_binding_get_value_by_parameter = _ccs_get_function("ccs_binding_get_value_by_parameter", [ccs_binding, ccs_parameter, ct.POINTER(ccs_bool), ct.POINTER(Datum)])
ccs_binding_hash = _ccs_get_function("ccs_binding_hash", [ccs_binding, ct.POINTER(ccs_hash)])
ccs_binding_cmp = _ccs_get_function("ccs_binding_cmp", [ccs_binding, ccs_binding, ct.POINTER(ct.c_int)])
Expand Down Expand Up @@ -37,7 +37,7 @@ def value(self, parameter):
if isinstance(parameter, Parameter):
res = ccs_binding_get_value_by_parameter(self.handle, parameter.handle, None, ct.byref(v))
elif isinstance(parameter, str):
res = ccs_binding_get_value_by_name(self.handle, str.encode(parameter), ct.byref(v))
res = ccs_binding_get_value_by_name(self.handle, str.encode(parameter), None, ct.byref(v))
else:
res = ccs_binding_get_value(self.handle, parameter, ct.byref(v))
Error.check(res)
Expand Down
9 changes: 6 additions & 3 deletions bindings/python/cconfigspace/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ccs_context_get_num_parameters = _ccs_get_function("ccs_context_get_num_parameters", [ccs_context, ct.POINTER(ct.c_size_t)])
ccs_context_get_parameter = _ccs_get_function("ccs_context_get_parameter", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter)])
ccs_context_get_parameter_by_name = _ccs_get_function("ccs_context_get_parameter_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ccs_parameter)])
ccs_context_get_parameter_index_by_name = _ccs_get_function("ccs_context_get_parameter_index_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ct.c_size_t)])
ccs_context_get_parameter_index_by_name = _ccs_get_function("ccs_context_get_parameter_index_by_name", [ccs_context, ct.c_char_p, ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)])
ccs_context_get_parameter_index = _ccs_get_function("ccs_context_get_parameter_index", [ccs_context, ccs_parameter, ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)])
ccs_context_get_parameter_indexes = _ccs_get_function("ccs_context_get_parameter_indexes", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ccs_bool), ct.POINTER(ct.c_size_t)])
ccs_context_get_parameters = _ccs_get_function("ccs_context_get_parameters", [ccs_context, ct.c_size_t, ct.POINTER(ccs_parameter), ct.POINTER(ct.c_size_t)])
Expand Down Expand Up @@ -34,7 +34,10 @@ def parameter_by_name(self, name):
v = ccs_parameter()
res = ccs_context_get_parameter_by_name(self.handle, str.encode(name), ct.byref(v))
Error.check(res)
return Parameter.from_handle(v)
if v.value is None:
return None
else:
return Parameter.from_handle(v)

def parameter_index(self, parameter):
v = ct.c_size_t()
Expand All @@ -44,7 +47,7 @@ def parameter_index(self, parameter):

def parameter_index_by_name(self, name):
v = ct.c_size_t()
res = ccs_context_get_parameter_index_by_name(self.handle, str.encode(name), ct.byref(v))
res = ccs_context_get_parameter_index_by_name(self.handle, str.encode(name), None, ct.byref(v))
Error.check(res)
return v.value

Expand Down
6 changes: 3 additions & 3 deletions bindings/ruby/lib/cconfigspace/binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CCS
attach_function :ccs_binding_get_context, [:ccs_binding_t, :pointer], :ccs_result_t
attach_function :ccs_binding_get_value, [:ccs_binding_t, :size_t, :pointer], :ccs_result_t
attach_function :ccs_binding_get_values, [:ccs_binding_t, :size_t, :pointer, :pointer], :ccs_result_t
attach_function :ccs_binding_get_value_by_name, [:ccs_binding_t, :string, :pointer], :ccs_result_t
attach_function :ccs_binding_get_value_by_name, [:ccs_binding_t, :string, :pointer, :pointer], :ccs_result_t
attach_function :ccs_binding_get_value_by_parameter, [:ccs_binding_t, :ccs_parameter_t, :pointer, :pointer], :ccs_result_t
attach_function :ccs_binding_hash, [:ccs_binding_t, :pointer], :ccs_result_t
attach_function :ccs_binding_cmp, [:ccs_binding_t, :ccs_binding_t, :pointer], :ccs_result_t
Expand All @@ -16,10 +16,10 @@ def value(parameter)
ptr = MemoryPointer::new(:ccs_datum_t)
case parameter
when String
CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, parameter, ptr)
CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, parameter, nil, ptr)
when Symbol
name = parameter.inspect
CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, name, ptr)
CCS.error_check CCS.ccs_binding_get_value_by_name(@handle, name, nil, ptr)
when Parameter
CCS.error_check CCS.ccs_binding_get_value_by_parameter(@handle, parameter.handle, nil, ptr)
when Integer
Expand Down
7 changes: 4 additions & 3 deletions bindings/ruby/lib/cconfigspace/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CCS
attach_function :ccs_context_get_num_parameters, [:ccs_context_t, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter, [:ccs_context_t, :size_t, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter_by_name, [:ccs_context_t, :string, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter_index_by_name, [:ccs_context_t, :string, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter_index_by_name, [:ccs_context_t, :string, :pointer, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter_index, [:ccs_context_t, :ccs_parameter_t, :pointer, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameter_indexes, [:ccs_context_t, :size_t, :pointer, :pointer, :pointer], :ccs_result_t
attach_function :ccs_context_get_parameters, [:ccs_context_t, :size_t, :pointer, :pointer], :ccs_result_t
Expand All @@ -30,13 +30,14 @@ def parameter_by_name(name)
name = name.inspect if name.kind_of?(Symbol)
ptr = MemoryPointer::new(:ccs_parameter_t)
CCS.error_check CCS.ccs_context_get_parameter_by_name(@handle, name, ptr)
Parameter.from_handle(ptr.read_ccs_parameter_t)
param = ptr.read_ccs_parameter_t
param.null? ? nil : Parameter.from_handle(param)
end

def parameter_index_by_name(name)
name = name.inspect if name.kind_of?(Symbol)
ptr = MemoryPointer::new(:size_t)
CCS.error_check CCS.ccs_context_get_parameter_index_by_name(@handle, name, ptr)
CCS.error_check CCS.ccs_context_get_parameter_index_by_name(@handle, name, nil, ptr)
ptr.read_size_t
end

Expand Down
15 changes: 8 additions & 7 deletions connectors/kokkos/ccs-kokkos-connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ kokkosp_request_values(
ccs_datum_t *values = new ccs_datum_t[numContextVariables];
for (size_t i = 0; i < numContextVariables; i++) {
size_t indx;
CCS_CHECK(ccs_features_space_get_parameter_index(
features_space, features[contextValues[i].type_id],
NULL, &indx));
CCS_CHECK(ccs_context_get_parameter_index(
(ccs_context_t)features_space,
features[contextValues[i].type_id], NULL, &indx));
extract_value(contextValues + i, values + indx);
}
CCS_CHECK(ccs_create_features(
Expand All @@ -604,12 +604,13 @@ kokkosp_request_values(
tuner, &configuration_space));
{
ccs_datum_t *values = new ccs_datum_t[numTuningVariables];
CCS_CHECK(ccs_configuration_get_values(
configuration, numTuningVariables, values, NULL));
CCS_CHECK(ccs_binding_get_values(
(ccs_binding_t)configuration, numTuningVariables, values,
NULL));
for (size_t i = 0; i < numTuningVariables; i++) {
size_t indx;
CCS_CHECK(ccs_configuration_space_get_parameter_index(
configuration_space,
CCS_CHECK(ccs_context_get_parameter_index(
(ccs_context_t)configuration_space,
parameters[tuningValues[i].type_id], NULL, &indx));
set_value(tuningValues + i, values + indx);
}
Expand Down
13 changes: 9 additions & 4 deletions include/cconfigspace/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,24 @@ ccs_binding_get_values(
* Get the value of the parameter with the given name.
* @param[in] binding
* @param[in] name the name of the parameter whose value to retrieve
* @param[out] found_ret a pointer to the an optional variable that will
* hold wether a parameter named \p name was found in
* \p binding
* @param[out] value_ret a pointer to the variable that will hold the value
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS
* object
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p value_ret is NULL
* @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name
* exist in the \p binding context
* @return #CCS_RESULT_ERROR_INVALID_NAME if \p found_ret is NULL no parameter
* with such \p name exist in the \p binding context
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_binding_get_value_by_name(
ccs_binding_t binding,
const char *name,
ccs_bool_t *found_ret,
ccs_datum_t *value_ret);

/**
Expand Down Expand Up @@ -125,7 +129,7 @@ ccs_binding_get_value_by_parameter(
* value.
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding is not a valid CCS
* object
* binding
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p hash_ret is NULL
* @remarks
* This function is thread-safe
Expand All @@ -144,7 +148,8 @@ ccs_binding_hash(ccs_binding_t binding, ccs_hash_t *hash_ret);
* than, equal, or greater then the second binding
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p binding or \p other_binding
* are not valid CCS objects
* are not valid CCS bindings; or if \p binding and \p other_binding are
* bindings of different types
* @return #CCS_RESULT_ERROR_INVALID_VALUE if \p cmp_ret is NULL
* @remarks
* This function is thread-safe
Expand Down
106 changes: 0 additions & 106 deletions include/cconfigspace/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,74 +57,6 @@ ccs_configuration_get_configuration_space(
ccs_configuration_t configuration,
ccs_configuration_space_t *configuration_space_ret);

/**
* Get the value of the parameter at the given index.
* @param[in] configuration
* @param[in] index index of the parameter in the associated configuration
* space
* @param[out] value_ret a pointer to the variable that will hold the value
* @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 value_ret is NULL
* @return #CCS_RESULT_ERROR_OUT_OF_BOUNDS if \p index is greater than the count
* of parameters in the configuration space
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_get_value(
ccs_configuration_t configuration,
size_t index,
ccs_datum_t *value_ret);

/**
* Get all the values in the configuration.
* @param[in] configuration
* @param[in] num_values the size of the \p values array
* @param[out] values an array of size \p num_values to hold the returned
* values, or NULL. If the array is too big, extra values
* are set to #CCS_DATA_TYPE_NONE
* @param[out] num_values_ret a pointer to a variable that will contain the
* number of values that are or would be returned.
* Can be NULL
* @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 values is NULL and \p
* num_values is greater than 0; or if \p values is NULL and \p num_values_ret
* is NULL; or if \p num_values is less than the number of values that would be
* returned
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_get_values(
ccs_configuration_t configuration,
size_t num_values,
ccs_datum_t *values,
size_t *num_values_ret);

/**
* Get the value of the parameter with the given name.
* @param[in] configuration
* @param[in] name the name of the parameter whose value to retrieve
* @param[out] value_ret a pointer to the variable that will hold the value
* @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 value_ret is NULL
* @return #CCS_RESULT_ERROR_INVALID_NAME if no parameter with such \p name
* exist in the \p configuration space
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_get_value_by_name(
ccs_configuration_t configuration,
const char *name,
ccs_datum_t *value_ret);

/**
* Check that the configuration is a valid configuration for the configuration
* space.
Expand All @@ -149,44 +81,6 @@ ccs_configuration_check(
ccs_configuration_t configuration,
ccs_bool_t *is_valid_ret);

/**
* Compute a hash value for the configuration by hashing together the
* configuration space reference, the number of values, and the values
* themselves.
* @param[in] configuration
* @param[out] hash_ret the address of the variable that will contain the hash
* value
* @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 hash_ret is NULL
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_hash(ccs_configuration_t configuration, ccs_hash_t *hash_ret);

/**
* Define a strict ordering of configuration instances. Configuration space,
* number of values and values are compared.
* @param[in] configuration the first configuration
* @param[in] other_configuration the second configuration
* @param[out] cmp_ret the pointer to the variable that will contain the result
* of the comparison. Will contain -1, 0, or 1 depending on
* if the first configuration is found to be respectively
* lesser than, equal, or greater then the second
* configuration
* @return #CCS_RESULT_SUCCESS on success
* @return #CCS_RESULT_ERROR_INVALID_OBJECT if \p configuration or \p
* other_configuration are not a valid CCS object
* @remarks
* This function is thread-safe
*/
extern ccs_result_t
ccs_configuration_cmp(
ccs_configuration_t configuration,
ccs_configuration_t other_configuration,
int *cmp_ret);
#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit cfa3a22

Please sign in to comment.