Nebula
Loading...
Searching...
No Matches
Jobs Namespace Reference

Detailed Description

Job system allows for scheduling and execution of a parallel task.

A model context bind a ModelInstance to a model, which allows it to be rendered using an .n3 file.

The job system works as follows. First one creates a job port with a name and some threads. The threads will be named as the port but with their index appended.

The job port has a priority, meaning all jobs sent to this port will inherit said priority. The job ports are then updated every frame to schedule work packages.

A job is not single-threaded, but spreads its work by chunking its slices and scheduling an equal amount of work on several threads. If you require the jobs to execute in sequence, you can execute a sequence of jobs which will be guaranteed to run on the same thread.

To synchronize, you have to create a job synchronization primitive, and it allows for signaling, waiting on the host-side, and waiting on the threads between jobs.

How to setup a job: Create port, create a job when required, use the function context to provide the job with inputs, outputs and uniform data.

Classes

struct  CreateJobInfo
 
struct  CreateJobPortInfo
 
struct  CreateJobSyncInfo
 
struct  JobContext
 
struct  JobFuncContext
 This class describes the size of a workload for a single thread (can be multiple items) More...
 
struct  JobId
 
struct  JobIOData
 
struct  JobPortId
 
struct  JobSyncId
 
class  JobThread
 
struct  JobUniformData
 
struct  PrivateMemory
 

Typedefs

typedef Ids::IdAllocator< Util::StringAtom, Util::FixedArray< Ptr< JobThread > >, uintJobPortAllocator
 
typedef Ids::IdAllocator< CreateJobInfo, std::function< void()>, PrivateMemoryJobAllocator
 
typedef Ids::IdAllocator< std::function< void()>, Threading::Event *, std::atomic_uint *, bool > JobSyncAllocator
 

Enumerations

enum  { JobPort_Name , JobPort_Threads , JobPort_NextThreadIndex }
 
enum  { Job_CreateInfo , Job_CallbackFunc , Job_ScratchMemory }
 
enum  { SyncCallback , SyncCompletionEvent , SyncCompletionCounter , SyncPendingSignal }
 

Functions

JobPortId CreateJobPort (const CreateJobPortInfo &info)
 create a new job port
 
void DestroyJobPort (const JobPortId &id)
 destroy job port
 
JobId CreateJob (const CreateJobInfo &info)
 create job
 
void DestroyJob (const JobId &id)
 delete job
 
void JobSchedule (const JobId &job, const JobPortId &port, const JobContext &ctx, const bool cycleThreads=true)
 schedule job to be executed
 
void JobSchedule (const JobId &job, const JobPortId &port, const JobContext &ctx, const std::function< void()> &callback, const bool cycleThreads=true)
 schedule job with callback when finished
 
void JobSchedule (const JobId &job, const JobPortId &port)
 schedule job without a context
 
void JobScheduleSequence (const Util::Array< JobId > &jobs, const JobPortId &port, const Util::Array< JobContext > &contexts)
 schedule a sequence of jobs
 
void JobScheduleSequence (const Util::Array< JobId > &jobs, const JobPortId &port, const Util::Array< JobContext > &contexts, const std::function< void()> &callback)
 schedule a sequence of jobs
 
void * JobAllocateScratchMemory (const JobId &job, const Memory::HeapType heap, const SizeT size)
 allocate memory for job
 
JobSyncId CreateJobSync (const CreateJobSyncInfo &info)
 create job sync
 
void DestroyJobSync (const JobSyncId id)
 destroy job sync
 
void JobSyncHostReset (const JobSyncId id)
 reset job sync on host
 
void JobSyncHostSignal (const JobSyncId id, bool reset=true)
 signal job sync on host
 
void JobSyncThreadSignal (const JobSyncId id, const JobPortId port, bool reset=true)
 put job sync on port, if reset is true, reset prior to signaling
 
void JobSyncHostWait (const JobSyncId id, bool reset=false)
 wait for job on host side, if reset is true, resets after waiting
 
void JobSyncThreadWait (const JobSyncId id, const JobPortId port, bool reset=false)
 wait for job on thread side, if reset is true, reset after waiting
 
bool JobSyncSignaled (const JobSyncId id)
 returns true if sync object has been signaled
 
 __ImplementClass (Jobs::JobThread, 'JBTH', Threading::Thread)
 
bool JobPortBusy (const JobPortId &id)
 check to see if port is idle
 
void JobSchedule (const JobId &job, const JobPortId &port, void *ctx, SizeT count, SizeT groupSize, const bool cycleThreads=true)
 schedule a job with a poiunter as context and a work group size and item count
 

Variables

JobPortAllocator jobPortAllocator (0xFFFF)
 
JobAllocator jobAllocator (0xFFFFFFFF)
 
JobSyncAllocator jobSyncAllocator (0xFFFFFFFF)
 

Typedef Documentation

◆ JobAllocator

typedef Ids::IdAllocator< CreateJobInfo, std::function<void()>, PrivateMemory > Jobs::JobAllocator

◆ JobPortAllocator

◆ JobSyncAllocator

typedef Ids::IdAllocator< std::function<void()>, Threading::Event*, std::atomic_uint*, bool > Jobs::JobSyncAllocator

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
JobPort_Name 
JobPort_Threads 
JobPort_NextThreadIndex 

◆ anonymous enum

anonymous enum
Enumerator
Job_CreateInfo 
Job_CallbackFunc 
Job_ScratchMemory 

◆ anonymous enum

anonymous enum
Enumerator
SyncCallback 
SyncCompletionEvent 
SyncCompletionCounter 
SyncPendingSignal 

Function Documentation

◆ __ImplementClass()

Jobs::__ImplementClass ( Jobs::JobThread ,
'JBTH' ,
Threading::Thread  )

◆ CreateJob()

JobId Jobs::CreateJob ( const CreateJobInfo & info)

create job

◆ CreateJobPort()

JobPortId Jobs::CreateJobPort ( const CreateJobPortInfo & info)

create a new job port

◆ CreateJobSync()

JobSyncId Jobs::CreateJobSync ( const CreateJobSyncInfo & info)

create job sync

◆ DestroyJob()

void Jobs::DestroyJob ( const JobId & id)

delete job

◆ DestroyJobPort()

void Jobs::DestroyJobPort ( const JobPortId & id)

destroy job port

◆ DestroyJobSync()

void Jobs::DestroyJobSync ( const JobSyncId id)

destroy job sync

◆ JobAllocateScratchMemory()

void * Jobs::JobAllocateScratchMemory ( const JobId & job,
const Memory::HeapType heap,
const SizeT size )

allocate memory for job

◆ JobPortBusy()

bool Jobs::JobPortBusy ( const JobPortId & id)

check to see if port is idle

◆ JobSchedule() [1/4]

void Jobs::JobSchedule ( const JobId & job,
const JobPortId & port )

schedule job without a context

◆ JobSchedule() [2/4]

void Jobs::JobSchedule ( const JobId & job,
const JobPortId & port,
const JobContext & ctx,
const bool cycleThreads )

schedule job to be executed

◆ JobSchedule() [3/4]

void Jobs::JobSchedule ( const JobId & job,
const JobPortId & port,
const JobContext & ctx,
const std::function< void()> & callback,
const bool cycleThreads )

schedule job with callback when finished

◆ JobSchedule() [4/4]

void Jobs::JobSchedule ( const JobId & job,
const JobPortId & port,
void * ctx,
SizeT count,
SizeT groupSize,
const bool cycleThreads = true )

schedule a job with a poiunter as context and a work group size and item count

◆ JobScheduleSequence() [1/2]

void Jobs::JobScheduleSequence ( const Util::Array< JobId > & jobs,
const JobPortId & port,
const Util::Array< JobContext > & contexts )

schedule a sequence of jobs

◆ JobScheduleSequence() [2/2]

void Jobs::JobScheduleSequence ( const Util::Array< JobId > & jobs,
const JobPortId & port,
const Util::Array< JobContext > & contexts,
const std::function< void()> & callback )

schedule a sequence of jobs

◆ JobSyncHostReset()

void Jobs::JobSyncHostReset ( const JobSyncId id)

reset job sync on host

◆ JobSyncHostSignal()

void Jobs::JobSyncHostSignal ( const JobSyncId id,
bool reset )

signal job sync on host

◆ JobSyncHostWait()

void Jobs::JobSyncHostWait ( const JobSyncId id,
bool reset )

wait for job on host side, if reset is true, resets after waiting

◆ JobSyncSignaled()

bool Jobs::JobSyncSignaled ( const JobSyncId id)

returns true if sync object has been signaled

◆ JobSyncThreadSignal()

void Jobs::JobSyncThreadSignal ( const JobSyncId id,
const JobPortId port,
bool reset )

put job sync on port, if reset is true, reset prior to signaling

◆ JobSyncThreadWait()

void Jobs::JobSyncThreadWait ( const JobSyncId id,
const JobPortId port,
bool reset )

wait for job on thread side, if reset is true, reset after waiting

Variable Documentation

◆ jobAllocator

JobAllocator Jobs::jobAllocator ( 0xFFFFFFFF )

◆ jobPortAllocator

JobPortAllocator Jobs::jobPortAllocator ( 0xFFFF )

◆ jobSyncAllocator

JobSyncAllocator Jobs::jobSyncAllocator ( 0xFFFFFFFF )