/* StarPU --- Runtime system for heterogeneous multicore architectures. * * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria * * StarPU is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * StarPU is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License in COPYING.LGPL for more details. */ #ifndef __STARPU_TASK_UTIL_H__ #define __STARPU_TASK_UTIL_H__ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /** @defgroup API_Insert_Task Task Insert Utility @{ */ /* NOTE: when adding a value here, please make sure to update both * src/util/starpu_task_insert_utils.c (in two places) and * mpi/src/starpu_mpi_task_insert.c and mpi/src/starpu_mpi_task_insert_fortran.c */ #define STARPU_MODE_SHIFT 17 /** Used when calling starpu_task_insert(), must be followed by a pointer to a constant value and the size of the constant */ #define STARPU_VALUE (1<MUST explicitly cast into double, otherwise parameter passing will not work. */ #define STARPU_FLOPS (12<
  • ::STARPU_R, ::STARPU_W, ::STARPU_RW, ::STARPU_SCRATCH, ::STARPU_REDUX an access mode followed by a data handle;
  • ::STARPU_DATA_ARRAY followed by an array of data handles and its number of elements;
  • ::STARPU_DATA_MODE_ARRAY followed by an array of struct starpu_data_descr, i.e data handles with their associated access modes, and its number of elements;
  • ::STARPU_EXECUTE_ON_WORKER, ::STARPU_WORKER_ORDER followed by an integer value specifying the worker on which to execute the task (as specified by starpu_task::execute_on_a_specific_worker)
  • the specific values ::STARPU_VALUE, ::STARPU_CALLBACK, ::STARPU_CALLBACK_ARG, ::STARPU_CALLBACK_WITH_ARG, ::STARPU_PRIORITY, ::STARPU_TAG, ::STARPU_TAG_ONLY, ::STARPU_FLOPS, ::STARPU_SCHED_CTX, ::STARPU_CL_ARGS, ::STARPU_CL_ARGS_NFREE, ::STARPU_TASK_DEPS_ARRAY, ::STARPU_TASK_COLOR, ::STARPU_HANDLES_SEQUENTIAL_CONSISTENCY, ::STARPU_TASK_SYNCHRONOUS, ::STARPU_TASK_END_DEP followed by the appropriated objects as defined elsewhere. When using ::STARPU_DATA_ARRAY, the access mode of the data handles is not defined, it will be taken from the codelet starpu_codelet::modes or starpu_codelet::dyn_modes field. One should use ::STARPU_DATA_MODE_ARRAY to define the data handles along with the access modes. Parameters to be passed to the codelet implementation are defined through the type ::STARPU_VALUE. The function starpu_codelet_unpack_args() must be called within the codelet implementation to retrieve them. */ int starpu_task_insert(struct starpu_codelet *cl, ...); #ifdef STARPU_USE_FXT #define starpu_task_insert(cl, ...) \ starpu_task_insert((cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__) #endif /** Similar to starpu_task_insert(). Kept to avoid breaking old codes. */ int starpu_insert_task(struct starpu_codelet *cl, ...); #ifdef STARPU_USE_FXT #define starpu_insert_task(cl, ...) \ starpu_insert_task((cl), STARPU_TASK_FILE, __FILE__, STARPU_TASK_LINE, __LINE__, ##__VA_ARGS__) #endif /** Assuming that there are already \p current_buffer data handles passed to the task, and if *allocated_buffers is not 0, the task->dyn_handles array has size \p *allocated_buffers, this function makes room for \p room other data handles, allocating or reallocating task->dyn_handles as necessary and updating \p *allocated_buffers accordingly. One can thus start with *allocated_buffers equal to 0 and current_buffer equal to 0, then make room by calling this function, then store handles with STARPU_TASK_SET_HANDLE(), make room again with this function, store yet more handles, etc. */ void starpu_task_insert_data_make_room(struct starpu_codelet *cl, struct starpu_task *task, int *allocated_buffers, int current_buffer, int room); /** Store data handle \p handle into task \p task with mode \p arg_type, updating \p *allocated_buffers and \p *current_buffer accordingly. */ void starpu_task_insert_data_process_arg(struct starpu_codelet *cl, struct starpu_task *task, int *allocated_buffers, int *current_buffer, int arg_type, starpu_data_handle_t handle); /** Store \p nb_handles data handles \p handles into task \p task, updating \p *allocated_buffers and \p *current_buffer accordingly. */ void starpu_task_insert_data_process_array_arg(struct starpu_codelet *cl, struct starpu_task *task, int *allocated_buffers, int *current_buffer, int nb_handles, starpu_data_handle_t *handles); /** Store \p nb_descrs data handles described by \p descrs into task \p task, updating \p *allocated_buffers and \p *current_buffer accordingly. */ void starpu_task_insert_data_process_mode_array_arg(struct starpu_codelet *cl, struct starpu_task *task, int *allocated_buffers, int *current_buffer, int nb_descrs, struct starpu_data_descr *descrs); /** Pack arguments of type ::STARPU_VALUE into a buffer which can be given to a codelet and later unpacked with the function starpu_codelet_unpack_args(). Instead of calling starpu_codelet_pack_args(), one can also call starpu_codelet_pack_arg_init(), then starpu_codelet_pack_arg() for each data, then starpu_codelet_pack_arg_fini(). */ void starpu_codelet_pack_args(void **arg_buffer, size_t *arg_buffer_size, ...); /** Structure to be used for starpu_codelet_pack_arg_init() & co, and starpu_codelet_unpack_arg_init() & co. The contents is public, however users should not directly access it, but only use as a parameter to the appropriate functions. */ struct starpu_codelet_pack_arg_data { char *arg_buffer; size_t arg_buffer_size; size_t current_offset; int nargs; }; /** Initialize struct starpu_codelet_pack_arg before calling starpu_codelet_pack_arg() and starpu_codelet_pack_arg_fini(). This will simply initialize the content of the structure. */ void starpu_codelet_pack_arg_init(struct starpu_codelet_pack_arg_data *state); /** Pack one argument into struct starpu_codelet_pack_arg \p state. That structure has to be initialized before with starpu_codelet_pack_arg_init(), and after all starpu_codelet_pack_arg() calls performed, starpu_codelet_pack_arg_fini() has to be used to get the \p cl_arg and \p cl_arg_size to be put in the task. */ void starpu_codelet_pack_arg(struct starpu_codelet_pack_arg_data *state, const void *ptr, size_t ptr_size); /** Finish packing data, after calling starpu_codelet_pack_arg_init() once and starpu_codelet_pack_arg() several times. */ void starpu_codelet_pack_arg_fini(struct starpu_codelet_pack_arg_data *state, void **cl_arg, size_t *cl_arg_size); /** Retrieve the arguments of type ::STARPU_VALUE associated to a task automatically created using the function starpu_task_insert(). If any parameter's value is 0, unpacking will stop there and ignore the remaining parameters. */ void starpu_codelet_unpack_args(void *cl_arg, ...); /** Initialize \p state with \p cl_arg and \p cl_arg_size. This has to be called before calling starpu_codelet_unpack_arg(). */ void starpu_codelet_unpack_arg_init(struct starpu_codelet_pack_arg_data *state, void *cl_arg, size_t cl_arg_size); /** Unpack the next argument of size \p size from \p state into \p ptr with a copy. \p state has to be initialized before with starpu_codelet_unpack_arg_init(). */ void starpu_codelet_unpack_arg(struct starpu_codelet_pack_arg_data *state, void *ptr, size_t size); /** Unpack the next argument of unknown size from \p state into \p ptr with a copy. \p ptr is allocated before copying in it the value of the argument. The size of the argument is returned in \p size. \p has to be initialized before with starpu_codelet_unpack_arg_init(). */ void starpu_codelet_dup_arg(struct starpu_codelet_pack_arg_data *state, void **ptr, size_t *size); /** Unpack the next argument of unknown size from \p state into \p ptr. \p ptr will be a pointer to the memory of the argument. The size of the argument is returned in \p size. \p has to be initialized before with starpu_codelet_unpack_arg_init(). */ void starpu_codelet_pick_arg(struct starpu_codelet_pack_arg_data *state, void **ptr, size_t *size); /** Finish unpacking data, after calling starpu_codelet_unpack_arg_init() once and starpu_codelet_unpack_arg() or starpu_codelet_dup_arg() or starpu_codelet_pick_arg() several times. */ void starpu_codelet_unpack_arg_fini(struct starpu_codelet_pack_arg_data *state); /** Call this function during unpacking to skip saving the argument in ptr. */ void starpu_codelet_unpack_discard_arg(struct starpu_codelet_pack_arg_data *state); /** Similar to starpu_codelet_unpack_args(), but if any parameter is 0, copy the part of \p cl_arg that has not been read in \p buffer which can then be used in a later call to one of the unpack functions. */ void starpu_codelet_unpack_args_and_copyleft(void *cl_arg, void *buffer, size_t buffer_size, ...); /** @} */ #ifdef __cplusplus } #endif #endif /* __STARPU_TASK_UTIL_H__ */