Beatmup
Beatmup::Multitask Class Reference

Conditional multiple tasks execution. More...

#include <multitask.h>

Inheritance diagram for Beatmup::Multitask:
Beatmup::CustomPipeline Beatmup::AbstractTask Beatmup::Object

Public Types

enum class  RepetitionPolicy { REPEAT_ALWAYS , REPEAT_UPDATE , IGNORE_IF_UPTODATE , IGNORE_ALWAYS }
 Determines when a specific task in the sequence is run when the whole sequence is invoked. More...
 
- Public Types inherited from Beatmup::AbstractTask
enum class  TaskDeviceRequirement { CPU_ONLY , GPU_OR_CPU , GPU_ONLY }
 Specifies which device (CPU and/or GPU) is used to run the task. More...
 

Public Member Functions

 Multitask ()
 
RepetitionPolicy getRepetitionPolicy (const TaskHolder &)
 
void setRepetitionPolicy (TaskHolder &taskHolder, RepetitionPolicy policy)
 Sets repetition policy of a task. More...
 
- Public Member Functions inherited from Beatmup::CustomPipeline
 ~CustomPipeline ()
 
int getTaskCount () const
 
TaskHoldergetTask (int) const
 Retrieves a task by its index. More...
 
int getTaskIndex (const TaskHolder &)
 Retrieves task index if it is in the pipeline; returns -1 otherwise. More...
 
TaskHolderaddTask (AbstractTask &)
 Adds a new task to the end of the pipeline. More...
 
TaskHolderinsertTask (AbstractTask &task, const TaskHolder &before)
 Inserts a task in a specified position of the pipeline before another task. More...
 
bool removeTask (const TaskHolder &task)
 Removes a task from the pipeline. More...
 
void measure ()
 Determines pipeline execution mode and required thread count. More...
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Protected Member Functions

TaskHoldercreateTaskHolder (AbstractTask &task)
 
bool route (TaskRouter &router)
 
- Protected Member Functions inherited from Beatmup::CustomPipeline
TaskDeviceRequirement getUsedDevices () const
 Communicates devices (CPU and/or GPU) the task is run on. More...
 
ThreadIndex getMaxThreads () const
 Gives the upper limint on the number of threads the task may be performed by. More...
 
void beforeProcessing (ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
 Instruction called before the task is executed. More...
 
void afterProcessing (ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
 Instruction called after the task is executed. More...
 
bool process (TaskThread &thread)
 Executes the task on CPU within a given thread. More...
 
bool processOnGPU (GraphicPipeline &gpu, TaskThread &thread)
 Executes the task on GPU. More...
 
 CustomPipeline ()
 

Private Attributes

std::mutex policyAccess
 access control to modify repetition policies More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 

Detailed Description

Conditional multiple tasks execution.

Multitask is a technique to build complex multi-stage image processing pipelines. It allows to concatenate different tasks into a linear conveyor and run them all or selectively. To handle this selection, each task is associated with a repetition policy specifying the conditions whether this given task is executed or ignored when the pipeline is running.

Specifically, it implements two extreme modes that force the task execution every time (Multitask::RepetitionPolicy::REPEAT_ALWAYS) or its unconditional skipping (Multitask::RepetitionPolicy::IGNORE_ALWAYS) and two more sophisticated modes:

Definition at line 48 of file multitask.h.

Member Enumeration Documentation

◆ RepetitionPolicy

Determines when a specific task in the sequence is run when the whole sequence is invoked.

Enumerator
REPEAT_ALWAYS 

execute the task unconditionally on each run

REPEAT_UPDATE 

execute the task one time then switch to IGNORE_IF_UPTODATE

IGNORE_IF_UPTODATE 

do not execute the task if no preceding tasks are run

IGNORE_ALWAYS 

do not execute the task

Definition at line 60 of file multitask.h.

60  {
61  REPEAT_ALWAYS, //!< execute the task unconditionally on each run
62  REPEAT_UPDATE, //!< execute the task one time then switch to IGNORE_IF_UPTODATE
63  IGNORE_IF_UPTODATE, //!< do not execute the task if no preceding tasks are run
64  IGNORE_ALWAYS //!< do not execute the task
65  };

Constructor & Destructor Documentation

◆ Multitask()

Multitask::Multitask ( )

Definition at line 76 of file multitask.cpp.

76 {}

Member Function Documentation

◆ createTaskHolder()

CustomPipeline::TaskHolder * Multitask::createTaskHolder ( AbstractTask task)
protectedvirtual

Implements Beatmup::CustomPipeline.

Definition at line 42 of file multitask.cpp.

42  {
44 }
TaskHolder implementation for Multitask pipeline.
Definition: multitask.cpp:30
Beatmup::NNets::InferenceTask * task

◆ route()

bool Multitask::route ( TaskRouter router)
protectedvirtual

Implements Beatmup::CustomPipeline.

Definition at line 46 of file multitask.cpp.

46  {
47  // skip tasks that are "ignored"
48  {
49  std::lock_guard<std::mutex> lock(policyAccess);
50  while (!router.allTasksDone()) {
51  RepetitionPolicy policy = static_cast<const Internal::MultitaskTaskHolder&>(router.getCurrentTask()).repetitionPolicy;
53  break;
54  router.goToNextTask();
55  }
56  }
57 
58  // then go
59  while (!router.allTasksDone() && !router.allTasksAborted()) {
61  if (task.repetitionPolicy != RepetitionPolicy::IGNORE_ALWAYS)
62  router.runTask();
63 
64  // switch repetition policy if needed
65  policyAccess.lock();
66  if (task.repetitionPolicy == RepetitionPolicy::REPEAT_UPDATE)
67  task.repetitionPolicy = RepetitionPolicy::IGNORE_IF_UPTODATE;
68  policyAccess.unlock();
69 
70  router.goToNextTask();
71  }
72 
73  return true;
74 }
std::mutex policyAccess
access control to modify repetition policies
Definition: multitask.h:50
RepetitionPolicy
Determines when a specific task in the sequence is run when the whole sequence is invoked.
Definition: multitask.h:60
@ IGNORE_IF_UPTODATE
do not execute the task if no preceding tasks are run
@ REPEAT_ALWAYS
execute the task unconditionally on each run
@ IGNORE_ALWAYS
do not execute the task
@ REPEAT_UPDATE
execute the task one time then switch to IGNORE_IF_UPTODATE
virtual void goToNextTask()=0
Goes to the next task in the list.
virtual void runTask()=0
Executes the pointed task.
virtual CustomPipeline::TaskHolder & getCurrentTask()=0
Returns currently pointed task.
virtual bool allTasksDone() const =0
Returns true if all tasks are done.
virtual bool allTasksAborted() const =0
Returns true if the current session is aborted.
jlong jlong jint policy

◆ getRepetitionPolicy()

Multitask::RepetitionPolicy Multitask::getRepetitionPolicy ( const TaskHolder task)
Returns
repetition policy of a specific task in the pipeline.

Definition at line 78 of file multitask.cpp.

79 {
81  std::lock_guard<std::mutex> lock(policyAccess);
82  return ((const Internal::MultitaskTaskHolder&)task).repetitionPolicy;
83 }
int getTaskIndex(const TaskHolder &)
Retrieves task index if it is in the pipeline; returns -1 otherwise.
#define BEATMUP_ASSERT_DEBUG(C)
Definition: exception.h:163

◆ setRepetitionPolicy()

void Multitask::setRepetitionPolicy ( TaskHolder taskHolder,
RepetitionPolicy  policy 
)

Sets repetition policy of a task.

If the pipeline is processing at the moment of the call, it is the application responsibility to abort and restart it, if the policy change needs to be applied immediately.

Parameters
taskHolderTaskHolder of a task to apply the policy to
policyThe new policy

Definition at line 85 of file multitask.cpp.

85  {
87  std::lock_guard<std::mutex> lock(policyAccess);
88  static_cast<Internal::MultitaskTaskHolder&>(taskHolder).repetitionPolicy = policy;
89 }
return pipeline getTaskIndex * taskHolder

Member Data Documentation

◆ policyAccess

std::mutex Beatmup::Multitask::policyAccess
private

access control to modify repetition policies

Definition at line 50 of file multitask.h.


The documentation for this class was generated from the following files: