arrow_back_ios Back to List

__offload

Offload KB - offload-library

Old Content Alert

Please note that this is a old document archive and the will most likely be out-dated or superseded by various other products and is purely here for historical purposes.

The basic Offload™ keyword is __offload - which is used to denote an offload block.

offloadThread_t handle = __offload()
{
	; // performs its execution on the SPU
};

The __offload keyword is followed by function-like parenthesis, then the scope of the block. It returns a result, an offloadThread_t handle, which can be used to join on the block thereafter. Any work within this scope is performed on the SPU instead of on the PPU. An __offload block can optionally take parameters that will be passed into the __offload block's context.

int number = 42;
offloadThread_t handle = __offload(number)
{
	;
};

Within the __offload block number has been passed in by value, and can be used in calculations within. Parameters passed into __offload blocks are useful for bringing local variables on the stack within the __offload block for use.The __offload modifier is also used to denote specialization of functions for use only on the SPU.

static int foo()
{
	return 13;
}

__offload static int foo()
{
	return 42;
}

static void func()
{
	int outerFoo = foo(); // returns 13
	offloadThread_t handle = __offload()
	{
		int innerFoo = foo(); // returns 42
	};
}

__offload functions allow functions to be specialized to perform slightly different actions on the SPU, performance optimizations, avoid calling PPU methods, etc. __offload functions can apply to static and member functions, but also to constructors and destructors too.

These non-blocking __offload blocks return an offloadThread_t handle, which must be passed to a call to offloadThreadJoin(handle); to correctly consume the resources allocated for each non-blocking __offload block. Not joining on the block will eventually result in the Offload™ SPURS instance faulting, as there will not be a free handle in which to allocate an __offload block.

Share