Beatmup
Beatmup::AbstractTask Class Referenceabstract

Task: an operation that can be executed by multiple threads in parallel. More...

#include <parallelism.h>

Inheritance diagram for Beatmup::AbstractTask:
Beatmup::Object Beatmup::Audio::AbstractPlayback Beatmup::Audio::SignalPlot Beatmup::BitmapBinaryOperation Beatmup::BitmapFromChunk Beatmup::BitmapResampler Beatmup::CallbackTask Beatmup::Crop Beatmup::CustomPipeline Beatmup::DisplaySwitch Beatmup::Filters::PixelwiseFilter Beatmup::FloodFill Beatmup::FormatConverter Beatmup::GpuTask Beatmup::Metric Beatmup::TextureHandleFactory Internal::Recycler

Public Types

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

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

Static Public Member Functions

static ThreadIndex validThreadCount (int number)
 Valid thread count from a given integer value. More...
 

Detailed Description

Task: an operation that can be executed by multiple threads in parallel.

Before executing the task, ThreadPool queries the task concerning

  • the device (CPU or GPU) the task will be run on, by calling getUsedDevices(),
  • the maximum number of threads the task may be run in, by calling getMaxThreads(). By default the tasks run on CPU in a single thread. This behavior can be overridden in subclasses. The task has three main stages:
  • beforeProcessing() to prepare the operation. It is run in a single thread.
  • processOnGPU() and process() to execute the operation.
    • processOnGPU() is called from a single thread having access to the GPU.
    • process() is potentially called from multiple threads to run the operation on CPU. The number of theads is not greatr than what was returned by getMaxThreads().
  • afterProcessing() to tear down the operation. It is run in a single thread as well.

Definition at line 90 of file parallelism.h.

Member Enumeration Documentation

◆ TaskDeviceRequirement

Specifies which device (CPU and/or GPU) is used to run the task.

Enumerator
CPU_ONLY 

this task does not use GPU

GPU_OR_CPU 

this task uses GPU if it is available, but CPU fallback is possible

GPU_ONLY 

this task requires GPU, otherwise it cannot run

Definition at line 95 of file parallelism.h.

95  {
96  CPU_ONLY, //!< this task does not use GPU
97  GPU_OR_CPU, //!< this task uses GPU if it is available, but CPU fallback is possible
98  GPU_ONLY //!< this task requires GPU, otherwise it cannot run
99  };

Member Function Documentation

◆ beforeProcessing()

void AbstractTask::beforeProcessing ( ThreadIndex  threadCount,
ProcessingTarget  target,
GraphicPipeline gpu 
)
virtual

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 in Beatmup::BitmapResampler, Beatmup::BitmapBinaryOperation, Beatmup::Crop, Beatmup::Audio::SignalPlot, Beatmup::NNets::InferenceTask, Beatmup::FloodFill, Beatmup::BitmapFromChunk, Beatmup::ShaderApplicator, Beatmup::SceneRenderer, Beatmup::CustomPipeline, Beatmup::Filters::PixelwiseFilter, Beatmup::Metric, Beatmup::FormatConverter, and Beatmup::Audio::AbstractPlayback.

Definition at line 24 of file parallelism.cpp.

24  {
25  // nothing to do by default
26 }

◆ afterProcessing()

void AbstractTask::afterProcessing ( ThreadIndex  threadCount,
GraphicPipeline gpu,
bool  aborted 
)
virtual

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 in Beatmup::BitmapResampler, Beatmup::BitmapBinaryOperation, Beatmup::Crop, Beatmup::Audio::SignalPlot, Beatmup::NNets::InferenceTask, Beatmup::FloodFill, Beatmup::BitmapFromChunk, Beatmup::ShaderApplicator, Beatmup::CustomPipeline, Beatmup::Filters::PixelwiseFilter, Beatmup::Metric, and Beatmup::FormatConverter.

Definition at line 29 of file parallelism.cpp.

29  {
30  // nothing to do by default
31 }

◆ process()

virtual bool Beatmup::AbstractTask::process ( TaskThread thread)
pure virtual

◆ processOnGPU()

bool AbstractTask::processOnGPU ( GraphicPipeline gpu,
TaskThread thread 
)
virtual

Executes the task on GPU.

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

Reimplemented in Beatmup::NNets::InferenceTask, Beatmup::Filters::PixelwiseFilter, Beatmup::ShaderApplicator, Beatmup::SceneRenderer, Beatmup::CustomPipeline, Beatmup::GL::StorageBufferFetcher, Internal::Recycler, Beatmup::BitmapResampler, Beatmup::TextureHandleFactory, Beatmup::Swapper, and Beatmup::DisplaySwitch.

Definition at line 34 of file parallelism.cpp.

34  {
35  // nothing to do by default
36  return true;
37 }

◆ getUsedDevices()

◆ getMaxThreads()

ThreadIndex AbstractTask::getMaxThreads ( ) const
virtual

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 in Beatmup::NNets::InferenceTask, Beatmup::CallbackTask, Beatmup::CustomPipeline, Beatmup::FloodFill, Beatmup::GpuTask, Beatmup::Filters::PixelwiseFilter, Beatmup::BitmapResampler, Beatmup::BitmapBinaryOperation, Beatmup::Metric, Beatmup::Crop, Beatmup::FormatConverter, Beatmup::Audio::SignalPlot, and Beatmup::Audio::AbstractPlayback.

Definition at line 40 of file parallelism.cpp.

40  {
41  return 1;
42 }

◆ validThreadCount()

ThreadIndex AbstractTask::validThreadCount ( int  number)
static

Valid thread count from a given integer value.

Definition at line 45 of file parallelism.cpp.

45  {
46  if (number < 1)
47  return 1;
48  if (number > MAX_THREAD_INDEX)
49  return MAX_THREAD_INDEX;
50  return number;
51 }
static const ThreadIndex MAX_THREAD_INDEX
maximum possible thread index value
Definition: parallelism.h:71

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