Skip to content

Commit

Permalink
[CTL] Make CTL API as a variadic functions
Browse files Browse the repository at this point in the history
Since this commit all the CTL API functions (umfCtlSet/Get/Exec)
will be defined as a variadic functions to provide more elastic
approach in future development.
  • Loading branch information
KFilipek committed Feb 26, 2025
1 parent d319917 commit d425443
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
15 changes: 6 additions & 9 deletions include/umf/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,26 @@ typedef enum umf_ctl_query_type {
///
/// @brief Get value of a specified attribute at the given name.
/// @param name name of an attribute to be retrieved
/// @param ctx pointer to the pool or the provider
/// @param arg [out] pointer to the variable where the value will be stored
/// @param ... number and type of arguments depends on the given name
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
///
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg);
umf_result_t umfCtlGet(const char *name, ...);

///
/// @brief Set value of a specified attribute at the given name.
/// @param name name of an attribute to be set
/// @param ctx pointer to the pool or the provider
/// @param arg [in] pointer to the value that will be set
/// @param ... number and type of arguments depends on the given name
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
///
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg);
umf_result_t umfCtlSet(const char *name, ...);

///
/// @brief Execute callback related with the specified attribute.
/// @param name name of an attribute to be executed
/// @param ctx pointer to the pool or the provider
/// @param arg [in/out] pointer to the value, can be used as an input or output
/// @param ... number and type of arguments depends on the given name
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
///
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg);
umf_result_t umfCtlExec(const char *name, ...);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion include/umf/memory_pool_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
/// @brief Version of the Memory Pool ops structure.
/// NOTE: This is equal to the latest UMF version, in which the ops structure
/// has been modified.
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)

///
/// @brief This structure comprises function pointers used by corresponding umfPool*
Expand Down
2 changes: 1 addition & 1 deletion include/umf/memory_provider_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C" {
/// @brief Version of the Memory Provider ops structure.
/// NOTE: This is equal to the latest UMF version, in which the ops structure
/// has been modified.
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)

///
/// @brief This structure comprises optional function pointers used
Expand Down
49 changes: 37 additions & 12 deletions src/ctl/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -81,30 +82,54 @@ char *Strdup(const char *s) {
return p;
}

umf_result_t umfCtlGet(const char *name, void *ctx, void *arg) {
if (name == NULL || arg == NULL || ctx == NULL) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
umf_result_t umfCtlGet(const char *name, ...) {
assert(name != NULL);

va_list args;
va_start(args, name);

void *ctx = va_arg(args, void *);
void *arg = va_arg(args, void *);
va_end(args);

assert(arg != NULL);
assert(ctx != NULL);
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ,
arg)
? UMF_RESULT_ERROR_UNKNOWN
: UMF_RESULT_SUCCESS;
}

umf_result_t umfCtlSet(const char *name, void *ctx, void *arg) {
if (name == NULL || arg == NULL || ctx == NULL) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
umf_result_t umfCtlSet(const char *name, ...) {
assert(name != NULL);

va_list args;
va_start(args, name);

void *ctx = va_arg(args, void *);
void *arg = va_arg(args, void *);
va_end(args);

assert(arg != NULL);
assert(ctx != NULL);
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE,
arg)
? UMF_RESULT_ERROR_UNKNOWN
: UMF_RESULT_SUCCESS;
}

umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
if (name == NULL || arg == NULL || ctx == NULL) {
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
}
umf_result_t umfCtlExec(const char *name, ...) {
assert(name != NULL);

va_list args;
va_start(args, name);

void *ctx = va_arg(args, void *);
void *arg = va_arg(args, void *);
va_end(args);

assert(arg != NULL);
assert(ctx != NULL);
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
CTL_QUERY_RUNNABLE, arg)
? UMF_RESULT_ERROR_UNKNOWN
Expand Down
7 changes: 4 additions & 3 deletions src/libumf.def
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ EXPORTS
umfScalablePoolParamsSetKeepAllMemory
; Added in UMF_0.11
umfCUDAMemoryProviderParamsSetAllocFlags
umfCtlExec
umfCtlGet
umfCtlSet
umfDisjointPoolOps
umfDisjointPoolParamsCreate
umfDisjointPoolParamsDestroy
Expand All @@ -139,3 +136,7 @@ EXPORTS
umfFixedMemoryProviderParamsDestroy
umfLevelZeroMemoryProviderParamsSetFreePolicy
umfLevelZeroMemoryProviderParamsSetDeviceOrdinal
; Added in UMF_0.12
umfCtlExec
umfCtlGet
umfCtlSet
9 changes: 6 additions & 3 deletions src/libumf.map
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ UMF_0.10 {

UMF_0.11 {
umfCUDAMemoryProviderParamsSetAllocFlags;
umfCtlExec;
umfCtlGet;
umfCtlSet;
umfDisjointPoolOps;
umfDisjointPoolParamsCreate;
umfDisjointPoolParamsDestroy;
Expand All @@ -138,3 +135,9 @@ UMF_0.11 {
umfLevelZeroMemoryProviderParamsSetFreePolicy;
umfLevelZeroMemoryProviderParamsSetDeviceOrdinal;
} UMF_0.10;

UMF_0.12 {
umfCtlExec;
umfCtlGet;
umfCtlSet;
};

0 comments on commit d425443

Please sign in to comment.