Skip to content

Commit

Permalink
Merge pull request #353 from shintaro-iwasaki/pr/pool_config
Browse files Browse the repository at this point in the history
implement ABT_pool_config
  • Loading branch information
shintaro-iwasaki authored Jul 18, 2021
2 parents c74c160 + 117bbf3 commit 577e8f0
Show file tree
Hide file tree
Showing 22 changed files with 1,090 additions and 202 deletions.
18 changes: 16 additions & 2 deletions Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,9 @@ ALIASES += DOC_DESC_ATOMICITY_XSTREAM_REQUEST="Requests for execution streams ar

ALIASES += DOC_DESC_ATOMICITY_XSTREAM_STATE="Management of states of execution streams is performed atomically."

ALIASES += DOC_DESC_SCHED_AUTOMATIC{1}="If \1 is not configured to be automatically freed, it is the user's responsibility to free \1 after its use unless \c newsched is associated with the main scheduler of the primary execution stream. If \1 is configured to be automatically freed, \1 is automatically freed when a work unit associated with \1 is freed. If the user never associates \1 with a work unit (e.g., by \c ABT_pool_add_sched() or \c ABT_xstream_set_main_sched()), it is the user's responsibility to free \1."
ALIASES += DOC_DESC_POOL_AUTOMATIC{1}="If \1 is not configured to be automatically freed, it is the user's responsibility to free \1 after its use unless \c 1 is associated with the main scheduler of the primary execution stream. If \1 is configured to be automatically freed, \1 is automatically freed when all schedulers associated with \1 is freed. If the user never associates \1 with a scheduler (e.g., by \c ABT_sched_create()), it is the user's responsibility to free \1."

ALIASES += DOC_DESC_SCHED_AUTOMATIC{1}="If \1 is not configured to be automatically freed, it is the user's responsibility to free \1 after its use unless \c 1 is associated with the main scheduler of the primary execution stream. If \1 is configured to be automatically freed, \1 is automatically freed when a work unit associated with \1 is freed. If the user never associates \1 with a work unit (e.g., by \c ABT_pool_add_sched() or \c ABT_xstream_set_main_sched()), it is the user's responsibility to free \1."

ALIASES += DOC_DESC_TIMER_RESOLUTION="The resolution of elapsed time depends on the clock resolution of the system."

Expand Down Expand Up @@ -1980,6 +1982,12 @@ ALIASES += DOC_ERROR_INV_ARG_INV_TOOL_QUERY_KIND{2}="\c ABT_ERR_INV_ARG is retur

ALIASES += DOC_ERROR_INV_ARG_NEG{1}="\c ABT_ERR_INV_ARG is returned if \1 is negative.\n"

ALIASES += DOC_ERROR_INV_ARG_POOL_CONFIG_INDEX{2}="\c ABT_ERR_INV_ARG is returned if \1 does not have a value associated with \2.\n"

ALIASES += DOC_ERROR_INV_ARG_POOL_CONFIG_TYPE="\c ABT_ERR_INV_ARG is returned if \c type of the given \c ABT_pool_config_var is invalid.\n"

ALIASES += DOC_ERROR_INV_ARG_POOL_CONFIG_TYPE{1}="\c ABT_ERR_INV_ARG is returned if \1 is invalid.\n"

ALIASES += DOC_ERROR_INV_ARG_SCHED_CONFIG_INDEX{2}="\c ABT_ERR_INV_ARG is returned if \1 does not have a value associated with \2.\n"

ALIASES += DOC_ERROR_INV_ARG_SCHED_CONFIG_TYPE="\c ABT_ERR_INV_ARG is returned if \c type of the given \c ABT_sched_config_var is invalid.\n"
Expand Down Expand Up @@ -2022,6 +2030,10 @@ ALIASES += DOC_ERROR_INV_MUTEX_PTR{1}="\c ABT_ERR_INV_MUTEX is returned if \1 po

ALIASES += DOC_ERROR_INV_POOL_ACCESS{1}="\c ABT_ERR_INV_POOL_ACCESS is returned if \1 is not a valid pool access type.\n"

ALIASES += DOC_ERROR_INV_POOL_CONFIG_HANDLE{1}="\c ABT_ERR_INV_POOL_CONFIG is returned if \1 is \c ABT_SCHED_POOL_NULL.\n"

ALIASES += DOC_ERROR_INV_POOL_CONFIG_PTR{1}="\c ABT_ERR_INV_POOL_CONFIG is returned if \1 points to \c ABT_SCHED_POOL_NULL.\n"

ALIASES += DOC_ERROR_INV_POOL_HANDLE{1}="\c ABT_ERR_INV_POOL is returned if \1 is \c ABT_POOL_NULL.\n"

ALIASES += DOC_ERROR_INV_POOL_KIND{1}="\c ABT_ERR_INV_POOL_KIND is returned if \1 is not a valid pool kind.\n"
Expand Down Expand Up @@ -2162,7 +2174,9 @@ ALIASES += DOC_NOTE_DEFAULT_MUTEX_ATTRIBUTE="To check the details of the default

ALIASES += DOC_NOTE_DEFAULT_POOL="To see the details of the default pool, please check \c ABT_pool_create()."

ALIASES += DOC_NOTE_DEFAULT_POOL_CONFIG=""
ALIASES += DOC_NOTE_DEFAULT_POOL_AUTOMATIC="To see the details of whether the pool is automatically freed or not, please check \c ABT_pool_create()."

ALIASES += DOC_NOTE_DEFAULT_POOL_CONFIG=""To see the details of the default pool configuration, please check \c ABT_pool_config_create()."

ALIASES += DOC_NOTE_DEFAULT_SCHED="To see the details of the default scheduler, please check \c ABT_sched_create()."

Expand Down
3 changes: 2 additions & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ int ABT_error_get_str(int err, char *str, size_t *len)
"ABT_ERR_INV_TOOL_CONTEXT",
"ABT_ERR_INV_ARG",
"ABT_ERR_SYS",
"ABT_ERR_CPUID" };
"ABT_ERR_CPUID",
"ABT_ERR_INV_POOL_CONFIG" };

#ifndef ABT_CONFIG_ENABLE_VER_20_API
ABTI_CHECK_TRUE(err >= ABT_SUCCESS &&
Expand Down
3 changes: 2 additions & 1 deletion src/include/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ noinst_HEADERS = \
include/abti.h \
include/abti_barrier.h \
include/abti_cond.h \
include/abti_config.h \
include/abti_error.h \
include/abti_event.h \
include/abti_eventual.h \
Expand All @@ -32,7 +31,9 @@ noinst_HEADERS = \
include/abti_mutex_attr.h \
include/abti_rwlock.h \
include/abti_pool.h \
include/abti_pool_config.h \
include/abti_sched.h \
include/abti_sched_config.h \
include/abti_self.h \
include/abti_stream.h \
include/abti_stream_barrier.h \
Expand Down
53 changes: 53 additions & 0 deletions src/include/abt.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ extern "C" {
* @brief Error code: invalid pool access type.
*/
#define ABT_ERR_INV_POOL_ACCESS 14
/**
* @ingroup ERROR_CODE
* @brief Error code: invalid pool configuration.
*/
#define ABT_ERR_INV_POOL_CONFIG 56
/**
* @ingroup ERROR_CODE
* @brief Error code: invalid work unit for scheduling.
Expand Down Expand Up @@ -1400,6 +1405,46 @@ typedef struct {
ABT_sched_get_migr_pool_fn get_migr_pool;
} ABT_sched_def;

/**
* @ingroup POOL_CONFIG
* @brief A struct that sets and gets a pool configuration.
*/
typedef enum {
/** Parameter of type int */
ABT_POOL_CONFIG_INT = 0,
/** Parameter of type double */
ABT_POOL_CONFIG_DOUBLE = 1,
/** Parameter of type pointer */
ABT_POOL_CONFIG_PTR = 2,
} ABT_pool_config_type;

/**
* @ingroup POOL_CONFIG
* @brief A struct that sets and gets a pool configuration.
*/
typedef struct {
/**
* A key of a configuration variable. It must be non-negative as negative
* keys are reserved for the Argobots internal use.
*/
int key;
/** Type of a configuration variable. */
ABT_pool_config_type type;
} ABT_pool_config_var;

/**
* @ingroup POOL_CONFIG
* @var ABT_pool_config_automatic
* @brief Predefined ABT_pool_config_var to configure whether the pool is
* freed automatically or not.
* @hideinitializer
*
* Its type is int. If the value is non-zero, the pool is freed automatically
* after its associated objects are released. If the value is zero, the pool is
* configured to be not freed automatically by the Argobots runtime.
*/
extern const ABT_pool_config_var ABT_pool_config_automatic ABT_API_PUBLIC;

/* Pool Functions */
typedef ABT_unit_type (*ABT_unit_get_type_fn)(ABT_unit);
typedef ABT_thread (*ABT_unit_get_thread_fn)(ABT_unit);
Expand Down Expand Up @@ -1782,6 +1827,14 @@ int ABT_pool_get_data(ABT_pool pool, void **data) ABT_API_PUBLIC;
int ABT_pool_add_sched(ABT_pool pool, ABT_sched sched) ABT_API_PUBLIC;
int ABT_pool_get_id(ABT_pool pool, int *id) ABT_API_PUBLIC;

/* Pool config */
int ABT_pool_config_create(ABT_pool_config *config) ABT_API_PUBLIC;
int ABT_pool_config_free(ABT_pool_config *config) ABT_API_PUBLIC;
int ABT_pool_config_set(ABT_pool_config config, int key, ABT_pool_config_type type,
const void *val) ABT_API_PUBLIC;
int ABT_pool_config_get(ABT_pool_config config, int key,
ABT_pool_config_type *p_type, void *val) ABT_API_PUBLIC;

/* Work Unit */
int ABT_unit_get_thread(ABT_unit unit, ABT_thread *thread) ABT_API_PUBLIC;
int ABT_unit_set_associated_pool(ABT_unit unit, ABT_pool pool) ABT_API_PUBLIC;
Expand Down
27 changes: 12 additions & 15 deletions src/include/abti.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
#define ABTI_UNIT_HASH_TABLE_SIZE_EXP 8 /* N -> 2^N table entries */
#define ABTI_UNIT_HASH_TABLE_SIZE ((size_t)(1 << ABTI_UNIT_HASH_TABLE_SIZE_EXP))

#define ABTI_SCHED_CONFIG_HTABLE_SIZE 8
#define ABTI_SCHED_CONFIG_UNUSED_INDEX INT_MIN

#define ABTI_STACK_CHECK_TYPE_NONE 0
#define ABTI_STACK_CHECK_TYPE_CANARY 1
#define ABTI_STACK_CHECK_TYPE_MPROTECT 2
Expand Down Expand Up @@ -116,13 +113,13 @@ typedef struct ABTI_local_func ABTI_local_func;
typedef struct ABTI_xstream ABTI_xstream;
typedef enum ABTI_xstream_type ABTI_xstream_type;
typedef struct ABTI_sched ABTI_sched;
typedef struct ABTI_sched_config_element ABTI_sched_config_element;
typedef struct ABTI_sched_config ABTI_sched_config;
typedef enum ABTI_sched_used ABTI_sched_used;
typedef void *ABTI_sched_id; /* Scheduler id */
typedef uintptr_t ABTI_sched_kind; /* Scheduler kind */
typedef struct ABTI_pool ABTI_pool;
typedef struct ABTI_pool_def ABTI_pool_def;
typedef struct ABTI_pool_config ABTI_pool_config;
typedef struct ABTI_thread ABTI_thread;
typedef struct ABTI_thread_attr ABTI_thread_attr;
typedef struct ABTI_ythread ABTI_ythread;
Expand Down Expand Up @@ -319,17 +316,8 @@ struct ABTI_sched {
#endif
};

struct ABTI_sched_config_element {
int idx; /* Index of this element. */
ABT_sched_config_type type; /* Element type. */
char val[sizeof(double) > sizeof(void *)
? sizeof(double)
: sizeof(void *)]; /* Memory for double, int, or pointer */
ABTI_sched_config_element *p_next; /* Next element. */
};

struct ABTI_sched_config {
ABTI_sched_config_element elements[ABTI_SCHED_CONFIG_HTABLE_SIZE];
ABTU_hashtable *p_table;
};

struct ABTI_pool {
Expand Down Expand Up @@ -376,6 +364,10 @@ struct ABTI_pool_def {
ABT_pool_print_all_fn p_print_all;
};

struct ABTI_pool_config {
ABTU_hashtable *p_table;
};

struct ABTI_thread {
ABTI_thread *p_prev;
ABTI_thread *p_next;
Expand Down Expand Up @@ -566,6 +558,10 @@ ABTU_ret_err int ABTI_pool_get_fifo_wait_def(ABT_pool_access access,
void ABTI_pool_print(ABTI_pool *p_pool, FILE *p_os, int indent);
void ABTI_pool_reset_id(void);

/* Pool config */
ABTU_ret_err int ABTI_pool_config_read(const ABTI_pool_config *p_config,
int key, void *p_val);

/* Work Unit */
void ABTI_unit_init_hash_table(ABTI_global *p_global);
void ABTI_unit_finalize_hash_table(ABTI_global *p_global);
Expand Down Expand Up @@ -640,8 +636,9 @@ void ABTI_info_check_print_all_thread_stacks(void);
#include "abti_global.h"
#include "abti_self.h"
#include "abti_pool.h"
#include "abti_pool_config.h"
#include "abti_sched.h"
#include "abti_config.h"
#include "abti_sched_config.h"
#include "abti_stream.h"
#include "abti_thread.h"
#include "abti_unit.h"
Expand Down
9 changes: 9 additions & 0 deletions src/include/abti_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@
} \
} while (0)

#define ABTI_CHECK_NULL_POOL_CONFIG_PTR(p) \
do { \
if (ABTI_IS_ERROR_CHECK_ENABLED && \
ABTU_unlikely(p == (ABTI_pool_config *)NULL)) { \
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_POOL_CONFIG); \
return ABT_ERR_INV_POOL_CONFIG; \
} \
} while (0)

#define ABTI_CHECK_NULL_SCHED_PTR(p) \
do { \
if (ABTI_IS_ERROR_CHECK_ENABLED && \
Expand Down
42 changes: 42 additions & 0 deletions src/include/abti_pool_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
* See COPYRIGHT in top-level directory.
*/

#ifndef ABTI_POOL_CONFIG_H_INCLUDED
#define ABTI_POOL_CONFIG_H_INCLUDED

/* Inlined functions for pool config */

static inline ABTI_pool_config *ABTI_pool_config_get_ptr(ABT_pool_config config)
{
#ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
ABTI_pool_config *p_config;
if (config == ABT_POOL_CONFIG_NULL) {
p_config = NULL;
} else {
p_config = (ABTI_pool_config *)config;
}
return p_config;
#else
return (ABTI_pool_config *)config;
#endif
}

static inline ABT_pool_config
ABTI_pool_config_get_handle(ABTI_pool_config *p_config)
{
#ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
ABT_pool_config h_config;
if (p_config == NULL) {
h_config = ABT_POOL_CONFIG_NULL;
} else {
h_config = (ABT_pool_config)p_config;
}
return h_config;
#else
return (ABT_pool_config)p_config;
#endif
}

#endif /* ABTI_POOL_CONFIG_H_INCLUDED */
8 changes: 4 additions & 4 deletions src/include/abti_config.h → src/include/abti_sched_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* See COPYRIGHT in top-level directory.
*/

#ifndef ABTI_CONFIG_H_INCLUDED
#define ABTI_CONFIG_H_INCLUDED
#ifndef ABTI_SCHED_CONFIG_H_INCLUDED
#define ABTI_SCHED_CONFIG_H_INCLUDED

/* Inlined functions for Config */
/* Inlined functions for scheduler config */

static inline ABTI_sched_config *
ABTI_sched_config_get_ptr(ABT_sched_config config)
Expand Down Expand Up @@ -40,4 +40,4 @@ ABTI_sched_config_get_handle(ABTI_sched_config *p_config)
#endif
}

#endif /* ABTI_CONFIG_H_INCLUDED */
#endif /* ABTI_SCHED_CONFIG_H_INCLUDED */
22 changes: 22 additions & 0 deletions src/include/abtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,26 @@ ABTU_ret_err int ABTU_atoui64(const char *str, uint64_t *p_val,
ABTU_ret_err int ABTU_atosz(const char *str, size_t *p_val,
ABT_bool *p_overflow);

/* Simple hash table */

typedef struct ABTU_hashtable_element {
int key;
struct ABTU_hashtable_element *p_next;
char *data;
} ABTU_hashtable_element;

typedef struct ABTU_hashtable {
size_t num_entries;
size_t data_size;
} ABTU_hashtable;

ABTU_ret_err int ABTU_hashtable_create(size_t num_entries, size_t data_size,
ABTU_hashtable **pp_hashtable);
void ABTU_hashtable_free(ABTU_hashtable *p_hashtable);
void ABTU_hashtable_get(const ABTU_hashtable *p_hashtable, int key, void *data,
int *found);
ABTU_ret_err int ABTU_hashtable_set(ABTU_hashtable *p_hashtable, int key,
const void *data, int *overwritten);
void ABTU_hashtable_delete(ABTU_hashtable *p_hashtable, int key, int *deleted);

#endif /* ABTU_H_INCLUDED */
4 changes: 2 additions & 2 deletions src/pool/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
abt_sources += \
pool/fifo.c \
pool/fifo_wait.c \
pool/pool.c

pool/pool.c \
pool/pool_config.c
Loading

0 comments on commit 577e8f0

Please sign in to comment.