Add optional CUDA surface interpolation
This commit is contained in:
@@ -11,12 +11,15 @@
|
||||
using namespace std;
|
||||
|
||||
#include "misc.h"
|
||||
#include "MPatch.h"
|
||||
#include "Parallel.h"
|
||||
#include "fmisc.h"
|
||||
#ifdef INTERP_LB_PROFILE
|
||||
#include "interp_lb_profile.h"
|
||||
#endif
|
||||
#include "MPatch.h"
|
||||
#include "Parallel.h"
|
||||
#include "fmisc.h"
|
||||
#if USE_CUDA_BSSN
|
||||
#include "bssn_rhs_cuda.h"
|
||||
#endif
|
||||
#ifdef INTERP_LB_PROFILE
|
||||
#include "interp_lb_profile.h"
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -195,6 +198,17 @@ bool interp_fast_enabled()
|
||||
return enabled != 0;
|
||||
}
|
||||
|
||||
bool interp_gpu_enabled()
|
||||
{
|
||||
static int enabled = -1;
|
||||
if (enabled < 0)
|
||||
{
|
||||
const char *env = getenv("AMSS_INTERP_GPU");
|
||||
enabled = (env && atoi(env) != 0) ? 1 : 0;
|
||||
}
|
||||
return enabled != 0;
|
||||
}
|
||||
|
||||
bool interp_fast_compare_enabled()
|
||||
{
|
||||
static int enabled = -1;
|
||||
@@ -1113,6 +1127,101 @@ void Patch::Interp_Points(MyList<var> *VarList,
|
||||
}
|
||||
|
||||
// --- Interpolation phase (identical to original) ---
|
||||
#if USE_CUDA_BSSN
|
||||
const bool use_gpu_interp = interp_gpu_enabled() && use_surface_cache && num_var == 2 &&
|
||||
VarList && VarList->next && !VarList->next->next;
|
||||
#else
|
||||
const bool use_gpu_interp = false;
|
||||
#endif
|
||||
if (use_gpu_interp)
|
||||
{
|
||||
#if USE_CUDA_BSSN
|
||||
vector<vector<int> > local_points(block_index.views.size());
|
||||
for (int j = 0; j < NN; j++)
|
||||
{
|
||||
for (int i = 0; i < dim; i++)
|
||||
{
|
||||
if (myrank == 0 && (XX[i][j] < bbox[i] + lli[i] * DH[i] || XX[i][j] > bbox[dim + i] - uui[i] * DH[i]))
|
||||
{
|
||||
cout << "Patch::Interp_Points: point (";
|
||||
for (int k = 0; k < dim; k++)
|
||||
{
|
||||
cout << XX[k][j];
|
||||
if (k < dim - 1)
|
||||
cout << ",";
|
||||
else
|
||||
cout << ") is out of current Patch." << endl;
|
||||
}
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
}
|
||||
|
||||
CachedInterpPoint &cp = surface_cache->points[j];
|
||||
Block *BP = cp.bp;
|
||||
owner_rank[j] = cp.owner_rank;
|
||||
if (BP && myrank == BP->rank)
|
||||
{
|
||||
for (size_t bi = 0; bi < block_index.views.size(); bi++)
|
||||
{
|
||||
if (block_index.views[bi].bp == BP)
|
||||
{
|
||||
local_points[bi].push_back(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var *v0 = VarList->data;
|
||||
var *v1 = VarList->next->data;
|
||||
double soa6[6] = {
|
||||
v0->SoA[0], v0->SoA[1], v0->SoA[2],
|
||||
v1->SoA[0], v1->SoA[1], v1->SoA[2]};
|
||||
|
||||
for (size_t bi = 0; bi < local_points.size(); bi++)
|
||||
{
|
||||
const int count = int(local_points[bi].size());
|
||||
if (count <= 0)
|
||||
continue;
|
||||
|
||||
Block *BP = block_index.views[bi].bp;
|
||||
vector<double> px(count), py(count), pz(count), out(2 * count);
|
||||
for (int q = 0; q < count; q++)
|
||||
{
|
||||
const int j = local_points[bi][q];
|
||||
px[q] = XX[0][j];
|
||||
py[q] = XX[1][j];
|
||||
pz[q] = XX[2][j];
|
||||
}
|
||||
|
||||
const double dx = BP->X[0][1] - BP->X[0][0];
|
||||
const double dy = BP->X[1][1] - BP->X[1][0];
|
||||
const double dz = BP->X[2][1] - BP->X[2][0];
|
||||
const int ok = bssn_cuda_interp_host_two_fields(
|
||||
BP, BP->shape,
|
||||
BP->fgfs[v0->sgfn], BP->fgfs[v1->sgfn],
|
||||
BP->X[0][0], BP->X[1][0], BP->X[2][0],
|
||||
dx, dy, dz,
|
||||
&px[0], &py[0], &pz[0], count,
|
||||
ordn, Symmetry, soa6, &out[0]);
|
||||
if (ok != 0)
|
||||
{
|
||||
if (myrank == 0)
|
||||
cout << "Patch::Interp_Points: CUDA two-field interpolation failed" << endl;
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
}
|
||||
|
||||
for (int q = 0; q < count; q++)
|
||||
{
|
||||
const int j = local_points[bi][q];
|
||||
Shellf[j * num_var] = out[2 * q];
|
||||
Shellf[j * num_var + 1] = out[2 * q + 1];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < NN; j++)
|
||||
{
|
||||
double pox[dim];
|
||||
@@ -1183,6 +1292,7 @@ void Patch::Interp_Points(MyList<var> *VarList,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef INTERP_LB_PROFILE
|
||||
double t_interp_end = MPI_Wtime();
|
||||
|
||||
Reference in New Issue
Block a user