Compare commits

..

6 Commits

View File

@ -264,126 +264,83 @@ class Benchmark
return; return;
} }
static void Latency(void) static void PointToPoint(void)
{ {
int Nloop = 200; int Nloop = 200;
int nmu = 0;
Coordinate simd_layout = GridDefaultSimd(Nd, vComplexD::Nsimd()); Coordinate simd_layout = GridDefaultSimd(Nd, vComplexD::Nsimd());
Coordinate mpi_layout = GridDefaultMpi(); Coordinate mpi_layout = GridDefaultMpi();
Coordinate shm_layout;
GlobalSharedMemory::GetShmDims(mpi_layout, shm_layout);
for (int mu = 0; mu < Nd; mu++) std::cout << GridLogMessage << "Benchmarking point-to-point latency" << std::endl;
if (mpi_layout[mu] > 1)
nmu++;
std::vector<double> t_time(Nloop);
time_statistics timestat;
std::cout << GridLogMessage << "Benchmarking Latency to neighbors in " << nmu
<< " dimensions" << std::endl;
grid_small_sep(); grid_small_sep();
grid_printf("%5s %7s %15s %15s %15s\n", "dir", "shm", "time (usec)", "std dev", grid_printf("from to mean(usec) err min\n");
"min");
int lat = 8; // dummy lattice size. Not really used. int lat = 8; // dummy lattice size. Not actually used.
Coordinate latt_size({lat * mpi_layout[0], lat * mpi_layout[1], lat * mpi_layout[2], Coordinate latt_size({lat * mpi_layout[0], lat * mpi_layout[1], lat * mpi_layout[2],
lat * mpi_layout[3]}); lat * mpi_layout[3]});
GridCartesian Grid(latt_size, simd_layout, mpi_layout); GridCartesian Grid(latt_size, simd_layout, mpi_layout);
RealD Nrank = Grid._Nprocessors;
RealD Nnode = Grid.NodeCount();
RealD ppn = Nrank / Nnode;
std::vector<HalfSpinColourVectorD *> xbuf(8); int ranks;
std::vector<HalfSpinColourVectorD *> rbuf(8); int me;
uint64_t bytes = 8; MPI_Comm_size(Grid.communicator, &ranks);
for (int d = 0; d < 8; d++) MPI_Comm_rank(Grid.communicator, &me);
assert(ranks == Grid._Nprocessors);
assert(me == Grid._processor);
int bytes = 8;
void *buf_from = acceleratorAllocDevice(bytes);
void *buf_to = acceleratorAllocDevice(bytes);
nlohmann::json json_p2p;
for (int from = 0; from < ranks; ++from)
for (int to = 0; to < ranks; ++to)
{ {
xbuf[d] = (HalfSpinColourVectorD *)acceleratorAllocDevice(bytes); if (from == to)
rbuf[d] = (HalfSpinColourVectorD *)acceleratorAllocDevice(bytes);
}
double dbytes;
#define NWARMUP 50
for (int dir = 0; dir < 8; dir++)
{
int mu = dir % 4;
if (mpi_layout[mu] == 1) // skip directions that are not distributed
continue; continue;
bool is_shm = mpi_layout[mu] == shm_layout[mu];
bool is_partial_shm = !is_shm && shm_layout[mu] != 1;
std::vector<double> times(Nloop); std::vector<double> t_time(Nloop);
for (int i = 0; i < NWARMUP; i++) time_statistics timestat;
{ MPI_Status status;
int xmit_to_rank;
int recv_from_rank;
if (dir == mu) for (int i = 0; i < Nloop; ++i)
{ {
int comm_proc = 1;
Grid.ShiftedRanks(mu, comm_proc, xmit_to_rank, recv_from_rank);
}
else
{
int comm_proc = mpi_layout[mu] - 1;
Grid.ShiftedRanks(mu, comm_proc, xmit_to_rank, recv_from_rank);
}
Grid.SendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, (void *)&rbuf[dir][0],
recv_from_rank, bytes);
}
for (int i = 0; i < Nloop; i++)
{
dbytes = 0;
double start = usecond(); double start = usecond();
int xmit_to_rank; if (from == me)
int recv_from_rank;
if (dir == mu)
{ {
int comm_proc = 1; auto err = MPI_Send(buf_from, bytes, MPI_CHAR, to, 0, Grid.communicator);
Grid.ShiftedRanks(mu, comm_proc, xmit_to_rank, recv_from_rank); assert(err == MPI_SUCCESS);
err = MPI_Recv(buf_to, bytes, MPI_CHAR, to, 0, Grid.communicator, &status);
assert(err == MPI_SUCCESS);
} }
else if (to == me)
{ {
int comm_proc = mpi_layout[mu] - 1; auto err =
Grid.ShiftedRanks(mu, comm_proc, xmit_to_rank, recv_from_rank); MPI_Recv(buf_to, bytes, MPI_CHAR, from, 0, Grid.communicator, &status);
assert(err == MPI_SUCCESS);
err = MPI_Send(buf_from, bytes, MPI_CHAR, from, 0, Grid.communicator);
assert(err == MPI_SUCCESS);
} }
Grid.SendToRecvFrom((void *)&xbuf[dir][0], xmit_to_rank, (void *)&rbuf[dir][0],
recv_from_rank, bytes);
dbytes += bytes;
double stop = usecond(); double stop = usecond();
t_time[i] = stop - start; // microseconds t_time[i] = stop - start;
} }
timestat.statistics(t_time); // important: only the 'from' rank has a trustworthy time
MPI_Bcast(t_time.data(), Nloop, MPI_DOUBLE, from, Grid.communicator);
grid_printf("%5d %7s %15.2f %15.1f %15.2f\n", dir, timestat.statistics(t_time);
is_shm ? "yes" grid_printf("%2d %2d %15.2f %15.1f %15.2f\n", from, to, timestat.mean,
: is_partial_shm ? "partial" timestat.err, timestat.min);
: "no",
timestat.mean, timestat.err, timestat.min);
nlohmann::json tmp; nlohmann::json tmp;
nlohmann::json tmp_rate; tmp["from"] = from;
tmp["dir"] = dir; tmp["to"] = to;
tmp["shared_mem"] = is_shm;
tmp["partial_shared_mem"] = is_partial_shm;
tmp["time_usec"] = timestat.mean; tmp["time_usec"] = timestat.mean;
tmp["time_usec_error"] = timestat.err; tmp["time_usec_error"] = timestat.err;
tmp["time_usec_max"] = timestat.min; tmp["time_usec_max"] = timestat.min;
json_results["latency"].push_back(tmp); json_p2p.push_back(tmp);
}
for (int d = 0; d < 8; d++)
{
acceleratorFreeDevice(xbuf[d]);
acceleratorFreeDevice(rbuf[d]);
} }
json_results["latency"] = json_p2p;
return; acceleratorFreeDevice(buf_from);
acceleratorFreeDevice(buf_to);
} }
static void Memory(void) static void Memory(void)
@ -647,8 +604,6 @@ class Benchmark
FGrid->Broadcast(0, &ncall, sizeof(ncall)); FGrid->Broadcast(0, &ncall, sizeof(ncall));
Dw.ZeroCounters();
time_statistics timestat; time_statistics timestat;
std::vector<double> t_time(ncall); std::vector<double> t_time(ncall);
for (uint64_t i = 0; i < ncall; i++) for (uint64_t i = 0; i < ncall; i++)
@ -843,7 +798,6 @@ class Benchmark
uint64_t ncall = 500; uint64_t ncall = 500;
FGrid->Broadcast(0, &ncall, sizeof(ncall)); FGrid->Broadcast(0, &ncall, sizeof(ncall));
Ds.ZeroCounters();
time_statistics timestat; time_statistics timestat;
std::vector<double> t_time(ncall); std::vector<double> t_time(ncall);
@ -930,7 +884,7 @@ int main(int argc, char **argv)
int do_su4 = 1; int do_su4 = 1;
int do_memory = 1; int do_memory = 1;
int do_comms = 1; int do_comms = 1;
int do_latency = 1; int do_p2p = 1;
int do_flops = 1; int do_flops = 1;
int Ls = 1; int Ls = 1;
@ -966,12 +920,12 @@ int main(int argc, char **argv)
Benchmark::Comms(); Benchmark::Comms();
} }
if (do_latency) if (do_p2p)
{ {
grid_big_sep(); grid_big_sep();
std::cout << GridLogMessage << " Latency benchmark " << std::endl; std::cout << GridLogMessage << " Point-to-Point benchmark " << std::endl;
grid_big_sep(); grid_big_sep();
Benchmark::Latency(); Benchmark::PointToPoint();
} }
if (do_flops) if (do_flops)