arrow_back_ios Back to List

Using SPA With Offload™

Offload KB - case-studies

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.

Using the Offload™ compiler does not stop you from doing all the funky SPU tricks you could have ever dreamed of. The Offload™ compilers intention is simply to get code onto the SPU quickly and with type safety.

Content has been removed.

#include <liboffload>

int func()
{
	int result;
	int bar1 = 13;
	__blockingoffload()
	{
		int bar2 = 42;
		result = foo1(bar2);
		result += foo2(&bar2);
		result += foo3(&bar1);
	};
	return result;
}

In the above example, we are trying to call three functions, foo1, foo2 & foo3 from within an Offload™ block. For arguments sake, say we want to write each of these three functions in SPA, for performance reasons. The first step is to change the code like so:

#include <liboffload>

extern "C" __offload int foo1(int);
extern "C" __offload int foo2(int * );
extern "C" __offload int foo3(__outer int * );

int func()
{
	int result;
	int bar1 = 13;
	__blockingoffload()
	{
		int bar2 = 42;
		result = foo1(bar2);
		result += foo2(&bar2);
		result += foo3(&bar1);
	};
	return result;
}

We have added three extern "C" __offload definitions to the code. Each of these definitions is telling the compiler there is an external method, using C calling conventions (e.g. no mangling of the function name!) that can be called only from the SPU. the Offload™ compiler will generate prototype functions for the SPU code to link against these functions.

Content has been removed.

To link an Offload™ block against an SPU object file we need to put the SPU object file into an archive, by using spu-lv2-ar. For this example, lets say we generate libSPA.a. To link this into the Offload™ block we add -BEspuL"C:pathtolibSPA" -BEspulSPA to the command line (see /kb/125.html & /kb/126.html for more details).We've just linked our type-safe, easily offloaded Offload™ block to SPA, with relatively little effort! Offload™ can be linked against any SPU archive in this manner too, but crucially only against extern "C" functions - functions that are not mangled. Care should be taken when passing __outer pointer arguments into these functions, as once passed to code not going through the Offload™ compiler the pointer loses its type safety.