33 #ifdef BEATMUP_PLATFORM_ANDROID
34 #include <android/log.h>
74 std::rethrow_exception(exPtr);
76 catch (
const std::exception & ex) {
77 #if BEATMUP_PLATFORM_ANDROID
78 __android_log_print(ANDROID_LOG_ERROR,
"Beatmup",
79 "\n********************************************\n"
80 "Beatmup engine raises exception:\n%s"
81 "\n********************************************\n", ex.what());
83 std::cout << ex.what() << std::endl;
92 std::rethrow_exception(exPtr);
94 catch (
const std::exception & ex) {
95 #if BEATMUP_PLATFORM_ANDROID
96 __android_log_print(ANDROID_LOG_ERROR,
"Beatmup",
97 "\n********************************************\n"
98 "Beatmup engine was unable to init GPU:\n%s"
99 "\n********************************************\n", ex.what());
101 std::cout << ex.what() << std::endl;
139 auto startTime = std::chrono::high_resolution_clock::now();
142 auto endTime = std::chrono::high_resolution_clock::now();
144 return std::chrono::duration<float, std::milli>(endTime - startTime).count();
313 GpuQueryingTask(std::string& vendor, std::string&
renderer) :
316 TaskDeviceRequirement getUsedDevices()
const {
return TaskDeviceRequirement::GPU_OR_CPU; }
333 return task.gpuFound;
Task: an operation that can be executed by multiple threads in parallel.
An event listener (bunch of callbacks)
virtual void taskFail(PoolIndex pool, AbstractTask &task, const std::exception &ex)=0
Called when a task fails.
virtual void gpuInitFail(PoolIndex pool, const std::exception &ex)=0
Called when GPU initialization failed.
virtual void threadCreated(PoolIndex pool)=0
Called when a new worker thread is created.
virtual void threadTerminating(PoolIndex pool)=0
Called when a worker thread finished.
virtual bool taskDone(PoolIndex pool, AbstractTask &task, bool aborted)=0
Called when a task is successfully finished.
Basic class: task and memory management, any kind of static data.
const ThreadIndex maxAllowedWorkerCount(const PoolIndex pool=DEFAULT_POOL) const
GL::RecycleBin * recycleBin
stores GPU garbage: resources managed by GPU and might be freed in the managing thread only
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
void wait(const PoolIndex pool=DEFAULT_POOL)
Blocks until all the submitted jobs are executed.
Job submitTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Adds a new task to the jobs queue.
bool abortJob(Job job, const PoolIndex pool=DEFAULT_POOL)
Aborts a given submitted job.
GL::RecycleBin * getGpuRecycleBin() const
bool isManagingThread() const
Job submitPersistentTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Adds a new persistent task to the jobs queue.
bool queryGpuInfo(std::string &vendor, std::string &renderer)
Initializes the GPU if not yet and queries information about it.
void check(const PoolIndex pool=DEFAULT_POOL)
Checks if a specific thread pool is doing great: rethrows exceptions occurred during tasks execution,...
EventListener * getEventListener() const
Returns current event listener (or NULL)
bool busy(const PoolIndex pool=DEFAULT_POOL)
Queries whether a given thread pool is busy with a task.
void repeatTask(AbstractTask &task, bool abortCurrent, const PoolIndex pool=DEFAULT_POOL)
Ensures a given task executed at least once.
void warmUpGpu()
Initializes GPU within a given Context if not yet (takes no effect if it already is).
bool isGpuQueried() const
void limitWorkerCount(ThreadIndex maxValue, const PoolIndex pool=DEFAULT_POOL)
Limits maximum number of threads (workers) when performing tasks in a given pool.
void setEventListener(EventListener *eventListener)
Installs new event listener.
void waitForJob(Job job, const PoolIndex pool=DEFAULT_POOL)
Waits until a given job finishes.
Stores references to GPU resources that will not be used anymore and needed to be recycled in a threa...
void emptyBin()
Empty the bin destroying all the items in a GPU-aware thread.
Template of a task using GPU.
Internal low-level GPU control API.
const char * getGpuRendererString() const
const char * getGpuVendorString() const
A pool of threads running tasks ThreadPool runs AbstractTasks, possibly in multiple threads.
Job submitTask(AbstractTask &task, const TaskExecutionMode mode)
Adds a new task to the jobs queue.
void resize(ThreadIndex newThreadCount)
Resizes the pool.
@ PERSISTENT
persistent task, run process() until it returns false
@ NORMAL
normal task, should be run it once
void waitForJob(Job job)
Blocks until a given job finishes if not yet.
Job repeatTask(AbstractTask &task, bool abortCurrent)
Ensures a given task executed at least once.
ThreadIndex getThreadCount() const
bool abortJob(Job job)
Aborts a given submitted job.
bool busy()
Checks whether the pool has jobs.
void check()
Checks if the thread pool is doing great.
bool isGpuQueried() const
void wait()
Blocks until all the submitted jobs are executed.
Thread pool event listener.
void threadCreated(PoolIndex pool)
Callback function called when a new worker thread is created.
const Context::Impl & ctx
void threadTerminating(PoolIndex pool)
Callback function called when a worker thread is terminating.
ThreadPoolEventListener(const Context::Impl &ctx)
void taskFail(PoolIndex pool, AbstractTask &task, std::exception_ptr exPtr)
Callback function called when an exception is thrown.
bool taskDone(PoolIndex pool, AbstractTask &task, bool aborted)
Callback function called when a task is done or cancelled; if returns true, the task will be repeated...
void gpuInitFail(PoolIndex pool, std::exception_ptr exPtr)
Callback function called when the GPU cannot start.
Context class implementation (pimpl)
bool abortJob(const PoolIndex pool, Job job)
Impl(const PoolIndex numThreadPools)
bool busy(const PoolIndex pool)
void waitForJob(const PoolIndex pool, Job job)
void repeatTask(PoolIndex pool, AbstractTask &task, bool abortCurrent)
void limitWorkerCount(const PoolIndex pool, ThreadIndex maxValue)
Job submitTask(const PoolIndex pool, AbstractTask &task)
Context::EventListener * eventListener
an event listener
ThreadPool ** threadPools
thread pools of task workers
void check(const PoolIndex pool)
bool isManagingThread() const
bool isGpuQueried() const
ThreadIndex optimalThreadCount
optimal default number of worker threads per task in each pool
void wait(const PoolIndex pool)
ThreadPoolEventListener threadPoolEventListener
const ThreadIndex maxAllowedWorkerCount(const PoolIndex pool) const
Job submitPersistentTask(const PoolIndex pool, AbstractTask &task)
float performTask(PoolIndex pool, AbstractTask &task)
#define BEATMUP_ASSERT_DEBUG(C)
unsigned char ThreadIndex
number of threads / thread index
unsigned char PoolIndex
number of tread pools or a pool index
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
JNIEnv jlong jint jint job
Beatmup::SceneRenderer * renderer
Beatmup::NNets::InferenceTask * task