Login or Register

Case Studies Right Offloading a Function Call

Caching instance data

How To Call A Method On A Cached Object.

This article was updated on 2011-06-03 03:58:38


The code below caches the this pointer only by using a local temporary object on the SPU, copies data from the PPU via DMA or Software Cache into that object and calls the (duplicated) method func on it with 2 PPU pointer arguments.

__offload()
{
	auto localptr = *ptr; //DMA or SW cache read into a local
	localptr.func(ptrarg1,ptrarg2);//__inner this pointer and outer argument pointers* ptr
	*ptr = localptr; //writing data back
}

This means that all fields of the instance are now in fast local memory. The write-back at the end may not be necessary if func is a const-qualified member function (doesn't modify the SPU local instance). In fact if any code before the write-back causes side-effects to the (PPU) data that ptr points to, the a single write-back would clobber these changes.

This caching required changes to existing code which may not be practical when offloading larger chunks of code. The next Article 136 describes how to minimise those changes by using standard C++ cache classes.