arrow_back_ios Back to List

__outer

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 __outer keyword is used on pointers within an Offload™ block context.

offloadThread_t handle = __offload()
{
	__outer int * ptr;
};

In the above example, ptr is an outer pointer - it points to main memory rather than local memory. The ptr variable can be assigned to any data that resides on the main memory, but will throw an error if a local memory pointer is being assigned to it.

offloadThread_t handle = __offload()
{
	__outer int * ptr1;
	int foo = 42;
	int * ptr2;
	ptr1 = &foo; // fails at compile time, because address of foo is a local memory pointer
	ptr2 = &foo; // succeeds at compile time, types are the same
	ptr2 = ptr1; // fails at compile time, because pointer types are different!
};

Within an Offload™ context, the compiler will try to deduce what the pointer type is by what is being assigned to it.

int outerFoo = 42;
offloadthread_t handle = __offload()
{
	int * ptr1 = &outerFoo; // is deduced as an outer pointer
	int innerFoo = 42;
	int * ptr2 = &innerFoo; // is deduced as an inner pointer
};

The __outer keyword is also used to denote a main memory this pointer on __offload function specializations.

struct MyType
{
	int foo()
	{
		return 13;
	}

	__offload int foo()
	{
		return 42;
	}

	__offload int foo() __outer
	{
		return 53;
	}
}

static void func()
{
	MyType outerBar;
	int outerFoo = outerBar.foo(); // returns 13
	offloadThread_t handle = __offload()
	{
		int localFoo = outerBar.foo(); // returns 53
		MyType localBar;
		localFoo = localBar.foo(); // returns 42
	};
}

The example above shows you the power of Offload™ - allowing different specializations of functions for main memory and local memory.