| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
- c This file is part of the StarPU Handbook.
- 'e de Bordeaux 1
- c Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
- menu
- * Defining a new data interface::
- * Multiformat Data Interface::
- * Task Bundles::
- * Task Lists::
- * Using Parallel Tasks::
- * Defining a new scheduling policy::
- * Running drivers::
- * Expert mode::
- node Defining a new data interface
- menu
- * Data Interface API:: Data Interface API
- * An example of data interface:: An example of data interface
- node Data Interface API
- deftp {Data Type} {struct starpu_data_interface_ops}
- table
- item
- item
- item
- item
- item
- item
- item
- item
- item
- item
- item
- item
- item
- item
- code{ptr}
- code{int (*unpack_data)(starpu_data_handle_t handle, uint32_t node, void *ptr)}
- Unpack the data handle from the contiguous buffer at the address
- end table
- deftp {Data Type} {struct starpu_data_copy_methods}
- Defines the per-interface methods.
- asis
- code{int }_to_}(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node)}
- These 16 functions define how to copy data from the
- var{src_node} node to the
- var{dst_node} node. They return 0 on success.
- code{int (*ram_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
- Define how to copy data from the
- var{src_node} node (in RAM) to the
- var{dst_node} node (on a CUDA device), using the given
- item
- var{src_interface} interface on the
- var{dst_interface} interface on the
- var{stream}. Return 0
- on success.
- code{int (*cuda_to_cuda_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream)}
- Define how to copy data from the
- var{src_node} node (on a CUDA device) to the
- var{dst_node} node (on another CUDA device), using the given
- item
- var{src_interface} interface on the
- var{dst_interface} interface on the
- var{event}, a pointer to a
- cl_event. Return 0 on success.
- code{int (*opencl_to_ram_async)(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, void *event)}
- Define how to copy data from the
- var{src_node} node (on an OpenCL device) to the
- var{dst_node} node (in RAM), using the given
- item
- var{src_interface} interface on the
- var{dst_interface} interface
- on the
- var{event}, a pointer to a cl_event. Return 0 on success.
- end deftp
- var{input}, size_t var{inputcrc})
- Compute the CRC of a byte buffer seeded by the inputcrc "current
- state". The return value should be considered as the new "current
- state" for future CRC computation. This is used for computing data size
- footprint.
- deftypefun uint32_t starpu_crc32_be (uint32_t var{inputcrc})
- Compute the CRC of a 32bit number seeded by the inputcrc "current
- state". The return value should be considered as the new "current
- state" for future CRC computation. This is used for computing data size
- footprint.
- deftypefun uint32_t starpu_crc32_string ({char *}var{inputcrc})
- Compute the CRC of a string seeded by the inputcrc "current state".
- The return value should be considered as the new "current state" for
- future CRC computation. This is used for computing data size footprint.
- node An example of data interface
- deftypefun int starpu_data_interface_get_next_id (void)
- Returns the next available id for a newly created data interface.
- cartouche
- {
- double *real;
- double *imaginary;
- int nx;
- end smallexample
- code{starpu_data_register} (
- code{interface_complex_ops}, will be
- described below.
- smallexample
- void starpu_complex_data_register(starpu_data_handle_t *handle,
- uint32_t home_node, double *real, double *imaginary, int nx)
- {
- .real = real,
- .imaginary = imaginary,
- .nx = nx
-
- {
- interface_complex_ops.interfaceid = starpu_data_interface_get_next_id();
-
- }
- end cartouche
- Different operations need to be defined for a data interface through
- the type pxref{Data
- Interface API}). We only define here the basic operations needed to
- run simple applications. The source code for the different functions
- can be found in the file
- cartouche
- {
- .register_data_handle = complex_register_data_handle,
- .allocate_data_on_node = complex_allocate_data_on_node,
- .copy_methods = &complex_copy_methods,
- .get_size = complex_get_size,
- .footprint = complex_footprint,
- .interfaceid = -1,
- .interface_size = sizeof(struct starpu_complex_interface),
- end smallexample
- cartouche
- {
- struct starpu_complex_interface *complex_interface =
- (struct starpu_complex_interface *) starpu_data_get_interface_on_node(handle, 0);
- return complex_interface->real;
- end smallexample
- code{void *} pointer to be used within codelet
- implemetations.
- smallexample
- #define STARPU_COMPLEX_GET_REAL(interface) \
- (((struct starpu_complex_interface *)(interface))->real)
- #define STARPU_COMPLEX_GET_IMAGINARY(interface) \
- (((struct starpu_complex_interface *)(interface))->imaginary)
- #define STARPU_COMPLEX_GET_NX(interface) \
- (((struct starpu_complex_interface *)(interface))->nx)
- end cartouche
- Complex data interfaces can then be registered to StarPU.
- smallexample
- double real = 45.0;
- double imaginary = 12.0;
- starpu_complex_data_register(&handle1, 0, &real, &imaginary, 1);
- starpu_insert_task(&cl_display, STARPU_R, handle1, 0);
- end cartouche
- and used by codelets.
- smallexample
- void display_complex_codelet(void *descr[], __attribute__ ((unused)) void *_args)
- {
- fprintf(stderr, "Complex[%d] = %3.2f + %3.2f i\n", i, real[i], imaginary[i]);
-
- }
- end cartouche
- The whole code for this complex data interface is available in the
- directory
- node Multiformat Data Interface
- deftp {Data Type} {struct starpu_multiformat_data_interface_ops}
- The different fields are:
- asis
- code{size_t cpu_elemsize}
- the size of each element on CPUs,
- code{size_t opencl_elemsize}
- the size of each element on OpenCL devices,
- code{struct starpu_codelet *cpu_to_opencl_cl}
- pointer to a codelet which converts from CPU to OpenCL
- code{struct starpu_codelet *opencl_to_cpu_cl}
- pointer to a codelet which converts from OpenCL to CPU
- code{size_t cuda_elemsize}
- the size of each element on CUDA devices,
- code{struct starpu_codelet *cpu_to_cuda_cl}
- pointer to a codelet which converts from CPU to CUDA
- code{struct starpu_codelet *cuda_to_cpu_cl}
- pointer to a codelet which converts from CUDA to CPU
- end deftp
- var{handle}, uint32_t var{ptr}, uint32_t var{format_ops})
- Register a piece of data that can be represented in different ways, depending upon
- the processing unit that manipulates it. It allows the programmer, for instance, to
- use an array of structures when working on a CPU, and a structure of arrays when
- working on a GPU.
- var{format_ops} describes
- the format.
- defmac STARPU_MULTIFORMAT_GET_CPU_PTR ({void *}
- end defmac
- var{interface})
- returns the local pointer to the data with CUDA format.
- defmac STARPU_MULTIFORMAT_GET_OPENCL_PTR ({void *}
- end defmac
- var{interface})
- returns the number of elements in the data.
- node Task Bundles
- deftp {Data Type} {starpu_task_bundle_t}
- Opaque structure describing a list of tasks that should be scheduled
- on the same worker whenever it's possible. It must be considered as a
- hint given to the scheduler as there is no guarantee that they will be
- executed on the same worker.
- deftypefun void starpu_task_bundle_create ({starpu_task_bundle_t *}
- var{bundle}, when the call returns, memory needed is allocated and
- end deftypefun
- var{bundle}, {struct starpu_task *}
- var{task} in var{task} is removed from var{bundle}.
- This function mustn't be called if var{task} is already submitted.
- deftypefun int starpu_task_bundle_remove (starpu_task_bundle_t var{task})
- Remove var{bundle}.
- Of course var{bundle}.
- This function mustn't be called if var{task} is already submitted. Doing so would result in undefined behaviour.
- deftypefun void starpu_task_bundle_close (starpu_task_bundle_t
- var{bundle} anymore, it means no more inserting or removing task. Thus the runtime can destroy it when possible.
- deftypefun double starpu_task_bundle_expected_length (starpu_task_bundle_t var{arch}, unsigned
- end deftypefun
- var{bundle}, enum starpu_perf_archtype var{nimpl})
- Return the expected power consumption of the entire task bundle in J.
- deftypefun double starpu_task_bundle_expected_data_transfer_time (starpu_task_bundle_t var{memory_node})
- Return the time (in µs) expected to transfer all data used within the bundle.
- node Task Lists
- deftp {Data Type} {struct starpu_task_list}
- Stores a double-chained list of tasks
- deftypefun void starpu_task_list_init ({struct starpu_task_list *}
- end deftypefun
- var{list}, {struct starpu_task *}
- end deftypefun
- var{list}, {struct starpu_task *}
- end deftypefun
- var{list})
- Get the front of the list (without removing it)
- deftypefun {struct starpu_task *} starpu_task_list_back ({struct starpu_task_list *}
- end deftypefun
- var{list})
- Test if a list is empty
- deftypefun void starpu_task_list_erase ({struct starpu_task_list *}var{task})
- Remove an element from the list
- deftypefun {struct starpu_task *} starpu_task_list_pop_front ({struct starpu_task_list *}
- end deftypefun
- var{list})
- Remove the element at the back of the list
- deftypefun {struct starpu_task *} starpu_task_list_begin ({struct starpu_task_list *}
- end deftypefun
- var{list})
- Get the end of the list.
- deftypefun {struct starpu_task *} starpu_task_list_next ({struct starpu_task *}
- end deftypefun
- section Using Parallel Tasks
- These are used by parallel tasks:
- end deftypefun
- end deftypefun
- Most of these are used for schedulers which support parallel tasks.
- end deftypefun
- end deftypefun
- var{nworkers}, int
- end deftypefun
- var{workerid}, {int *}var{combined_workerid})
- Get the description of a combined worker
- deftypefun int starpu_combined_worker_can_execute_task (unsigned var{task}, unsigned
- end deftypefun
- section Defining a new scheduling policy
- TODO
- A full example showing how to define a new scheduling policy is available in
- the StarPU sources in the directory
- menu
- * Scheduling Policy API:: Scheduling Policy API
- * Source code::
- node Scheduling Policy API
- pxref{Task
- scheduling policy}), it may sometimes be desirable to implement custom
- policies to address specific problems. The API described below allows
- users to write their own scheduling policy.
- table
- item
- item
- item
- code{void *dummy}
- code{unsigned nhwcpus}
- Total number of CPUs, as detected by the topology code. May be different from
- the actual number of CPU workers.
- code{unsigned nhwcudagpus}
- Total number of CUDA devices, as detected. May be different from the actual
- number of CUDA workers.
- code{unsigned nhwopenclgpus}
- Total number of OpenCL devices, as detected. May be different from the actual
- number of CUDA workers.
- code{unsigned ncpus}
- Actual number of CPU workers used by StarPU.
- code{unsigned ncudagpus}
- Actual number of CUDA workers used by StarPU.
- code{unsigned nopenclgpus}
- Actual number of OpenCL workers used by StarPU.
- code{unsigned workers_bindid[STARPU_NMAXWORKERS]}
- Indicates the successive cpu identifier that should be used to bind the
- workers. It is either filled according to the user's explicit
- parameters (from starpu_conf) or according to the STARPU_WORKERS_CPUID env.
- variable. Otherwise, a round-robin policy is used to distributed the workers
- over the cpus.
- code{unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS]}
- Indicates the successive cpu identifier that should be used by the CUDA
- driver. It is either filled according to the user's explicit parameters (from
- starpu_conf) or according to the STARPU_WORKERS_CUDAID env. variable. Otherwise,
- they are taken in ID order.
- code{unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS]}
- Indicates the successive cpu identifier that should be used by the OpenCL
- driver. It is either filled according to the user's explicit parameters (from
- starpu_conf) or according to the STARPU_WORKERS_OPENCLID env. variable. Otherwise,
- they are taken in ID order.
- end deftp
- code{sched_policy}
- field of the code{starpu_init}
- function. The different fields are:
- asis
- code{void (*init_sched)(struct starpu_machine_topology *, struct starpu_sched_policy *)}
- Initialize the scheduling policy.
- code{void (*deinit_sched)(struct starpu_machine_topology *, struct starpu_sched_policy *)}
- Cleanup the scheduling policy.
- code{int (*push_task)(struct starpu_task *)}
- Insert a task into the scheduler.
- code{void (*push_task_notify)(struct starpu_task *, int workerid)}
- Notify the scheduler that a task was pushed on a given worker. This method is
- called when a task that was explicitely assigned to a worker becomes ready and
- is about to be executed by the worker. This method therefore permits to keep
- the state of of the scheduler coherent even when StarPU bypasses the scheduling
- strategy.
- code{struct starpu_task *(*pop_task)(void)} (optional)
- Get a task from the scheduler. The mutex associated to the worker is already
- taken when this method is called. If this method is defined as
- code{push_task} method should use the
- item
- item
- item
- item
- item
- end table
- deftypefun void starpu_worker_set_sched_condition (int var{sched_cond}, pthread_mutex_t *
- code{init_sched}) must
- call this function once per worker.
- deftypefun void starpu_sched_set_min_priority (int
- code{starpu_sched_get_min_priority} function. This function should only be
- called from the initialization method of the scheduling policy, and should not
- be used directly from the application.
- deftypefun void starpu_sched_set_max_priority (int
- code{starpu_sched_get_max_priority} function. This function should
- only be called from the initialization method of the scheduling policy, and
- should not be used directly from the application.
- deftypefun int starpu_sched_get_min_priority (void)
- Returns the current minimum priority level supported by the
- scheduling policy
- deftypefun int starpu_sched_get_max_priority (void)
- Returns the current maximum priority level supported by the
- scheduling policy
- deftypefun int starpu_push_local_task (int var{task}, int
- var{back} not null,
- var{back} to 0 therefore ensures
- a FIFO ordering.
- deftypefun int starpu_worker_can_execute_task (unsigned var{task}, unsigned {nimpl})
- Check if the worker specified by workerid can execute the codelet. Schedulers need to call it before assigning a task to a worker, otherwise the task may fail to execute.
- deftypefun double starpu_timing_now (void)
- Return the current date in µs
- deftypefun double starpu_task_expected_length ({struct starpu_task *}var{arch}, unsigned
- end deftypefun
- var{perf_archtype})
- Returns an estimated speedup factor relative to CPU speed
- deftypefun double starpu_task_expected_data_transfer_time (uint32_t var{task})
- Returns expected data transfer time in µs
- deftypefun double starpu_data_expected_transfer_time (starpu_data_handle_t var{memory_node}, {enum starpu_access_mode}
- end deftypefun
- var{task}, {enum starpu_perf_archtype} var{nimpl})
- Returns expected power consumption in J
- deftypefun double starpu_task_expected_conversion_time ({struct starpu_task *}var{arch}, unsigned {nimpl})
- Returns expected conversion time in ms (multiformat interface only)
- node Source code
- cartouche
- {
- .init_sched = init_dummy_sched,
- .deinit_sched = deinit_dummy_sched,
- .push_task = push_task_dummy,
- .push_prio_task = NULL,
- .pop_task = pop_task_dummy,
- .post_exec_hook = NULL,
- .pop_every_task = NULL,
- .policy_name = "dummy",
- .policy_description = "dummy scheduling strategy"
- end smallexample
- node Running drivers
- menu
- * Driver API::
- * Example::
- node Driver API
- deftypefun int starpu_driver_run ({struct starpu_driver *}
- code{d->type}
- is not a valid StarPU device type (STARPU_CPU_WORKER, STARPU_CUDA_WORKER or
- STARPU_OPENCL_WORKER). This is the same as using the following
- functions: calling
- code{starpu_driver_run_once()} in a loop, and eventually
- end deftypefun
- var{d})
- Initialize the given driver. Returns 0 on success, -EINVAL if
- end deftypefun
- var{d})
- Run the driver once, then returns 0 on success, -EINVAL if
- end deftypefun
- var{d})
- Deinitialize the given driver. Returns 0 on success, -EINVAL if
- end deftypefun
- end deftypefun
- subsection Example
- smallexample
- int ret;
- struct starpu_driver =
- };
- ret = starpu_driver_init(&d);
- if (ret != 0)
- error();
- while (some_condition)
- }
- ret = starpu_driver_deinit(&d);
- if (ret != 0)
- error();
- end cartouche
- section Expert mode
- end deftypefun
- var{func})(void *arg), void *
- end deftypefun
- var{hook_id})
- Unregister a given progression hook.
|