I have been trying to offload an existing OpenMP parallel loop to a GPU target.
The problem is, the to-be-offloaded calculation function is using a vector of objects, and each of these objects has vectors of other objects as members.
Mapping a simple vector to GPU is quite easy:
std::vector<double> v;
// ...
double* vd = v.data();
#pragma omp target data
map(to: vd[:v.size()])
{
// ...
}
However, I'm at loss when it comes to mapping something like this:
// Example 1
struct Matrix {
std::vector<double> matrix_data;
std::size_t rows = 0
std::size_t cols = 0;
}
std::vector<Matrix> mv; // How to map "mv" to target?
Or, even more complicated:
// Example 2
struct S {
std::vector<Matrix> nodes;
std::map<int, Matrix> mm;
}
std::vector<S> sv; // How to map "sv" to target?
Unfortunately, the main object that the existing program (and its parallelized loops) is operating on is of a type with many such nested object members. The calculation loops read/write to deeply nested variables all over the object.
Compiler: Intel oneAPI DPC++/C++ Compiler 2022.0.0, Windows and Linux. GPU: Intel gen9 (i9-9900K).
P.S. I have not been able to find a good guide on OpenMP targets. It seems that there are either very simple beginner tutorials focusing only on saxpy, or the dry specification itself.
If it's not possible with OpenMP, is there another API that can be easily used with such C++ structures (ideally, without conflicting with other OpenMP code in the program)? Perhaps by defining mapper functions for each type?
Thanks