arrow_back_ios Back to List

-outputoffloadcode

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.

Offload by default will compile the input file for both PPU and SPU, duplicating all the PPU methods that are being used on the SPU into SPU code. One of the most useful features we have added is –outputoffloadcode, which will output only the minimal set of PPU functions required to call the Offload code, but still duplicating all the required SPU code.Lets consider the example;

struct Foo
{
	int work1();
	int work2();
};

Int Foo::work1()
{
	; // do something
	return -1;
}

Int Foo::work2()
{
	int result1 = work1();
	int result2 = work1();
	return result1 + result2;
}

Now, we wish to Offload some of the processing in work2, but want the rest of the code to be compiled for PPU without using Offload.

struct Foo
{
	int work1();
	int work2();
};

int Foo::work1()
{
	; // do something
	return -1;
}

#ifdef __offloadcplusplus

int Foo::work2()
{
	int result1;
	
	__offload()
	{
		result1 = work1();
	};
	
	int result2 = work1();
	return result1 + result2;
}
#endif

Now we have to compile this same C++ file twice, once to output the normal PPU code (but this time leaving out the definition of work2), and then again with Offload, with the –outputoffloadcode option added to the compiler. Offload will then correctly deduce that work2 has Offload specific code within it, and write out the PPU definition for that function, but also will ignore outputting all the other functions, instead duplicating the work for the SPU.

This option also comes in handy when Offload requires a definition for a function that resides within another C++ file. Without the –outputoffloadcode compiler option, when we included the C++ file within the current C++ file (so that we can see the definition) at the link stage lots of multiply defined errors would be thrown. Handily when we use the –outputoffloadcode option though the definitions will only be written out if they contain Offload specific code, meaning they will not be written out by the Offload compiler.