40#define JOBFUNCCONTEXT_MAXIO 8
41#define JOBFUNCCONTEXT_MAXUNIFORMS 4
43#define N_JOB_INPUT(ctx, slice, index) (ctx.inputs[index] + slice * ctx.inputSizes[index])
44#define N_JOB_OUTPUT(ctx, slice, index) (ctx.outputs[index] + slice * ctx.outputSizes[index])
128 const std::function<void()>*
callback;
146 void RunJobSlices(
uint sliceIndex,
uint numSlices,
const JobContext ctx,
void(*JobFunc)(
const JobFuncContext& ctx),
const std::function<
void()>* callback);
239 std::function<void()>,
274void JobSyncThreadWait(
const JobSyncId
id,
const JobPortId port,
bool reset =
false);
280 std::function<void()>,
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
bool HasWork()
returns true if thread has work
Definition jobs.cc:490
void DoWork()
this method runs in the thread context
Definition jobs.cc:421
JobThreadCommandType
Definition jobs.h:102
@ WaitAndReset
Definition jobs.h:106
@ RunJob
Definition jobs.h:103
@ Signal
Definition jobs.h:104
@ Wait
Definition jobs.h:105
static const SizeT MaxScratchSize
Definition jobs.h:154
JobThread()
constructor
Definition jobs.cc:390
virtual ~JobThread()
destructor
Definition jobs.cc:399
void PushCommands(const Util::Array< JobThreadCommand > &commands)
push command buffer work
Definition jobs.cc:564
void PushCommand(const JobThreadCommand &command)
push command buffer work
Definition jobs.cc:555
void RunJobSlices(uint sliceIndex, uint numSlices, const JobContext ctx, void(*JobFunc)(const JobFuncContext &ctx), const std::function< void()> *callback)
push a set of job slices
Definition jobs.cc:499
ubyte * scratchBuffer
Definition jobs.h:157
void EmitWakeupSignal()
called if thread needs a wakeup call before stopping
Definition jobs.cc:412
__DeclareClass(JobThread)
Threading::SafeQueue< JobThreadCommand > commands
Definition jobs.h:156
Thread-safe version of Util::Queue.
Definition safequeue.h:27
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
A StringAtom.
Definition stringatom.h:22
#define ID_16_TYPE(x)
Definition id.h:31
#define ID_32_TYPE(x)
Definition id.h:16
#define JOBFUNCCONTEXT_MAXUNIFORMS
Definition jobs.h:41
#define JOBFUNCCONTEXT_MAXIO
Definition jobs.h:40
Job system allows for scheduling and execution of a parallel task.
Definition jobs.cc:11
@ Job_CreateInfo
Definition jobs.h:232
@ Job_CallbackFunc
Definition jobs.h:233
@ Job_ScratchMemory
Definition jobs.h:234
@ JobPort_Threads
Definition jobs.h:185
@ JobPort_NextThreadIndex
Definition jobs.h:186
@ JobPort_Name
Definition jobs.h:184
JobSyncAllocator jobSyncAllocator(0xFFFFFFFF)
Definition jobs.h:285
void DestroyJob(const JobId &id)
delete job
Definition jobs.cc:78
JobPortAllocator jobPortAllocator(0xFFFF)
Definition jobs.h:194
void * JobAllocateScratchMemory(const JobId &job, const Memory::HeapType heap, const SizeT size)
allocate memory for job
Definition jobs.cc:238
void DestroyJobSync(const JobSyncId id)
destroy job sync
Definition jobs.cc:273
Ids::IdAllocator< Util::StringAtom, Util::FixedArray< Ptr< JobThread > >, uint > JobPortAllocator
Definition jobs.h:193
bool JobSyncSignaled(const JobSyncId id)
returns true if sync object has been signaled
Definition jobs.cc:380
JobSyncId CreateJobSync(const CreateJobSyncInfo &info)
create job sync
Definition jobs.cc:253
void JobSyncThreadWait(const JobSyncId id, const JobPortId port, bool reset)
wait for job on thread side, if reset is true, reset after waiting
Definition jobs.cc:357
@ SyncCompletionEvent
Definition jobs.h:255
@ SyncCallback
Definition jobs.h:254
@ SyncCompletionCounter
Definition jobs.h:256
@ SyncPendingSignal
Definition jobs.h:257
void JobSchedule(const JobId &job, const JobPortId &port, const JobContext &ctx, const bool cycleThreads)
schedule job to be executed
Definition jobs.cc:91
Ids::IdAllocator< std::function< void()>, Threading::Event *, std::atomic_uint *, bool > JobSyncAllocator
Definition jobs.h:284
void JobScheduleSequence(const Util::Array< JobId > &jobs, const JobPortId &port, const Util::Array< JobContext > &contexts)
schedule a sequence of jobs
Definition jobs.cc:196
void JobSyncHostSignal(const JobSyncId id, bool reset)
signal job sync on host
Definition jobs.cc:294
void DestroyJobPort(const JobPortId &id)
destroy job port
Definition jobs.cc:47
void JobSyncHostWait(const JobSyncId id, bool reset)
wait for job on host side, if reset is true, resets after waiting
Definition jobs.cc:344
JobAllocator jobAllocator(0xFFFFFFFF)
Definition jobs.h:242
bool JobPortBusy(const JobPortId &id)
check to see if port is idle
JobPortId CreateJobPort(const CreateJobPortInfo &info)
create a new job port
Definition jobs.cc:20
void JobSyncThreadSignal(const JobSyncId id, const JobPortId port, bool reset)
put job sync on port, if reset is true, reset prior to signaling
Definition jobs.cc:306
void JobSyncHostReset(const JobSyncId id)
reset job sync on host
Definition jobs.cc:284
Ids::IdAllocator< CreateJobInfo, std::function< void()>, PrivateMemory > JobAllocator
Definition jobs.h:241
JobId CreateJob(const CreateJobInfo &info)
create job
Definition jobs.cc:62
HeapType
Heap types are defined here.
Definition osxmemoryconfig.h:25
void(* JobFunc)(const JobFuncContext &ctx)
Definition jobs.h:200
uint affinity
Definition jobs.h:170
Util::StringAtom name
Definition jobs.h:168
SizeT numThreads
Definition jobs.h:169
uint priority
Definition jobs.h:171
std::function< void()> callback
Definition jobs.h:249
JobUniformData uniform
Definition jobs.h:93
JobIOData input
Definition jobs.h:91
JobIOData output
Definition jobs.h:92
This class describes the size of a workload for a single thread (can be multiple items)
Definition jobs.h:51
uint numSlices
Definition jobs.h:66
uint outputSizes[JOBFUNCCONTEXT_MAXIO]
Definition jobs.h:64
ubyte * outputs[JOBFUNCCONTEXT_MAXIO]
Definition jobs.h:63
uint uniformSizes[JOBFUNCCONTEXT_MAXUNIFORMS]
Definition jobs.h:56
uint numOutputs
Definition jobs.h:62
uint inputSizes[JOBFUNCCONTEXT_MAXIO]
Definition jobs.h:60
ubyte * scratch
Definition jobs.h:52
uint numInputs
Definition jobs.h:58
ubyte * uniforms[JOBFUNCCONTEXT_MAXUNIFORMS]
Definition jobs.h:55
ubyte * inputs[JOBFUNCCONTEXT_MAXIO]
Definition jobs.h:59
uint numUniforms
Definition jobs.h:54
SizeT dataSize[MaxNumBuffers]
Definition jobs.h:75
void * data[MaxNumBuffers]
Definition jobs.h:74
static const SizeT MaxNumBuffers
Definition jobs.h:71
SizeT numBuffers
Definition jobs.h:73
SizeT sliceSize[MaxNumBuffers]
Definition jobs.h:76
uint slice
Definition jobs.h:117
std::atomic_uint * completionCounter
Definition jobs.h:127
void(* JobFunc)(const JobFuncContext &ctx)
Definition jobs.h:120
Threading::Event * ev
Definition jobs.h:126
const std::function< void()> * callback
Definition jobs.h:121
JobContext context
Definition jobs.h:119
JobThreadCommandType ev
Definition jobs.h:112
uint numSlices
Definition jobs.h:118
struct Jobs::JobThread::JobThreadCommand::@17::@19 run
struct Jobs::JobThread::JobThreadCommand::@17::@20 sync
SizeT size
Definition jobs.h:226
void * memory
Definition jobs.h:227
Memory::HeapType heapType
Definition jobs.h:225
unsigned char ubyte
Definition types.h:34
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31