Skip to content

Commit

Permalink
Fixed MueLu to run without deprecated tpetra code enabled.
Browse files Browse the repository at this point in the history
This has not been tested through the Amesos2 path since that is not fixed yet
  • Loading branch information
Matt Bettencourt authored and Matt Bettencourt committed Jun 17, 2021
1 parent c994e85 commit b8e903c
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 132 deletions.
22 changes: 11 additions & 11 deletions packages/muelu/adapters/xpetra/MueLu_RefMaxwell_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ namespace MueLu {
TEUCHOS_ASSERT(dirichletDomain.extent(0) == domMap->getNodeNumElements());
RCP<Xpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > myColsToZero = Xpetra::VectorFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Build(colMap, /*zeroOut=*/true);
// Find all local column indices that are in Dirichlet rows, record in myColsToZero as 1.0
auto myColsToZeroView = myColsToZero->getDeviceLocalView();
auto localMatrix = A.getLocalMatrix();
auto myColsToZeroView = myColsToZero->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto localMatrix = A.getLocalMatrixDevice();
Kokkos::parallel_for("MueLu:RefMaxwell::DetectDirichletCols", range_type(0,rowMap->getNodeNumElements()),
KOKKOS_LAMBDA(const LocalOrdinal row) {
if (dirichletRows(row)) {
Expand All @@ -228,8 +228,8 @@ namespace MueLu {
}
else
globalColsToZero = myColsToZero;
FindNonZeros<Scalar,LocalOrdinal,GlobalOrdinal,Node>(globalColsToZero->getDeviceLocalView(),dirichletDomain);
FindNonZeros<Scalar,LocalOrdinal,GlobalOrdinal,Node>(myColsToZero->getDeviceLocalView(),dirichletCols);
FindNonZeros<Scalar,LocalOrdinal,GlobalOrdinal,Node>(globalColsToZero->getDeviceLocalView(Xpetra::Access::ReadWrite),dirichletDomain);
FindNonZeros<Scalar,LocalOrdinal,GlobalOrdinal,Node>(myColsToZero->getDeviceLocalView(Xpetra::Access::ReadWrite),dirichletCols);
}

#endif
Expand Down Expand Up @@ -1667,7 +1667,7 @@ namespace MueLu {
typedef typename KCRS::values_type::non_const_type scalar_view_t;

// Get data out of P_nodal_imported and D0.
auto localD0 = D0_Matrix_->getLocalMatrix();
auto localD0 = D0_Matrix_->getLocalMatrixHost();

// Which algorithm should we use for the construction of the special prolongator?
// Option "mat-mat":
Expand All @@ -1677,7 +1677,7 @@ namespace MueLu {

if (skipFirstLevel_) {

auto localP = P_nodal_imported->getLocalMatrix();
auto localP = P_nodal_imported->getLocalMatrixHost();

if (algo == "mat-mat") {
RCP<Matrix> D0_P_nodal = MatrixFactory::Build(SM_Matrix_->getRowMap());
Expand All @@ -1688,7 +1688,7 @@ namespace MueLu {
#endif

// Get data out of D0*P.
auto localD0P = D0_P_nodal->getLocalMatrix();
auto localD0P = D0_P_nodal->getLocalMatrixHost();

// Create the matrix object
RCP<Map> blockColMap = Xpetra::MapFactory<LO,GO,NO>::Build(P_nodal_imported->getColMap(), dim);
Expand All @@ -1714,7 +1714,7 @@ namespace MueLu {
}
});

auto localNullspace = Nullspace_->getDeviceLocalView();
auto localNullspace = Nullspace_->getDeviceLocalView(Xpetra::Access::ReadOnly);

// enter values
if (D0_Matrix_->getNodeMaxNumRowEntries()>2) {
Expand Down Expand Up @@ -1786,8 +1786,8 @@ namespace MueLu {

NullspaceH_ = MultiVectorFactory::Build(P11_->getDomainMap(), dim);

auto localNullspace_nodal = Nullspace_nodal->getDeviceLocalView();
auto localNullspaceH = NullspaceH_->getDeviceLocalView();
auto localNullspace_nodal = Nullspace_nodal->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto localNullspaceH = NullspaceH_->getDeviceLocalView(Xpetra::Access::ReadWrite);
Kokkos::parallel_for("MueLu:RefMaxwell::buildProlongator_nullspace", range_type(0,Nullspace_nodal->getLocalLength()),
KOKKOS_LAMBDA(const size_t i) {
Scalar val = localNullspace_nodal(i,0);
Expand Down Expand Up @@ -1825,7 +1825,7 @@ namespace MueLu {
}
});

auto localNullspace = Nullspace_->getDeviceLocalView();
auto localNullspace = Nullspace_->getDeviceLocalView(Xpetra::Access::ReadOnly);

// enter values
if (D0_Matrix_->getNodeMaxNumRowEntries()>2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace MueLu {

int myPID = GetMap()->getComm()->getRank();

auto vertex2AggId = vertex2AggId_->getDeviceLocalView();
auto procWinner = procWinner_ ->getDeviceLocalView();
auto vertex2AggId = vertex2AggId_->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto procWinner = procWinner_ ->getDeviceLocalView(Xpetra::Access::ReadOnly);

typename AppendTrait<decltype(aggregateSizes_), Kokkos::Atomic>::type aggregateSizesAtomic = aggregateSizes;
Kokkos::parallel_for("MueLu:Aggregates:ComputeAggregateSizes:for", range_type(0,procWinner.size()),
Expand Down Expand Up @@ -135,8 +135,8 @@ namespace MueLu {
if (static_cast<LO>(graph_.numRows()) == numAggregates)
return graph_;

auto vertex2AggId = vertex2AggId_->getDeviceLocalView();
auto procWinner = procWinner_ ->getDeviceLocalView();
auto vertex2AggId = vertex2AggId_->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto procWinner = procWinner_ ->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto sizes = ComputeAggregateSizes();

// FIXME_KOKKOS: replace by ViewAllocateWithoutInitializing + rows(0) = 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ namespace MueLu {
boundaryNodes = Utilities_kokkos::DetectDirichletRows(*A, dirichletThreshold);

// Trivial LWGraph construction
graph = rcp(new LWGraph_kokkos(A->getLocalMatrix().graph, A->getRowMap(), A->getColMap(), "graph of A"));
graph = rcp(new LWGraph_kokkos(A->getLocalMatrixDevice().graph, A->getRowMap(), A->getColMap(), "graph of A"));
graph->SetBoundaryNodeMap(boundaryNodes);

numTotal = A->getNodeNumEntries();
Expand All @@ -546,7 +546,7 @@ namespace MueLu {
typedef typename local_matrix_type::values_type::non_const_type vals_type;

LO numRows = A->getNodeNumRows();
auto kokkosMatrix = A->getLocalMatrix();
auto kokkosMatrix = A->getLocalMatrixDevice();
auto nnzA = kokkosMatrix.nnz();
auto rowsA = kokkosMatrix.graph.row_map;

Expand All @@ -573,7 +573,7 @@ namespace MueLu {
filteredA->fillComplete(fillCompleteParams);

// No need to reuseFill, just modify in place
valsAux = filteredA->getLocalMatrix().values;
valsAux = filteredA->getLocalMatrixDevice().values;

} else {
// Need an extra array to compress
Expand All @@ -596,7 +596,7 @@ namespace MueLu {
{
SubFactoryMonitor m2(*this, "MainLoop", currentLevel);

auto ghostedDiagView = ghostedDiag->getDeviceLocalView();
auto ghostedDiagView = ghostedDiag->getDeviceLocalView(Xpetra::Access::ReadWrite);

CoalesceDrop_Kokkos_Details::ClassicalDropFunctor<LO, decltype(ghostedDiagView)> dropFunctor(ghostedDiagView, threshold);
CoalesceDrop_Kokkos_Details::ScalarFunctor<typename ATS::val_type, LO, local_matrix_type, decltype(bndNodes), decltype(dropFunctor)>
Expand Down Expand Up @@ -626,7 +626,7 @@ namespace MueLu {
ghostedCoords->doImport(*coords, *importer, Xpetra::INSERT);
}

auto ghostedCoordsView = ghostedCoords->getDeviceLocalView();
auto ghostedCoordsView = ghostedCoords->getDeviceLocalView(Xpetra::Access::ReadWrite);
CoalesceDrop_Kokkos_Details::DistanceFunctor<LO, decltype(ghostedCoordsView)> distFunctor(ghostedCoordsView);

// Construct Laplacian diagonal
Expand All @@ -636,7 +636,7 @@ namespace MueLu {

localLaplDiag = VectorFactory::Build(uniqueMap);

auto localLaplDiagView = localLaplDiag->getDeviceLocalView();
auto localLaplDiagView = localLaplDiag->getDeviceLocalView(Xpetra::Access::OverwriteAll);
auto kokkosGraph = kokkosMatrix.graph;

Kokkos::parallel_for("MueLu:CoalesceDropF:Build:scalar_filter:laplacian_diag", range_type(0,numRows),
Expand Down Expand Up @@ -666,7 +666,7 @@ namespace MueLu {
{
SubFactoryMonitor m2(*this, "MainLoop", currentLevel);

auto ghostedLaplDiagView = ghostedLaplDiag->getDeviceLocalView();
auto ghostedLaplDiagView = ghostedLaplDiag->getDeviceLocalView(Xpetra::Access::ReadWrite);

CoalesceDrop_Kokkos_Details::DistanceLaplacianDropFunctor<LO, decltype(ghostedLaplDiagView), decltype(distFunctor)>
dropFunctor(ghostedLaplDiagView, distFunctor, threshold);
Expand Down Expand Up @@ -818,7 +818,7 @@ namespace MueLu {
if (blkId > -1)
blkPartSize = Teuchos::as<LocalOrdinal>(strMap->getStridingData()[blkId]);
}
auto kokkosMatrix = A->getLocalMatrix(); // access underlying kokkos data
auto kokkosMatrix = A->getLocalMatrixDevice(); // access underlying kokkos data

//
typedef typename LWGraph_kokkos::local_graph_type kokkos_graph_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace MueLu {

RCP<const GraphBase> graph = Get< RCP<GraphBase> >(currentLevel, "Graph");
RCP<const Matrix> A = Get< RCP<Matrix> >(currentLevel, "A");
local_matrix_type localA = A->getLocalMatrix();
local_matrix_type localA = A->getLocalMatrixDevice();

// Setup aggregates & aggStat objects
RCP<Aggregates> aggregates = rcp(new Aggregates(*graph));
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace MueLu {
// columns corresponding to local rows.
LO numLocalDirichletNodes = numDirichletNodes;
Array<LO> localVertex2AggId(aggregates->GetVertex2AggId()->getData(0).view(0, numRows));
BuildOnRankLocalMatrix(A->getLocalMatrix(), coarseLocalA);
BuildOnRankLocalMatrix(A->getLocalMatrixDevice(), coarseLocalA);
for(LO aggregationIter = 1; aggregationIter < maxNumIter; ++aggregationIter) {
// Compute the intermediate prolongator
BuildIntermediateProlongator(coarseLocalA.numRows(), numLocalDirichletNodes, numLocalAggregates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace MueLu {
using execution_space = typename local_graph_type::device_type::execution_space;
using memory_space = typename local_graph_type::device_type::memory_space;

using LOVectorView = decltype(std::declval<LOVector>().getDeviceLocalView());
using LOVectorView = decltype(std::declval<LOVector>().getDeviceLocalView(Xpetra::Access::ReadWrite));
using constIntTupleView = typename Kokkos::View<const int[3], memory_space>;
using constLOTupleView = typename Kokkos::View<const LO[3], memory_space>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ namespace MueLu {
RCP<IndexManager_kokkos> geoData = aggregates.GetIndexManager();
const LO numLocalFineNodes= geoData->getNumLocalFineNodes();
const LO numCoarseNodes = geoData->getNumCoarseNodes();
LOVectorView vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
LOVectorView procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
LOVectorView vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
LOVectorView procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);

*out << "Loop over fine nodes and assign them to an aggregate and a rank" << std::endl;
LO numAggregatedNodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ namespace MueLu {
const int myRank = graph.GetComm()->getRank();

// Extract data from aggregates
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();

LO numAggregatedNodes = 0;
Expand Down Expand Up @@ -213,8 +213,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();

LO numLocalAggregates = aggregates.GetNumAggregates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();
const LO numColors = aggregates.GetGraphNumColors();

Expand Down Expand Up @@ -213,8 +213,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();
const LO numColors = aggregates.GetGraphNumColors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();
const LO numColors = aggregates.GetGraphNumColors();
const LO numLocalAggregates = aggregates.GetNumAggregates();
Expand Down Expand Up @@ -195,8 +195,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();
const LO numColors = aggregates.GetGraphNumColors();
LO numLocalAggregates = aggregates.GetNumAggregates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ namespace MueLu {
const LO numRows = graph.GetNodeNumVertices();
const int myRank = graph.GetComm()->getRank();

auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto colors = aggregates.GetGraphColors();
const LO numColors = aggregates.GetGraphNumColors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ namespace MueLu {
const int myRank = graph.GetComm()->getRank();

// 3) the aggregates
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto procWinner = aggregates.GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadWrite);

// A view is needed to count on the fly the current number of local aggregates
Kokkos::View<LO, memory_space> aggCount("aggCount");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ namespace MueLu {
auto aggGraph = aggregates->GetGraph();
auto numAggs = aggGraph.numRows();

auto fineCoordsView = fineCoords ->getDeviceLocalView();
auto coarseCoordsView = coarseCoords->getDeviceLocalView();
auto fineCoordsView = fineCoords ->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);

// Fill in coarse coordinates
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ namespace MueLu {
Build(coarseCoordsMap, fineCoordinates->getNumVectors());

// Construct and launch functor to fill coarse coordinates values
// function should take a const view really
coarseCoordinatesBuilderFunctor myCoarseCoordinatesBuilder(geoData,
fineCoordinates-> getDeviceLocalView(),
coarseCoordinates->getDeviceLocalView());
fineCoordinates-> getDeviceLocalView(Xpetra::Access::ReadWrite),
coarseCoordinates->getDeviceLocalView(Xpetra::Access::OverwriteAll));
Kokkos::parallel_for("GeometricInterpolation: build coarse coordinates",
Kokkos::RangePolicy<execution_space>(0, geoData->getNumCoarseNodes()),
myCoarseCoordinatesBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace MueLu {
GetOStream(Runtime1) << "Generating canonical nullspace: dimension = " << numPDEs << std::endl;

nullspace = MultiVectorFactory::Build(A->getDomainMap(), numPDEs);
auto nullspaceView = nullspace->getDeviceLocalView();
auto nullspaceView = nullspace->getDeviceLocalView(Xpetra::Access::OverwriteAll);

int numBlocks = nullspace->getLocalLength() / numPDEs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ struct constraintKernel {
LO nPDEs = A->GetFixedBlockSize();

using local_mat_type = typename Matrix::local_matrix_type;
constraintKernel<local_mat_type> myKernel(nPDEs,P->getLocalMatrix() );
constraintKernel<local_mat_type> myKernel(nPDEs,P->getLocalMatrixDevice() );
Kokkos::parallel_for("enforce constraint",Kokkos::RangePolicy<typename Device::execution_space>(0, P->getRowMap()->getNodeNumElements() ),
myKernel );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ namespace MueLu {
auto aggGraph = aggregates->GetGraph();
auto numAggs = aggGraph.numRows();

auto fineCoordsView = fineCoords ->getDeviceLocalView();
auto coarseCoordsView = coarseCoords->getDeviceLocalView();
auto fineCoordsView = fineCoords ->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);

// Fill in coarse coordinates
{
Expand Down Expand Up @@ -615,8 +615,8 @@ namespace MueLu {
GO globalOffset = amalgInfo->GlobalOffset();

// Extract aggregation info (already in Kokkos host views)
auto procWinner = aggregates->GetProcWinner() ->getDeviceLocalView();
auto vertex2AggId = aggregates->GetVertex2AggId()->getDeviceLocalView();
auto procWinner = aggregates->GetProcWinner() ->getDeviceLocalView(Xpetra::Access::ReadOnly);
auto vertex2AggId = aggregates->GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadOnly);
const size_t numAggregates = aggregates->GetNumAggregates();

int myPID = aggregates->GetMap()->getComm()->getRank();
Expand Down Expand Up @@ -709,8 +709,8 @@ namespace MueLu {
coarseNullspace = MultiVectorFactory::Build(coarseMap, NSDim);

// Pull out the nullspace vectors so that we can have random access (on the device)
auto fineNS = fineNullspace ->getDeviceLocalView();
auto coarseNS = coarseNullspace->getDeviceLocalView();
auto fineNS = fineNullspace ->getDeviceLocalView(Xpetra::Access::ReadWrite);
auto coarseNS = coarseNullspace->getDeviceLocalView(Xpetra::Access::OverwriteAll);

size_t nnz = 0; // actual number of nnz

Expand Down
Loading

0 comments on commit b8e903c

Please sign in to comment.