Skip to content

How it is used

Hüseyin Tuğrul BÜYÜKIŞIK edited this page Mar 10, 2021 · 18 revisions

Currently (v1.0), it needs a vector of device objects that is created like:

// this object prepares OpenCL platforms and devices into same array to be used for data copies.
GraphicsCardSupplyDepot depot;
std::vector<ClDevice> gpus = depot.requestGpus();

then virtual array is constructed:

// usage on VRAM
// needs to be integer-multiple of pageSize
const size_t n = 1024*100000;

// less = lowers performance. more = uses more RAM.
const int maxActivePagesPerGpu = 100; 
const size_t pageSize=1024; // needs to be an exact divisor of n

VirtualMultiArray<Particle> testArray(n,depot.requestGpus(),pageSize,maxActivePagesPerGpu);
VirtualMultiArray<int> anotherTestArray(n,depot.requestGpus(),pageSize,maxActivePagesPerGpu);

testArray.set(index, Particle(some_parameters)); // cached in active-page (with LRU eviction policy per page).
auto particle = testArray.get(index); // gets particle at index

If sample class (Particle) costs 44 bytes per instance, then 100M elements need 4.5GB. Virtual array distributes data evenly(or with custom ratio using last parameter(memMult) of VirtualMultiArray constructor) to all graphics cards. So some asymmetric system setups may see overflowing data on one of cards to OS(Ubuntu?) paging system due to over-allocating in VRAM. I tested this only on three 2GB cards in same system.

Device, platform, etc, all OpenCL-related objects automatically release memory when they are out of scope (and destructed in the last surviving instance of VirtualMultiArray), so the virtual array does not need to be in scope of GraphicsCardSupplyDepot object.

It can also be used like a plain array:

VirtualMultiArray<Particle> testArray(....);

testArray[1000]=Particle(); // setter

Particle p = testArray[1000]; // getter

but not as

auto var = testArray[1000];

because compiler thinks the intended value type is proxy class instead of "Particle".

Also not usable as

float xCoordinate = testArray[1000].xCoordinate;
``

because, again, compiler still thinks we are referring to proxy class instead of the intended Particle class.