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

Add a context-level query capability. #621

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
47 changes: 47 additions & 0 deletions parsec/parsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2759,3 +2759,50 @@ void parsec_set_my_execution_stream(parsec_execution_stream_t *es)
{
PARSEC_TLS_SET_SPECIFIC(parsec_tls_execution_stream, es);
}


/**
* Query the number of devices of the requested type available in the
* PaRSEC context.
*/
bosilca marked this conversation as resolved.
Show resolved Hide resolved
int parsec_context_query(parsec_context_t *context, parsec_context_query_cmd_t cmd, ...)
{
parsec_device_module_t* dev;
va_list args;
va_start(args, cmd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing call to va_end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many return points to place an va_end. Plus everything related to the va_list is on the stack, so returning should clean up everything.


switch(cmd) {
case PARSEC_CONTEXT_QUERY_NODES:
switch (parsec_communication_engine_up) {
case 0: return 0; /* context not ready for distributed runs, and lacking datatype chandling capabilities */
case 1: return 1; /* single node runs, but the context has datatype management capabilties */
case 2: return PARSEC_ERR_NOT_FOUND; /* we are in a distributed run, but the MPI engine is not yet ready, so the nb_nodes might not be accurate */
case 3: return context->nb_nodes;
}
return PARSEC_ERROR;

case PARSEC_CONTEXT_QUERY_RANK:
return context->my_rank;

case PARSEC_CONTEXT_QUERY_DEVICES:
int device_type = va_arg(args, int), count = 0;
for( uint32_t i = 0; i < parsec_nb_devices; i++ ) {
dev = parsec_mca_device_get(i);
if( dev->type & device_type ) count++;
}
return count;

case PARSEC_CONTEXT_QUERY_CORES:
int nb_total_comp_threads = 0;
for (int idx = 0; idx < context->nb_vp; idx++) {
nb_total_comp_threads += context->virtual_processes[idx]->nb_cores;
}
return nb_total_comp_threads;

case PARSEC_CONTEXT_QUERY_ACTIVE_TASKPOOLS:
return context->active_taskpools;
/* no default */
}
return PARSEC_ERR_NOT_SUPPORTED; /* unknown command */
}

28 changes: 28 additions & 0 deletions parsec/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,34 @@ int parsec_context_add_taskpool( parsec_context_t* context, parsec_taskpool_t* t
*/
int parsec_context_remove_taskpool( parsec_taskpool_t* tp );

/**
* Query PaRSEC context capabilities.
*/

typedef enum parsec_context_query_cmd_e {
PARSEC_CONTEXT_QUERY_NODES,
PARSEC_CONTEXT_QUERY_RANK,
PARSEC_CONTEXT_QUERY_DEVICES,
PARSEC_CONTEXT_QUERY_CORES,
PARSEC_CONTEXT_QUERY_ACTIVE_TASKPOOLS
} parsec_context_query_cmd_t;
bosilca marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Query PaRSEC context's properties.
*
* @details
* Query properties of the runtime, such as number of devices of a certain type
* or number of cores available to the context.
*
* @param[in] context the PaRSEC context
* @param[in] device_type the type of device the query is about
* @return PARSEC_ERR_NOT_SUPPORTED if the command is not supported, PARSEC_ERR_NOT_FOUND
* if the correct answer cannot yet be returned (such as when the PaRSEC context
* has not yet properly been initialized), or the answer to the query (always
* a positive number).
*/
int parsec_context_query(parsec_context_t* context, parsec_context_query_cmd_t cmd, ... );

/**
* @brief Start taskpool that were enqueued into the PaRSEC context
*
Expand Down
Loading