Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CTL] Add variadic functions #1123

Draft
wants to merge 1 commit into
base: v0.12.x-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
} UMF_0.11;
Loading