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

Introduce managed objects #728

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions parsec/class/list_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
* Copyright (c) 2025 Stony Brook University. All rights reserved.
*/

#ifndef PARSEC_LIST_ITEM_H_HAS_BEEN_INCLUDED
Expand All @@ -25,7 +26,7 @@
* parsec_internal_classes_list, @ref parsec_internal_classes_lifo,
* @ref parsec_internal_classes_fifo, for examples of data structures
* that use list items.
*
*
* Functions and macros in this group are used to manipulate the
* list items.
*/
Expand All @@ -36,7 +37,7 @@ BEGIN_C_DECLS
* @brief List Item structure
*/
typedef struct parsec_list_item_s {
parsec_object_t super; /**< A list item is a @ref parsec_internal_classes_object */
parsec_managed_object_t super; /**< A list item is a @ref parsec_internal_classes_object */
volatile struct parsec_list_item_s* list_next; /**< Pointer to the next item */
volatile struct parsec_list_item_s* list_prev; /**< Pointer to the previous item */
int32_t aba_key; /**< This field is __very__ special and should be handled with extreme
Expand All @@ -62,7 +63,7 @@ PARSEC_DECLSPEC PARSEC_OBJ_CLASS_DECLARATION(parsec_list_item_t);
*/
#define PARSEC_LIST_ITEM_PREV(item) ((__typeof__(item))(((parsec_list_item_t*)(item))->list_prev))

/**
/**
* @brief
* Make a well formed singleton ring with a list item.
*
Expand Down Expand Up @@ -93,7 +94,7 @@ parsec_list_item_singleton( parsec_list_item_t* item )
* @details
* Starting with first, ending with last, returns first.
* if first->last is not a valid chain of items, result is undetermined
* in PARSEC_DEBUG_PARANOID mode, attached items are detached, must be reattached if needed
* in PARSEC_DEBUG_PARANOID mode, attached items are detached, must be reattached if needed
* @param[inout] first the first item of the chain
* @param[inout] last the last item of the chain
* @return first after it has been chained to last to make a ring
Expand Down
3 changes: 2 additions & 1 deletion parsec/class/parsec_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2013-2021 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2025 Stony Brook University. All rights reserved.
*/

#include "parsec/parsec_config.h"
Expand All @@ -22,7 +23,7 @@ parsec_list_item_construct( parsec_list_item_t* item )
#endif
}

PARSEC_OBJ_CLASS_INSTANCE(parsec_list_item_t, parsec_object_t,
PARSEC_OBJ_CLASS_INSTANCE(parsec_list_item_t, parsec_managed_object_t,
parsec_list_item_construct, NULL);

/**
Expand Down
13 changes: 13 additions & 0 deletions parsec/class/parsec_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2025 Stony Brook University. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -61,6 +62,18 @@ static const int increment = 10;
static void save_class(parsec_class_t *cls);
static void expand_array(void);

static inline void
parsec_managed_object_construct( parsec_managed_object_t* obj )
{
/* mark the object as managed so PARSEC_OBJ_RELEASE calls the release callback */
obj->super.obj_flags = PARSEC_OBJ_FLAG_MANAGED;
obj->obj_release = (parsec_release_t)&free; // fallback, may be overwritten by application
}

PARSEC_OBJ_CLASS_INSTANCE(parsec_managed_object_t, parsec_object_t,
parsec_managed_object_construct, NULL);


/*
* When we build PaRSEC itself, we will use the inline version of the function from
* the header file. When we are building outside the scope of PaRSEC, aka. using
Expand Down
46 changes: 43 additions & 3 deletions parsec/class/parsec_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2025 Stony Brook University. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -135,10 +136,20 @@ BEGIN_C_DECLS

typedef struct parsec_object_t parsec_object_t;
typedef struct parsec_class_t parsec_class_t;
typedef struct parsec_managed_object_t parsec_managed_object_t;
typedef void (*parsec_construct_t) (parsec_object_t *);
typedef void (*parsec_destruct_t) (parsec_object_t *);
typedef void (*parsec_release_t) (parsec_managed_object_t *);



/* enums **************************************************************/

enum {
PARSEC_OBJ_FLAG_DEFAULT = 0,
PARSEC_OBJ_FLAG_MANAGED = 1, // object release managed by applications
};

/* types **************************************************************/

/**
Expand Down Expand Up @@ -183,14 +194,24 @@ struct parsec_object_t {
struct's memory */
uint64_t obj_magic_id;
#endif /* defined(PARSEC_DEBUG_PARANOID) */
parsec_class_t *obj_class; /**< class descriptor */
parsec_class_t *obj_class; /**< class descriptor */
volatile int32_t obj_reference_count; /**< reference count */
int obj_flags; /**< flags */
#if defined(PARSEC_DEBUG_PARANOID)
const char* cls_init_file_name; /**< In debug mode store the file where the object get contructed */
int cls_init_lineno; /**< In debug mode store the line number where the object get contructed */
#endif /* defined(PARSEC_DEBUG_PARANOID) */
};

/**
* Managed object. This is a base object that allows users to set
* the function with which the object is released back to the system.
*/
struct parsec_managed_object_t {
parsec_object_t super;
parsec_release_t obj_release;
};

/* macros ************************************************************/

/**
Expand Down Expand Up @@ -314,7 +335,12 @@ static inline parsec_object_t *parsec_obj_new_debug(parsec_class_t* type, const
parsec_obj_run_destructors((parsec_object_t *) (object)); \
PARSEC_OBJ_SET_MAGIC_ID((object), 0); \
PARSEC_OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
free(object); \
if (((parsec_object_t *) (object))->obj_flags &= PARSEC_OBJ_FLAG_MANAGED) { \
assert(((parsec_managed_object_t*)(object))->obj_release != NULL); \
((parsec_managed_object_t*)(object))->obj_release((parsec_managed_object_t*)object); \
} else { \
free(object); \
} \
object = NULL; \
} \
} while (0)
Expand All @@ -323,7 +349,11 @@ static inline parsec_object_t *parsec_obj_new_debug(parsec_class_t* type, const
do { \
if (0 == parsec_obj_update((parsec_object_t *) (object), -1)) { \
parsec_obj_run_destructors((parsec_object_t *) (object)); \
free(object); \
if (((parsec_object_t *) (object))->obj_flags &= PARSEC_OBJ_FLAG_MANAGED) { \
((parsec_managed_object_t*)(object))->obj_release((parsec_managed_object_t*)object); \
} else { \
free(object); \
} \
object = NULL; \
} \
} while (0)
Expand Down Expand Up @@ -504,4 +534,14 @@ END_C_DECLS
* @}
*/

/**
* Set the release callback on a managed object.
*/
static inline void
parsec_managed_object_set_release(parsec_managed_object_t *obj, parsec_release_t release) {
obj->obj_release = release;
}

PARSEC_OBJ_CLASS_DECLARATION(parsec_managed_object_t);

#endif
16 changes: 8 additions & 8 deletions parsec/interfaces/dtd/insert_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ parsec_dtd_taskpool_destructor(parsec_dtd_taskpool_t *tp)
#if defined(PARSEC_PROF_TRACE)
free((void *)tp->super.profiling_array);
#endif /* defined(PARSEC_PROF_TRACE) */

if( NULL != tp->super.taskpool_name) {
free(tp->super.taskpool_name);
tp->super.taskpool_name = NULL;
Expand Down Expand Up @@ -1197,8 +1197,8 @@ parsec_dtd_tile_find(parsec_data_collection_t *dc, uint64_t key)
void
parsec_dtd_tile_release(parsec_dtd_tile_t *tile)
{
assert(tile->super.super.obj_reference_count > 1);
if( 2 == parsec_atomic_fetch_dec_int32(&tile->super.super.obj_reference_count)) {
assert(tile->super.super.super.obj_reference_count > 1);
if( 2 == parsec_atomic_fetch_dec_int32(&tile->super.super.super.obj_reference_count)) {
assert(tile->flushed == FLUSHED);
if(tile->dc->data_of_key == parsec_dtd_tile_new_dc_data_of_key) {
// This is a tile_new, we need to collect everything that it points to
Expand Down Expand Up @@ -1282,7 +1282,7 @@ parsec_dtd_tile_of(parsec_data_collection_t *dc, parsec_data_key_t key)
}
assert(tile->flushed == NOT_FLUSHED);
#if defined(PARSEC_DEBUG_PARANOID)
assert(tile->super.super.obj_reference_count > 0);
assert(tile->super.super.super.obj_reference_count > 0);
#endif
return tile;
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ parsec_dtd_tile_t *parsec_dtd_tile_new(parsec_taskpool_t *tp, int rank)
SET_LAST_ACCESSOR(tile);

#if defined(PARSEC_DEBUG_PARANOID)
assert(tile->super.super.obj_reference_count > 0);
assert(tile->super.super.super.obj_reference_count > 0);
#endif
return tile;
}
Expand Down Expand Up @@ -1852,7 +1852,7 @@ parsec_hook_return_t
parsec_dtd_release_local_task(parsec_dtd_task_t *this_task)
{
parsec_object_t *object = (parsec_object_t *)this_task;
assert(this_task->super.super.super.obj_reference_count > 1);
assert(this_task->super.super.super.super.obj_reference_count > 1);
if( 2 == parsec_atomic_fetch_dec_int32(&object->obj_reference_count)) {
int current_flow;
for( current_flow = 0; current_flow < this_task->super.task_class->nb_flows; current_flow++ ) {
Expand All @@ -1870,7 +1870,7 @@ parsec_dtd_release_local_task(parsec_dtd_task_t *this_task)
parsec_dtd_tile_release(tile);
}
}
assert(this_task->super.super.super.obj_reference_count == 1);
assert(this_task->super.super.super.super.obj_reference_count == 1);
parsec_thread_mempool_free(this_task->mempool_owner, this_task);
}
return PARSEC_HOOK_RETURN_DONE;
Expand Down Expand Up @@ -1916,7 +1916,7 @@ parsec_dtd_remote_task_release(parsec_dtd_task_t *this_task)
parsec_dtd_tile_release(tile);
}
}
assert(this_task->super.super.super.obj_reference_count == 1);
assert(this_task->super.super.super.super.obj_reference_count == 1);
parsec_taskpool_t *tp = this_task->super.taskpool;
parsec_thread_mempool_free(this_task->mempool_owner, this_task);
parsec_taskpool_update_runtime_nbtask(tp, -1);
Expand Down
Loading