How can I call a kernel function for multiple Thrust object member functions in CUDA?

Viewed 926

Please note that I am an absolute beginner with CUDA, and everything below is untested pseudocode. I'm coming from JavaScript, and my C++ is also super rusty, so I apologize for my ignorance :)

I am attempting to use CUDA for backtesting many different forex strategies.

Using Thrust, and I have 1000 objects instantiated from a class (pseudocode):

#include <stdio.h>
#include <thrust/device_ptr.h>
#include <thrust/device_new.h>

#define N 1000

typedef struct dataPoint {
    ...
} dataPoint;

class Strategy {
    public:
        __device__ __host__ Strategy(...) {
            ...
        }

        __device__ __host__ void backtest(dataPoint data) {
            ...
        }
};

int main() {
    dataPoint data[100000];
    thrust::device_ptr<Strategy> strategies[1000];
    int i;

    // Instantiate 5000 strategies.
    for (i=0; i<1000; i++) {
        thrust::device_ptr<Strategy> strategies[i] = thrust::device_new<Strategy>(...);
    }

    // Iterate over all 100000 data points.
    for (i=0; i<100000; i++) {
        // Somehow run .backtest(data[j]) on each strategy here.
        // i.e. Run backtest() in parallel for all 1000
        // strategy objects here.
    }
}

Now let's say I'd like to run the .backtest() method on each object for each item in data. Procedurally I would do the following:

// Iterate over all 100000 data points.
for (j=0; j<100000; j++) {
    // Iterate over all 1000 strategies.
    for (i=0; i<1000; i++) {
        strategies[i].backtest(data[j]);
    }
}

How might I accomplish this using CUDA such that .backtest() runs in parallel for all strategies each iteration j through the data?

If I have to completely rearchitect everything, so be it -- I'm open to whatever is necessary. If this isn't possible with classes, then so be it.

1 Answers
Related