From 8261dc39d9497871b70af7e7ec25871bad456d5d Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Mon, 24 Aug 2026 10:56:16 -0400 Subject: [PATCH] More tracing --- .../deflation/MultiRHSBlockProject.h | 10 ++ Grid/algorithms/multigrid/DenseCoarseMatrix.h | 96 +++++++++++-------- .../GeneralCoarsenedMatrixMultiRHSV2.h | 16 +++- ...mple_pvdagm_v2_3level_DenseCoarseMatrix.cc | 95 +++++++++++------- 4 files changed, 144 insertions(+), 73 deletions(-) diff --git a/Grid/algorithms/deflation/MultiRHSBlockProject.h b/Grid/algorithms/deflation/MultiRHSBlockProject.h index ca0f65fb4..1afceba80 100644 --- a/Grid/algorithms/deflation/MultiRHSBlockProject.h +++ b/Grid/algorithms/deflation/MultiRHSBlockProject.h @@ -760,6 +760,7 @@ public: template void blockProject(std::vector &fine,std::vector< Lattice > & coarse) { + GRID_TRACE("BlockProject"); int nrhs=fine.size(); int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); // std::cout << "blockProject nbasis " < void blockPromote(std::vector &fine,std::vector > & coarse) { + GRID_TRACE("BlockPromote"); int nrhs=fine.size(); int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -877,6 +879,7 @@ public: template void blockProject(Field &fine_mrhs,Lattice &coarse_mrhs) { + GRID_TRACE("BlockProjectMrhs"); int nrhs = fine_mrhs.Grid()->_rdimensions[0]; int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -893,6 +896,7 @@ public: template void blockPromote(Field &fine_mrhs,Lattice &coarse_mrhs) { + GRID_TRACE("BlockPromoteMrhs"); int nrhs = fine_mrhs.Grid()->_rdimensions[0]; int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -913,6 +917,7 @@ public: template void blockProject(std::vector &fine,Lattice &coarse_mrhs) { + GRID_TRACE("BlockProjectMixed"); int nrhs = fine.size(); int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -929,6 +934,7 @@ public: template void blockProject(Field &fine_mrhs,std::vector< Lattice > &coarse) { + GRID_TRACE("BlockProjectMixed"); int nrhs = fine_mrhs.Grid()->_rdimensions[0]; int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -945,6 +951,7 @@ public: template void blockPromote(std::vector &fine,Lattice &coarse_mrhs) { + GRID_TRACE("BlockPromoteMixed"); int nrhs = fine.size(); int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -961,6 +968,7 @@ public: template void blockPromote(Field &fine_mrhs,std::vector< Lattice > &coarse) { + GRID_TRACE("BlockPromoteMixed"); int nrhs = fine_mrhs.Grid()->_rdimensions[0]; int _nbasis = sizeof(typename cobj::scalar_object)/sizeof(scalar); GRID_ASSERT(nbasis==_nbasis); @@ -1002,6 +1010,7 @@ public: // C_br = V^dag F void ProjectBLAS(int nrhs) { + GRID_TRACE("ProjectBLAS"); deviceVector Vd(coarse_vol); deviceVector Fd(coarse_vol); deviceVector Cd(coarse_vol); @@ -1022,6 +1031,7 @@ public: // F_xr = Vxb Cbr void PromoteBLAS(int nrhs) { + GRID_TRACE("PromoteBLAS"); deviceVector Vd(coarse_vol); deviceVector Fd(coarse_vol); deviceVector Cd(coarse_vol); diff --git a/Grid/algorithms/multigrid/DenseCoarseMatrix.h b/Grid/algorithms/multigrid/DenseCoarseMatrix.h index a08e9f876..f581f71b4 100644 --- a/Grid/algorithms/multigrid/DenseCoarseMatrix.h +++ b/Grid/algorithms/multigrid/DenseCoarseMatrix.h @@ -948,6 +948,7 @@ public: //////////////////////////////////////////////////////////////////// void SlabApplyPacked(int nr, double *tprof) { + GRID_TRACE("DenseSlabApply"); GRID_ASSERT(nr <= MRHS_MAX); uint64_t nX = (uint64_t)N * nr; uint64_t nY = (uint64_t)nrows * nr; @@ -955,14 +956,22 @@ public: double t1 = usecond(); double t2, t3; if (devSum) { - acceleratorCopyToDevice(&hX[0],&dX[0],nX*sizeof(ComplexF)); + { GRID_TRACE("DenseH2D"); + acceleratorCopyToDevice(&hX[0],&dX[0],nX*sizeof(ComplexF)); + } t2 = usecond(); - grid->GlobalSumVector((ComplexF *)&dX[0], (int)nX); + { GRID_TRACE("DenseAllreduce"); + grid->GlobalSumVector((ComplexF *)&dX[0], (int)nX); + } t3 = usecond(); } else { - grid->GlobalSumVector(&hX[0], (int)nX); + { GRID_TRACE("DenseAllreduce"); + grid->GlobalSumVector(&hX[0], (int)nX); + } t2 = usecond(); - acceleratorCopyToDevice(&hX[0],&dX[0],nX*sizeof(ComplexF)); + { GRID_TRACE("DenseH2D"); + acceleratorCopyToDevice(&hX[0],&dX[0],nX*sizeof(ComplexF)); + } t3 = usecond(); } // Y = op(slab,T) . X : row-major slab (nrows x N) == col-major A^T @@ -970,13 +979,13 @@ public: // Split-K: NK chunk-GEMMs by pointer offset (AOT lists), then reduce. ComplexF one (1.0,0.0); ComplexF zero(0.0,0.0); - BLAS.gemmBatched(GridBLAS_OP_T, GridBLAS_OP_N, - (int)nrows, nr, (int)Kc, - one, aptrs, (int)N, - xptrs, (int)N, - zero, cptrs, (int)nrows); - BLAS.synchronise(); - { + { GRID_TRACE("DenseSplitKGEMM"); + BLAS.gemmBatched(GridBLAS_OP_T, GridBLAS_OP_N, + (int)nrows, nr, (int)Kc, + one, aptrs, (int)N, + xptrs, (int)N, + zero, cptrs, (int)nrows); + BLAS.synchronise(); ComplexF *pp = &dPartial[0]; ComplexF *py = &dY[0]; uint64_t stride = (uint64_t)nrows*MRHS_MAX; @@ -988,7 +997,9 @@ public: }); } double t4 = usecond(); - acceleratorCopyFromDevice(&dY[0],&hY[0],nY*sizeof(ComplexF)); + { GRID_TRACE("DenseD2H"); + acceleratorCopyFromDevice(&dY[0],&hY[0],nY*sizeof(ComplexF)); + } double t5 = usecond(); if (tprof) { tprof[0] = devSum ? (t3-t2) : (t2-t1); // allreduce @@ -1003,20 +1014,25 @@ public: //////////////////////////////////////////////////////////////////// virtual void operator()(const Field &src, Field &psi) { + GRID_TRACE("DenseApply1"); uint64_t nX = (uint64_t)N; - thread_for(i, nX, { hX[i]=ComplexF(0.0,0.0); }); - for(int ss=0; ss(in6); uint64_t nX = (uint64_t)N * nr; thread_for(i, nX, { hX[i]=ComplexF(0.0,0.0); }); - { + { GRID_TRACE("DensePack"); autoView(iv, in, CpuRead); Coordinate c6(nd+1); for(int ss=0; ssExchangePeriodic(tin); //padded input + // lambda scope so the roctx range covers exactly the exchange; the + // PaddedCellFwd/BwdMPI markers inside it then nest properly. + CoarseVector pin = [&](){ GRID_TRACE("CoarseV2Exchange"); + return CellMulti->ExchangePeriodic(tin); }(); //padded input t_exch+=usecond(); CoarseVector pout(pin.Grid()); @@ -812,12 +816,15 @@ public: t_GtoB=-usecond(); - GridtoBLAS(pin,BLAS_B); + { GRID_TRACE("CoarseV2GridToBLAS"); + GridtoBLAS(pin,BLAS_B); + } t_GtoB+=usecond(); GridBLAS BLAS; t_mult=-usecond(); + { GRID_TRACE("CoarseV2StencilGEMM"); for(int p=0;p SetFineSloppy = [](int){}; void ParseEnvironment(void) { @@ -388,23 +400,37 @@ public: : _FineOperator(FineOp),_PostSmoother(Post),_Projector(Projector),_CoarseSolve(CoarseSolve), _CoarseGrid(CoarseGrid),_CoarseGridMrhs(CoarseGridMrhs){} virtual void operator()(std::vector &in, std::vector &out){ + // The whole V-cycle is preconditioner: its fine residuals and the + // smoother run with sloppy halos; the caller (the outer Krylov) gets + // the exact operator back on exit. + GRID_TRACE("MGVcycle"); + SetFineSloppy(FineSloppyComms); int nrhs=in.size(); GridBase *fgrid=in[0].Grid(); std::vector vec1(nrhs,fgrid),vec2(nrhs,fgrid); for(int r=0;r D+1 coarse, via the mixed blockProject CoarseVector CsrcMrhs(_CoarseGridMrhs), CsolMrhs(_CoarseGridMrhs); - _Projector.blockProject(vec1,CsrcMrhs); - + { GRID_TRACE("MGProject"); + _Projector.blockProject(vec1,CsrcMrhs); + } CsolMrhs=Zero(); - _CoarseSolve(CsrcMrhs,CsolMrhs); - - _Projector.blockPromote(vec1,CsolMrhs); - for(int r=0;r PVdagM_t; typedef ShiftedPVdagMLinearOperator ShiftedPVdagM_t; @@ -546,6 +575,7 @@ int main (int argc, char ** argv) CoarseOpPV.SetGrid(CoarseBatch); std::cout << GridLogMessage << "*** L1 CoarsenOperator, batch "<