Beatmup
Beatmup::CustomPipeline Class Referenceabstract

Custom pipeline: a sequence of tasks to be executed as a whole. More...

#include <custom_pipeline.h>

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

Classes

class  Impl
 
class  PipelineNotReady
 
class  TaskHolder
 A task within a pipeline. More...
 

Public Member Functions

 ~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

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...
 
virtual TaskHoldercreateTaskHolder (AbstractTask &task)=0
 
virtual bool route (TaskRouter &router)=0
 
 CustomPipeline ()
 

Private Attributes

Implimpl
 

Additional Inherited Members

- 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...
 
- Static Public Member Functions inherited from Beatmup::AbstractTask
static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 

Detailed Description

Custom pipeline: a sequence of tasks to be executed as a whole.

Acts as an AbstractTask. Built by adding tasks one by one and calling measure() at the end.

Definition at line 32 of file custom_pipeline.h.

Constructor & Destructor Documentation

◆ CustomPipeline()

CustomPipeline::CustomPipeline ( )
protected

Definition at line 243 of file custom_pipeline.cpp.

243  :
244  impl(new Impl())
245 {}

◆ ~CustomPipeline()

CustomPipeline::~CustomPipeline ( )

Definition at line 247 of file custom_pipeline.cpp.

247  {
248  delete impl;
249 }

Member Function Documentation

◆ getUsedDevices()

AbstractTask::TaskDeviceRequirement CustomPipeline::getUsedDevices ( ) const
protectedvirtual

Communicates devices (CPU and/or GPU) the task is run on.

Reimplemented from Beatmup::AbstractTask.

Definition at line 219 of file custom_pipeline.cpp.

219  {
220  return impl->getUsedDevices();
221 }
AbstractTask::TaskDeviceRequirement getUsedDevices() const

◆ getMaxThreads()

ThreadIndex CustomPipeline::getMaxThreads ( ) const
protectedvirtual

Gives the upper limint on the number of threads the task may be performed by.

The actual number of threads running a specific task may be less or equal to the returned value, depending on the number of workers in ThreadPool running the task.

Reimplemented from Beatmup::AbstractTask.

Definition at line 223 of file custom_pipeline.cpp.

223  {
224  return impl->getMaxThreads();
225 }
ThreadIndex getMaxThreads() const

◆ beforeProcessing()

void CustomPipeline::beforeProcessing ( ThreadIndex  threadCount,
ProcessingTarget  target,
GraphicPipeline gpu 
)
protectedvirtual

Instruction called before the task is executed.

Parameters
threadCountNumber of threads used to perform the task
targetDevice used to perform the task
gpuA graphic pipeline instance; may be null.

Reimplemented from Beatmup::AbstractTask.

Definition at line 227 of file custom_pipeline.cpp.

227  {
228  impl->beforeProcessing(gpu);
229 }
void beforeProcessing(GraphicPipeline *gpu)

◆ afterProcessing()

void CustomPipeline::afterProcessing ( ThreadIndex  threadCount,
GraphicPipeline gpu,
bool  aborted 
)
protectedvirtual

Instruction called after the task is executed.

Parameters
threadCountNumber of threads used to perform the task
gpuGPU to be used to execute the task; may be null.
abortedtrue if the task was aborted

Reimplemented from Beatmup::AbstractTask.

Definition at line 231 of file custom_pipeline.cpp.

231  {
232  AbstractTask::afterProcessing(threadCount, gpu, aborted);
233 }
virtual void afterProcessing(ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
Instruction called after the task is executed.
Definition: parallelism.cpp:29

◆ process()

bool CustomPipeline::process ( TaskThread thread)
protectedvirtual

Executes the task on CPU within a given thread.

Generally called by multiple threads.

Parameters
threadassociated task execution context
Returns
true if the execution is finished correctly, false otherwise

Implements Beatmup::AbstractTask.

Definition at line 235 of file custom_pipeline.cpp.

235  {
236  return impl->process(nullptr, thread, *this);
237 }
bool process(GraphicPipeline *gpu, TaskThread &thread, CustomPipeline &pipeline)
Processing entry point.

◆ processOnGPU()

bool CustomPipeline::processOnGPU ( GraphicPipeline gpu,
TaskThread thread 
)
protectedvirtual

Executes the task on GPU.

Parameters
gpugraphic pipeline instance
threadassociated task execution context
Returns
true if the execution is finished correctly, false otherwise

Reimplemented from Beatmup::AbstractTask.

Definition at line 239 of file custom_pipeline.cpp.

239  {
240  return impl->process(&gpu, thread, *this);
241 }

◆ createTaskHolder()

virtual TaskHolder* Beatmup::CustomPipeline::createTaskHolder ( AbstractTask task)
protectedpure virtual

Implemented in Beatmup::Multitask.

◆ route()

virtual bool Beatmup::CustomPipeline::route ( TaskRouter router)
protectedpure virtual

Implemented in Beatmup::Multitask.

◆ getTaskCount()

int CustomPipeline::getTaskCount ( ) const
Returns
number of tasks in the pipeline

Definition at line 251 of file custom_pipeline.cpp.

251  {
252  return impl->getTaskCount();
253 }

◆ getTask()

CustomPipeline::TaskHolder & CustomPipeline::getTask ( int  index) const

Retrieves a task by its index.

Definition at line 255 of file custom_pipeline.cpp.

255  {
256  return *impl->getTask(index);
257 }
TaskHolder * getTask(int index)
jlong jint index

◆ getTaskIndex()

int CustomPipeline::getTaskIndex ( const TaskHolder task)

Retrieves task index if it is in the pipeline; returns -1 otherwise.

Definition at line 259 of file custom_pipeline.cpp.

259  {
260  return impl->getTaskIndex(&task);
261 }
int getTaskIndex(const TaskHolder *holder)
Beatmup::NNets::InferenceTask * task

◆ addTask()

CustomPipeline::TaskHolder & CustomPipeline::addTask ( AbstractTask task)

Adds a new task to the end of the pipeline.

Definition at line 263 of file custom_pipeline.cpp.

263  {
264  TaskHolder* holder = createTaskHolder(task);
265  impl->addTask(holder);
266  return *holder;
267 }
virtual TaskHolder * createTaskHolder(AbstractTask &task)=0
void addTask(TaskHolder *taskHolder)

◆ insertTask()

CustomPipeline::TaskHolder & CustomPipeline::insertTask ( AbstractTask task,
const TaskHolder before 
)

Inserts a task in a specified position of the pipeline before another task.

Parameters
taskThe task to insert
beforeTaskHolder specifying position of the task that will follow the newly inserted task
Returns
TaskHolder with the newly inserted task.

Definition at line 269 of file custom_pipeline.cpp.

269  {
270  TaskHolder* holder = createTaskHolder(task);
271  impl->insertTask(holder, &before);
272  return *holder;
273 }
void insertTask(TaskHolder *newbie, const TaskHolder *before)

◆ removeTask()

bool CustomPipeline::removeTask ( const TaskHolder task)

Removes a task from the pipeline.

Parameters
taskThe task to remove
Returns
true on success, false if this TaskHolder is not in the pipeline.

Definition at line 275 of file custom_pipeline.cpp.

275  {
276  return impl->removeTask(&task);
277 }
bool removeTask(const TaskHolder *target)

◆ measure()

void CustomPipeline::measure ( )

Determines pipeline execution mode and required thread count.

Definition at line 279 of file custom_pipeline.cpp.

279  {
280  impl->measure();
281 }
void measure()
Determining execution mode (GPU or CPU) and thread count for each task.

Member Data Documentation

◆ impl

Impl* Beatmup::CustomPipeline::impl
private

Definition at line 37 of file custom_pipeline.h.


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