Skip to content

Commit

Permalink
stokhos : simplify testing with cmake macro
Browse files Browse the repository at this point in the history
  • Loading branch information
romintomasetti committed Jul 7, 2022
1 parent 982b460 commit 43d3bc5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace Stokhos {
Vector& vec = const_cast<Vector&>(vec_const);

// Get data
ArrayRCP<Scalar> vec_vals = vec.get1dViewNonConst();
auto vec_vals = vec.getLocalViewDevice(Tpetra::Access::ReadOnly);
const size_t vec_size = vec_vals.size();

// Create view of data
Expand Down Expand Up @@ -329,7 +329,7 @@ namespace Stokhos {
const LocalOrdinal mp_size = Storage::static_size;

// Get data
ArrayRCP<Scalar> vec_vals = vec.get1dViewNonConst();
auto vec_vals = vec.getLocalViewDevice(Tpetra::Access::ReadOnly);
const size_t vec_size = vec_vals.size();

// Create view of data
Expand Down
87 changes: 41 additions & 46 deletions packages/stokhos/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -727,52 +727,47 @@ IF(Stokhos_ENABLE_Sacado)

IF (Stokhos_ENABLE_Tpetra)

IF (HAVE_TPETRA_PTHREAD)
TRIBITS_ADD_EXECUTABLE_AND_TEST(
TpetraCrsMatrixMPVectorUnitTest_Threads
SOURCES Stokhos_TpetraCrsMatrixMPVectorUnitTest.hpp
Stokhos_TpetraCrsMatrixMPVectorUnitTest_Threads.cpp
COMM serial mpi
STANDARD_PASS_OUTPUT
NUM_MPI_PROCS 4
RUN_SERIAL
)
ENDIF()

IF (HAVE_TPETRA_SERIAL)
TRIBITS_ADD_EXECUTABLE_AND_TEST(
TpetraCrsMatrixMPVectorUnitTest_Serial
SOURCES Stokhos_TpetraCrsMatrixMPVectorUnitTest.hpp
Stokhos_TpetraCrsMatrixMPVectorUnitTest_Serial.cpp
COMM serial mpi
STANDARD_PASS_OUTPUT
NUM_MPI_PROCS 4
)
ENDIF()

IF (HAVE_TPETRA_OPENMP)
TRIBITS_ADD_EXECUTABLE_AND_TEST(
TpetraCrsMatrixMPVectorUnitTest_OpenMP
SOURCES Stokhos_TpetraCrsMatrixMPVectorUnitTest.hpp
Stokhos_TpetraCrsMatrixMPVectorUnitTest_OpenMP.cpp
COMM serial mpi
STANDARD_PASS_OUTPUT
NUM_MPI_PROCS 4
RUN_SERIAL
)
ENDIF()

IF (HAVE_TPETRA_CUDA)
TRIBITS_ADD_EXECUTABLE_AND_TEST(
TpetraCrsMatrixMPVectorUnitTest_Cuda
SOURCES Stokhos_TpetraCrsMatrixMPVectorUnitTest.hpp
Stokhos_TpetraCrsMatrixMPVectorUnitTest_Cuda.cpp
COMM serial mpi
STANDARD_PASS_OUTPUT
NUM_MPI_PROCS 4
RUN_SERIAL
)
ENDIF()
# Use this function to add a test "TEST_NAME" that will be added conditionally on
# the value of "${VARIABLE_PREFIX}_${SPACE_CHECK}".
# Note that if the execution space matches "Serial", "RUN_SERIAL" is not added to
# "TRIBITS_ADD_EXECUTABLE_AND_TEST".
# The test compile unit will have access to the execution space through the defined variable "STOKHOS_TEST_SPACE".
function(STOKHOS_ADD_EXECUTABLE_AND_TEST)
cmake_parse_arguments(PARSE "" "TEST_NAME;VARIABLE_PREFIX" "SPACES_CHECK;SPACES_KOKKOS" "${ARGN}")
tribits_check_for_unparsed_arguments()
list(LENGTH PARSE_SPACES_CHECK length_space_check)
list(LENGTH PARSE_SPACES_KOKKOS length_space_kokkos)
foreach(space_check space_kokkos IN ZIP_LISTS PARSE_SPACES_CHECK PARSE_SPACES_KOKKOS)
if(${${PARSE_VARIABLE_PREFIX}_${space_check}})
if(NOT "${space_kokkos}" STREQUAL "Serial")
set(RUN_SERIAL RUN_SERIAL)
else()
SET(RUN_SERIAL )
endif()
TRIBITS_ADD_EXECUTABLE_AND_TEST(
"${PARSE_TEST_NAME}_${space_kokkos}"
SOURCES "Stokhos_${PARSE_TEST_NAME}.hpp"
"Stokhos_${PARSE_TEST_NAME}_main.cpp"
COMM serial mpi
STANDARD_PASS_OUTPUT
NUM_MPI_PROCS 4
${RUN_SERIAL}
)
target_compile_definitions(
"Stokhos_${PARSE_TEST_NAME}_${space_kokkos}"
PRIVATE
STOKHOS_TEST_SPACE=${space_kokkos}
)
endif()
endforeach()
endfunction()

STOKHOS_ADD_EXECUTABLE_AND_TEST(
TEST_NAME TpetraCrsMatrixMPVectorUnitTest
VARIABLE_PREFIX "HAVE_TPETRA"
SPACES_CHECK "PTHREAD;SERIAL;OPENMP;CUDA;HIP"
SPACES_KOKKOS "Threads;Serial;OpenMP;Cuda;HIP"
)

ENDIF()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,13 +978,15 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(
RCP<Flat_Tpetra_CrsMatrix> flat_matrix =
Stokhos::create_flat_matrix(*matrix, flat_graph, VectorSize);

// Multiply with flattened matix
// Multiply with flattened matrix
RCP<Tpetra_Vector> y2 = Tpetra::createVector<Scalar>(map);
RCP<Flat_Tpetra_Vector> flat_x =
Stokhos::create_flat_vector_view(*x, flat_x_map);
RCP<Flat_Tpetra_Vector> flat_y =
Stokhos::create_flat_vector_view(*y2, flat_y_map);
flat_matrix->apply(*flat_x, *flat_y);
{
RCP<Flat_Tpetra_Vector> flat_x =
Stokhos::create_flat_vector_view(*x, flat_x_map);
RCP<Flat_Tpetra_Vector> flat_y =
Stokhos::create_flat_vector_view(*y2, flat_y_map);
flat_matrix->apply(*flat_x, *flat_y);
}

// flat_y->describe(*(Teuchos::fancyOStream(rcp(&std::cout,false))),
// Teuchos::VERB_EXTREME);
Expand Down Expand Up @@ -2516,3 +2518,13 @@ TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(
// using default_global_ordinal_type = ::Tpetra::Map<>::global_ordinal_type;
// using default_local_ordinal_type = ::Tpetra::Map<>::local_ordinal_type;
// CRSMATRIX_MP_VECTOR_TESTS_SLGN(DS, default_global_ordinal_type, default_local_ordinal_type, N)

// Instantiate tests for the required node type defined by STOKHOS_TEST_SPACE
#ifndef STOKHOS_TEST_SPACE
#error "STOKHOS_TEST_SPACE must be defined."
#endif

#define GENERATE_WRAPPER_NODE_NAME WrapperNode##STOKHOS_TEST_SPACE

typedef Kokkos::Compat::KokkosDeviceWrapperNode<Kokkos::STOKHOS_TEST_SPACE> GENERATE_WRAPPER_NODE_NAME;
CRSMATRIX_MP_VECTOR_TESTS_N( GENERATE_WRAPPER_NODE_NAME )

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 43d3bc5

Please sign in to comment.