-
Notifications
You must be signed in to change notification settings - Fork 99
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
Wiki examples: tests added #737
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ SET(KOKKOSKERNELS_TOP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | |
|
||
IF(NOT KOKKOSKERNELS_HAS_TRILINOS) | ||
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) | ||
IF (Spack_WORKAROUND) | ||
IF (Spack_WORKAROUND) | ||
#if we are explicitly using Spack for development, | ||
#nuke the Spack compiler | ||
SET(SPACK_CXX $ENV{SPACK_CXX}) | ||
|
@@ -28,7 +28,7 @@ IF(NOT KOKKOSKERNELS_HAS_TRILINOS) | |
SET(KokkosKernels_VERSION_PATCH 0) | ||
ENDIF() | ||
|
||
IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") | ||
IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") | ||
MESSAGE(STATUS "Setting policy CMP0074 to use <Package>_ROOT variables") | ||
CMAKE_POLICY(SET CMP0074 NEW) | ||
ENDIF() | ||
|
@@ -70,6 +70,7 @@ SET(KokkosKernels_INSTALL_TESTING OFF CACHE INTERNAL | |
IF (KokkosKernels_INSTALL_TESTING) | ||
# Force testing on if we are doing intall testing | ||
SET(KOKKOSKERNELS_ENABLE_TESTS ON) | ||
SET(KOKKOSKERNELS_ENABLE_EXAMPLES ON) | ||
# Don't build, load installed kernels | ||
FIND_PACKAGE(KokkosKernels REQUIRED) | ||
# Still need to figure out which backends | ||
|
@@ -78,6 +79,7 @@ IF (KokkosKernels_INSTALL_TESTING) | |
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(test_common) | ||
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(perf_test) | ||
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test) | ||
KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example) | ||
ELSE() | ||
# Regular build, not install testing | ||
# Do all the regular option processing | ||
|
@@ -188,7 +190,7 @@ ELSE() | |
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(test_common) | ||
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(perf_test) | ||
KOKKOSKERNELS_ADD_TEST_DIRECTORIES(unit_test) | ||
#KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example) | ||
KOKKOSKERNELS_ADD_EXAMPLE_DIRECTORIES(example) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would squash the two commits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured I would get comments on the CMake side at least so I felt like squashing was going to be an inevitability before the PR merges ; ) |
||
|
||
KOKKOSKERNELS_PACKAGE_POSTPROCESS() | ||
ENDIF() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
ADD_SUBDIRECTORY(fenl) | ||
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) | ||
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../test_common) | ||
|
||
#ADD_SUBDIRECTORY(fenl) | ||
#ADD_SUBDIRECTORY(graph) | ||
ADD_SUBDIRECTORY(wiki) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ADD_SUBDIRECTORY(sparse) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) | ||
KOKKOSKERNELS_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( | ||
wiki_crsmatrix | ||
SOURCES KokkosSparse_wiki_crsmatrix.cpp | ||
) | ||
|
||
KOKKOSKERNELS_ADD_EXECUTABLE_AND_TEST( | ||
wiki_spmv | ||
SOURCES KokkosSparse_wiki_spmv.cpp | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <sstream> | ||
|
||
#include "Kokkos_Core.hpp" | ||
|
||
#include "KokkosKernels_default_types.hpp" | ||
#include "KokkosSparse_CrsMatrix.hpp" | ||
#include "KokkosSparse_spmv.hpp" | ||
|
||
using Scalar = default_scalar; | ||
using Ordinal = default_lno_t; | ||
using Offset = default_size_type; | ||
using Layout = default_layout; | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(); | ||
|
||
using device_type = typename Kokkos::Device< | ||
Kokkos::DefaultExecutionSpace, | ||
typename Kokkos::DefaultExecutionSpace::memory_space>; | ||
using matrix_type = | ||
typename KokkosSparse::CrsMatrix<Scalar, Ordinal, device_type, void, | ||
Offset>; | ||
using graph_type = typename matrix_type::staticcrsgraph_type; | ||
using row_map_type = typename graph_type::row_map_type; | ||
using entries_type = typename graph_type::entries_type; | ||
using values_type = typename matrix_type::values_type; | ||
|
||
const Scalar SC_ONE = Kokkos::ArithTraits<Scalar>::one(); | ||
|
||
Ordinal numRows = 10; | ||
|
||
{ | ||
const Offset numNNZ = 2 + (numRows - 2) * 3 + 2; | ||
typename row_map_type::non_const_type row_map("row pointers", numRows + 1); | ||
typename entries_type::non_const_type entries("column indices", numNNZ); | ||
typename values_type::non_const_type values("values", numNNZ); | ||
|
||
{ | ||
// Build the row pointers and store numNNZ | ||
typename row_map_type::HostMirror row_map_h = | ||
Kokkos::create_mirror_view(row_map); | ||
for (Ordinal rowIdx = 1; rowIdx < numRows + 1; ++rowIdx) { | ||
if ((rowIdx == 1) || (rowIdx == numRows)) { | ||
row_map_h(rowIdx) = row_map_h(rowIdx - 1) + 2; | ||
} else { | ||
row_map_h(rowIdx) = row_map_h(rowIdx - 1) + 3; | ||
} | ||
} | ||
Kokkos::deep_copy(row_map, row_map_h); | ||
if (row_map_h(numRows) != numNNZ) { | ||
std::ostringstream error_msg; | ||
error_msg << "error: row_map(numRows) != numNNZ, row_map_h(numRows)=" | ||
<< row_map_h(numRows) << ", numNNZ=" << numNNZ; | ||
throw std::runtime_error(error_msg.str()); | ||
} | ||
|
||
typename entries_type::HostMirror entries_h = | ||
Kokkos::create_mirror_view(entries); | ||
typename values_type::HostMirror values_h = | ||
Kokkos::create_mirror_view(values); | ||
for (Ordinal rowIdx = 0; rowIdx < numRows; ++rowIdx) { | ||
if (rowIdx == 0) { | ||
entries_h(row_map_h(rowIdx)) = rowIdx; | ||
entries_h(row_map_h(rowIdx) + 1) = rowIdx + 1; | ||
|
||
values_h(row_map_h(rowIdx)) = SC_ONE; | ||
values_h(row_map_h(rowIdx) + 1) = -SC_ONE; | ||
} else if (rowIdx == numRows - 1) { | ||
entries_h(row_map_h(rowIdx)) = rowIdx - 1; | ||
entries_h(row_map_h(rowIdx) + 1) = rowIdx; | ||
|
||
values_h(row_map_h(rowIdx)) = -SC_ONE; | ||
values_h(row_map_h(rowIdx) + 1) = SC_ONE; | ||
} else { | ||
entries_h(row_map_h(rowIdx)) = rowIdx - 1; | ||
entries_h(row_map_h(rowIdx) + 1) = rowIdx; | ||
entries_h(row_map_h(rowIdx) + 2) = rowIdx + 1; | ||
|
||
values_h(row_map_h(rowIdx)) = -SC_ONE; | ||
values_h(row_map_h(rowIdx) + 1) = SC_ONE + SC_ONE; | ||
values_h(row_map_h(rowIdx) + 2) = -SC_ONE; | ||
} | ||
} | ||
Kokkos::deep_copy(entries, entries_h); | ||
Kokkos::deep_copy(values, values_h); | ||
} | ||
|
||
graph_type myGraph(entries, row_map); | ||
matrix_type myMatrix("test matrix", numRows, values, myGraph); | ||
std::cout << "myMatrix has been created successfully:" << std::endl | ||
<< " - numRows=" << myMatrix.numRows() << std::endl | ||
<< " - numCols=" << myMatrix.numCols() << std::endl | ||
<< " - numNNZ= " << myMatrix.nnz() << std::endl; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The examples don't print anything at the end. Is there some performance stat or some sort of message that makes sense to print so the user knows the test is running successfully? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a fair question, at the moment if an error happens during construction the test will fail, if it reaches completion is will return 0 which ctest interprets as success. |
||
Kokkos::finalize(); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "Kokkos_Core.hpp" | ||
|
||
#include "KokkosKernels_default_types.hpp" | ||
#include "KokkosSparse_CrsMatrix.hpp" | ||
#include "KokkosSparse_spmv.hpp" | ||
|
||
using Scalar = default_scalar; | ||
using Ordinal = default_lno_t; | ||
using Offset = default_size_type; | ||
using Layout = default_layout; | ||
|
||
template <class Yvector> | ||
struct check_spmv_functor { | ||
Yvector y; | ||
const Scalar SC_ONE = Kokkos::ArithTraits<Scalar>::one(); | ||
|
||
check_spmv_functor(Yvector y_) : y(y_){}; | ||
|
||
KOKKOS_INLINE_FUNCTION | ||
void operator()(const int i, Ordinal& update) const { | ||
if (y(i) != (SC_ONE + SC_ONE)) { | ||
++update; | ||
} | ||
} | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
Kokkos::initialize(); | ||
|
||
using device_type = typename Kokkos::Device< | ||
Kokkos::DefaultExecutionSpace, | ||
typename Kokkos::DefaultExecutionSpace::memory_space>; | ||
using matrix_type = | ||
typename KokkosSparse::CrsMatrix<Scalar, Ordinal, device_type, void, | ||
Offset>; | ||
using graph_type = typename matrix_type::staticcrsgraph_type; | ||
using row_map_type = typename graph_type::row_map_type; | ||
using entries_type = typename graph_type::entries_type; | ||
using values_type = typename matrix_type::values_type; | ||
|
||
int return_value = 0; | ||
|
||
{ | ||
const Scalar SC_ONE = Kokkos::ArithTraits<Scalar>::one(); | ||
|
||
Ordinal numRows = 10; | ||
|
||
// Build the row pointers and store numNNZ | ||
typename row_map_type::non_const_type row_map("row pointers", numRows + 1); | ||
typename row_map_type::HostMirror row_map_h = | ||
Kokkos::create_mirror_view(row_map); | ||
for (Ordinal rowIdx = 1; rowIdx < numRows + 1; ++rowIdx) { | ||
if ((rowIdx == 1) || (rowIdx == numRows)) { | ||
row_map_h(rowIdx) = row_map_h(rowIdx - 1) + 2; | ||
} else { | ||
row_map_h(rowIdx) = row_map_h(rowIdx - 1) + 3; | ||
} | ||
} | ||
const Offset numNNZ = row_map_h(numRows); | ||
Kokkos::deep_copy(row_map, row_map_h); | ||
|
||
typename entries_type::non_const_type entries("column indices", numNNZ); | ||
typename entries_type::HostMirror entries_h = | ||
Kokkos::create_mirror_view(entries); | ||
typename values_type::non_const_type values("values", numNNZ); | ||
typename values_type::HostMirror values_h = | ||
Kokkos::create_mirror_view(values); | ||
for (Ordinal rowIdx = 0; rowIdx < numRows; ++rowIdx) { | ||
if (rowIdx == 0) { | ||
entries_h(0) = rowIdx; | ||
entries_h(1) = rowIdx + 1; | ||
|
||
values_h(0) = SC_ONE; | ||
values_h(1) = -SC_ONE; | ||
} else if (rowIdx == numRows - 1) { | ||
entries_h(row_map_h(rowIdx)) = rowIdx - 1; | ||
entries_h(row_map_h(rowIdx) + 1) = rowIdx; | ||
|
||
values_h(row_map_h(rowIdx)) = -SC_ONE; | ||
values_h(row_map_h(rowIdx) + 1) = SC_ONE; | ||
} else { | ||
entries_h(row_map_h(rowIdx)) = rowIdx - 1; | ||
entries_h(row_map_h(rowIdx) + 1) = rowIdx; | ||
entries_h(row_map_h(rowIdx) + 2) = rowIdx + 1; | ||
|
||
values_h(row_map_h(rowIdx)) = -SC_ONE; | ||
values_h(row_map_h(rowIdx) + 1) = SC_ONE + SC_ONE; | ||
values_h(row_map_h(rowIdx) + 2) = -SC_ONE; | ||
} | ||
} | ||
Kokkos::deep_copy(entries, entries_h); | ||
Kokkos::deep_copy(values, values_h); | ||
|
||
graph_type myGraph(entries, row_map); | ||
matrix_type myMatrix("test matrix", numRows, values, myGraph); | ||
|
||
const Scalar alpha = SC_ONE; | ||
const Scalar beta = SC_ONE; | ||
|
||
typename values_type::non_const_type x("lhs", numRows); | ||
typename values_type::non_const_type y("rhs", numRows); | ||
Kokkos::deep_copy(x, SC_ONE); | ||
Kokkos::deep_copy(y, SC_ONE + SC_ONE); | ||
|
||
KokkosSparse::spmv("N", alpha, myMatrix, x, beta, y); | ||
|
||
Ordinal count_errors = 0; | ||
check_spmv_functor<values_type> check_spmv(y); | ||
Kokkos::parallel_reduce(Kokkos::RangePolicy<Ordinal>(0, numRows), | ||
check_spmv, count_errors); | ||
if (count_errors > 0) { | ||
return_value = 1; | ||
std::cout << "Found " << count_errors << " errors in y vector!" | ||
<< std::endl; | ||
} else { | ||
std::cout << "spmv was performed correctly: y = beta*y + alpha*A*x" | ||
<< std::endl; | ||
} | ||
} | ||
|
||
Kokkos::finalize(); | ||
|
||
return return_value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When doing install testing we force testing on. Does it make sense to do the same for examples?