Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update KHPCG3.0 for Kokkos v3.0 promotion #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ int CG(const SparseMatrix & A, CGData & data, const Vector & b, Vector & x,
local_int_1d_type orig_rows = A_Optimized-> orig_rows;
Optivector * x_Optimized = (Optivector *) x.optimizationData;
double_1d_type x_values = x_Optimized->values;
double_1d_type x_copy = double_1d_type("", x_values.dimension_0());
double_1d_type x_copy = double_1d_type("", x_values.extent(0));
/*
for(int i = 0; i < x_values.dimension_0(); i++)
for(int i = 0; i < x_values.extent(0); i++)
x_copy(orig_rows(i)) = x_values(i);
*/
Kokkos::parallel_for(x_values.dimension_0(), PermuteX(orig_rows, x_copy, x_values));
Kokkos::parallel_for(x_values.extent(0), PermuteX(orig_rows, x_copy, x_values));
//for(int i = 0; i < 10; i++)
// std::cout<<"Px("<<i<<") = "<<x_values(i)<< " x("<<i<<") = "<<x_copy(i)<<std::endl;
x_values = x_copy;
Expand Down
14 changes: 7 additions & 7 deletions src/ColorReorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ int ColorReorder(SparseMatrix & A, Vector & x, Vector & b){
Kokkos::deep_copy(host_b_values, b_values);
//WHOO!!!! BABY STEPS!
std::cout<<"REORDERING..." << std::endl;
values_type newValues("New Values on Device", localMatrix.values.dimension_0());
local_index_type newIndices("New entries on Device", localMatrix.graph.entries.dimension_0());
non_const_row_map_type newRowMap("New RowMap on Device", localMatrix.graph.row_map.dimension_0());
values_type newValues("New Values on Device", localMatrix.values.extent(0));
local_index_type newIndices("New entries on Device", localMatrix.graph.entries.extent(0));
non_const_row_map_type newRowMap("New RowMap on Device", localMatrix.graph.row_map.extent(0));
host_non_const_row_map_type host_newRowMap = Kokkos::create_mirror_view(newRowMap); // ASSUME THIS SETS IT TO ALL 0's
double_1d_type newX("New X_values on Device", x_values.dimension_0());
double_1d_type newX("New X_values on Device", x_values.extent(0));
host_double_1d_type host_newX = Kokkos::create_mirror_view(newX);
double_1d_type newB("New B values on Device", b_values.dimension_0());
double_1d_type newB("New B values on Device", b_values.extent(0));
host_double_1d_type host_newB = Kokkos::create_mirror_view(newB);
local_int_1d_type orig_rows = local_int_1d_type("Original row indices", A.localNumberOfRows);
host_local_int_1d_type host_orig_rows = Kokkos::create_mirror_view(orig_rows);
Expand Down Expand Up @@ -137,10 +137,10 @@ int ColorReorder(SparseMatrix & A, Vector & x, Vector & b){
Kokkos::deep_copy(newB, host_newB);
//This will permute the columns to help us maintain symmetry.
/*
for(int i = 0; i < newIndices.dimension_0(); i++)
for(int i = 0; i < newIndices.extent(0); i++)
newIndices(i) = host_row_dest(newIndices(i));
*/
Kokkos::parallel_for(newIndices.dimension_0(), PermuteColumn(row_dest, newIndices));
Kokkos::parallel_for(newIndices.extent(0), PermuteColumn(row_dest, newIndices));
local_int_1d_type new_diag("New Diagonal", A.localNumberOfRows);
/*
for(int i = 0; i < A.localNumberOfRows; i++){
Expand Down
20 changes: 10 additions & 10 deletions src/Coloring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Coloring{
array_type _vertexList;
array_type _recolorList;
ordinal_type _vertexListLength; // 0-dim Kokkos::View, so really Ordinal
ordinal_type _recolorListLength; // 0-dim Kokkos::View, so really Ordinal
ordinal_type _recolorListLength; // 0-dim Kokkos::View, so really Ordinal

ordinal_type::HostMirror host_vertexListLength;
ordinal_type::HostMirror host_recolorListLength;
Expand Down Expand Up @@ -143,7 +143,7 @@ class Coloring{
// This method is in serial so it will need a bit of reworking to be used on Cuda.
// Compute maxColor.
const int maxColor = 255; // Guess, since too expensive to loop over nvtx

int forbidden[maxColor+1];
Ordinal i = 0;
for(Ordinal k = 0; k < _size; k++){
Expand All @@ -158,7 +158,7 @@ class Coloring{
}

// recolor vertex i with smallest available color

// check neighbors
for(Ordinal j = _idx[i]; j < _idx[i+1]; j++){
if(_adj[j] == i) continue; // Skip self-loops
Expand Down Expand Up @@ -223,7 +223,7 @@ class fillColorsMap{
void operator()(const int & i)const{
int color = i+1; // Since i starts at 0 and colors start at 1.
int total = 0;
for(int j = 0; j < colors.dimension_0(); j++)
for(int j = 0; j < colors.extent(0); j++)
if(colors(j) == color) total++;
colors_map(color) = total;
}
Expand Down Expand Up @@ -259,7 +259,7 @@ class fillColorsInd{
void operator()(const int & i)const{
int color = i+1; // Colors start at 1 and i starts at 0.
int start = colors_map(i);
for(int j = 0; j < colors.dimension_0(); j++){
for(int j = 0; j < colors.extent(0); j++){
if(colors(j) == color){
colors_ind(start) = j;
start++;
Expand All @@ -274,10 +274,10 @@ int doColoring(SparseMatrix & A){
Optimatrix * A_Optimized = (Optimatrix*) A.optimizationData;
local_matrix_type localMatrix = A_Optimized->localMatrix;
Coloring::array_type colors("colors", A.localNumberOfRows);
Coloring::array_type idx("idx", localMatrix.graph.row_map.dimension_0()); // Should be A.localNumberOfRows+1 length
Coloring::array_type adj("adj", localMatrix.graph.entries.dimension_0()); // Should be A.LocalNumberOfNonzeros.
Kokkos::parallel_for(localMatrix.graph.row_map.dimension_0(), fillIdx(idx, localMatrix.graph.row_map));
Kokkos::parallel_for(localMatrix.graph.entries.dimension_0(), fillAdj(adj, localMatrix.graph.entries));
Coloring::array_type idx("idx", localMatrix.graph.row_map.extent(0)); // Should be A.localNumberOfRows+1 length
Coloring::array_type adj("adj", localMatrix.graph.entries.extent(0)); // Should be A.LocalNumberOfNonzeros.
Kokkos::parallel_for(localMatrix.graph.row_map.extent(0), fillIdx(idx, localMatrix.graph.row_map));
Kokkos::parallel_for(localMatrix.graph.entries.extent(0), fillAdj(adj, localMatrix.graph.entries));
Coloring c(A.localNumberOfRows, idx, adj, colors);
c.color(false, false, false); // Flags are as follows... Use conflict List, Serial Resolve Conflict, Time and show.
int numColors = c.getNumColors();
Expand All @@ -303,4 +303,4 @@ int doColoring(SparseMatrix & A){
if(A.Ac != 0) return doColoring(*A.Ac);
return(0);
}
#endif
#endif
8 changes: 4 additions & 4 deletions src/KokkosSetup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ This file is for the intention of creating things needed by Kokkos.
#ifndef KOKKOS_SETUP
#define KOKKOS_SETUP

#include <KokkosCore_config.h>
#include <Kokkos_Macros.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_Sparse.hpp>
#include <KokkosSparse.hpp>
#include "Kokkos_UnorderedMap.hpp"
#include "Geometry.hpp" // Just so we have the local_int_t and global_int_t definitions.

Expand Down Expand Up @@ -62,8 +62,8 @@ typedef const_global_int_2d_type::HostMirror host_const_global_int_2d_type;
typedef const_char_1d_type::HostMirror host_const_char_1d_type;
//CrsMatrix typedefs
//CrsMatrix types
typedef Kokkos::CrsMatrix<double, local_int_t, execution_space> local_matrix_type;
typedef Kokkos::CrsMatrix<double, global_int_t, execution_space> global_matrix_type;
typedef KokkosSparse::CrsMatrix<double, local_int_t, execution_space> local_matrix_type;
typedef KokkosSparse::CrsMatrix<double, global_int_t, execution_space> global_matrix_type;
typedef local_matrix_type::values_type values_type; // View for matrix values, similar to double_1d_type.
typedef local_matrix_type::index_type local_index_type; // View for column Indices, similar to local_int_1d_type.
typedef global_matrix_type::index_type global_index_type;
Expand Down
8 changes: 4 additions & 4 deletions src/LevelSYMGS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ assert(x.localLength == A.localNumberOfColumns); // Make sure x contains space f
Optivector * x_Optimized = (Optivector *) x.optimizationData;
double_1d_type x_values = x_Optimized->values;

double_1d_type z("z", x_values.dimension_0());
double_1d_type z("z", x_values.extent(0));
#ifdef KOKKOS_TEAM
const int row_per_team=256;
const int vector_size = 32;
Expand All @@ -118,18 +118,18 @@ assert(x.localLength == A.localNumberOfColumns); // Make sure x contains space f
int numberOfTeams = level_index_end - level_index_begin;
Kokkos::parallel_for(team_policy(numberOfTeams/teamSizeMax + 1, teamSizeMax, vector_size),
LeveledSweep(level_index_begin, level_index_end, localMatrix, f_lev_ind, r_values, x_values));
execution_space::fence();
execution_space().fence();
}
for(int i = 0; i < b_numLevels; i++){
int level_index_begin = b_lev_map(i);
int level_index_end = b_lev_map(i+1);
int numberOfTeams = level_index_end - level_index_begin;
Kokkos::parallel_for(team_policy(numberOfTeams/teamSizeMax + 1, teamSizeMax, vector_size),
LeveledSweep(level_index_begin, level_index_end, localMatrix, b_lev_ind, r_values, x_values));
execution_space::fence();
execution_space().fence();
}


#else
for(int i = 0; i < f_numLevels; i++){
int start = f_lev_map(i);
Expand Down
6 changes: 3 additions & 3 deletions src/LevelScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class fillColorsMap{
void operator()(const int & i)const{
int color = i+1;
int total = 0;
for(unsigned j = 0; j < colors.dimension_0(); j++)
for(unsigned j = 0; j < colors.extent(0); j++)
if(colors(j) == color) total++;
colors_map(color) = total;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ class fillColorsInd{
void operator()(const int & i)const{
int color = i+1; // Colors start at 1 and i starts at 0.
int start = colors_map(i);
for(unsigned j = 0; j < colors.dimension_0(); j++){
for(unsigned j = 0; j < colors.extent(0); j++){
if(colors(j) == color){
colors_ind(start) = j;
start++;
Expand Down Expand Up @@ -162,4 +162,4 @@ int levelSchedule(SparseMatrix & A){
else return(0);

}
#endif
#endif