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

Kokkos: Add Performance class #336

Merged
merged 1 commit into from
Oct 31, 2018
Merged
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
13 changes: 12 additions & 1 deletion Makefile.kokkos-kernels
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ KOKKOSKERNELS_SPACES ?= $(KOKKOS_DEVICES),HostSpace
KOKKOSKERNELS_ORDINALS ?= int,int64_t
KOKKOSKERNELS_OFFSETS ?= int,size_t

# mkl, blas
# mkl, blas, yaml
KOKKOSKERNELS_ENABLE_TPLS ?= ""

# eti-only
KOKKOSKERNELS_OPTIONS ?= ""

KOKKOSKERNELS_INTERNAL_ENABLE_YAML := $(strip $(shell echo $(KOKKOSKERNELS_ENABLE_TPLS) | grep "yaml" | wc -l))
KOKKOSKERNELS_INTERNAL_ENABLE_BLAS := $(strip $(shell echo $(KOKKOSKERNELS_ENABLE_TPLS) | grep "blas" | wc -l))
KOKKOSKERNELS_INTERNAL_ENABLE_MKL := $(strip $(shell echo $(KOKKOSKERNELS_ENABLE_TPLS) | grep "mkl" | wc -l))
KOKKOSKERNELS_INTERNAL_ENABLE_CUSPARSE := $(strip $(shell echo $(KOKKOSKERNELS_ENABLE_TPLS) | grep "cusparse" | wc -l))
KOKKOSKERNELS_INTERNAL_ENABLE_CUBLAS := $(strip $(shell echo $(KOKKOSKERNELS_ENABLE_TPLS) | grep "cublas" | wc -l))

YAML_PATH ?= ${HOME}/yaml-cpp/install
YAML_LIBS ?= -L${YAML_PATH}/lib -lyaml-cpp

BLAS_PATH ?= /usr
BLAS_LIBS ?= -L${BLAS_PATH}/lib64 $(BLAS_LIBRARIES) -lgfortran -lgomp

Expand Down Expand Up @@ -229,6 +234,12 @@ tmp := $(shell echo "/* ---------------------------------------------" >> Kokkos
tmp := $(shell echo "Third Party Libraries:" >> KokkosKernels_config.tmp)
tmp := $(shell echo " ---------------------------------------------*/" >> KokkosKernels_config.tmp)

ifeq (${KOKKOSKERNELS_INTERNAL_ENABLE_YAML}, 1)
KOKKOSKERNELS_CPPFLAGS += -I${YAML_PATH}/include
KOKKOSKERNELS_LIBS += ${YAML_LIBS}
tmp := $(shell echo "\#define KOKKOSKERNELS_ENABLE_TPL_YAML" >> KokkosKernels_config.tmp )
endif

ifeq (${KOKKOSKERNELS_INTERNAL_ENABLE_BLAS}, 1)
KOKKOSKERNELS_LIBS += ${BLAS_LIBS}
tmp := $(shell echo "\#define KOKKOSKERNELS_ENABLE_TPL_BLAS" >> KokkosKernels_config.tmp )
Expand Down
1 change: 1 addition & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TRIBITS_PACKAGE_DEFINE_DEPENDENCIES(
LIB_REQUIRED_PACKAGES KokkosCore KokkosContainers KokkosAlgorithms
LIB_OPTIONAL_TPLS quadmath MKL BLAS LAPACK CUSPARSE
TEST_OPTIONAL_TPLS yaml-cpp
)
1 change: 1 addition & 0 deletions perf_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../test_common)

ADD_SUBDIRECTORIES(graph)
ADD_SUBDIRECTORIES(sparse)
ADD_SUBDIRECTORIES(performance)
#ADD_SUBDIRECTORIES(common)

6 changes: 5 additions & 1 deletion perf_test/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#=======================================================================
#=================== Settings ==========================================
#=======================================================================
Expand Down Expand Up @@ -77,6 +76,11 @@ EXECUTABLES += $(wildcard ${KOKKOSKERNELS_SRC_PATH}/perf_test/sparse/*cpp)
EXECUTABLES += $(wildcard ${KOKKOSKERNELS_SRC_PATH}/perf_test/graph/*cpp)
EXECUTABLES += $(wildcard ${KOKKOSKERNELS_SRC_PATH}/perf_test/../test_common/*cpp)

# Build yaml dependent performance class unit tests
ifeq (${KOKKOSKERNELS_INTERNAL_ENABLE_YAML}, 1)
EXECUTABLES += $(wildcard ${KOKKOSKERNELS_SRC_PATH}/perf_test/performance/*cpp)
endif



#=======================================================================
Expand Down
23 changes: 23 additions & 0 deletions perf_test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

# Add the two performance tests for the Performance class
# located in Kokkos_Performance.hpp.
# performance_validate validates the behavior of the Performance class.
# performance_example is a simple example of using it.
ASSERT_DEFINED(TPL_ENABLE_yaml-cpp)
IF(TPL_ENABLE_yaml-cpp)

TRIBITS_ADD_EXECUTABLE_AND_TEST(
performance_validate
SOURCES performance_validate.cpp
COMM serial mpi
)

TRIBITS_ADD_EXECUTABLE_AND_TEST(
performance_example
SOURCES performance_example.cpp
COMM serial mpi
)

ENDIF()
141 changes: 141 additions & 0 deletions perf_test/performance/performance_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam ([email protected])
//
// ************************************************************************
//@HEADER
*/

/*
Notes on performance_demo test

This is intended to be a minimal example of using the new YAML archiver.
The times and residuals are dummy values to mimic a real test.
First time running the test it should create the new yaml archive with 1 entry.
Subsequent runs will validate the values and pass.

To play around with this change the time1 value and run again to see it fail.
Or see performance_validate which runs through all the things the archiver does.
*/

#include "Kokkos_Performance.hpp" // provides performance archiver

bool run_example() {
// Some tests are run and produce some times...
double time1 = 10.0;
double time2 = 13.3;

// and they produce some results...
double residual = 0.001;
int some_exact_counter = 22;

// set up some user options
std::string archiveName("performance_example.yaml"); // name of the archive
std::string testName = "performance_example"; // name of test
std::string hostName; // optional hostname - auto detected if blank
double tolerance = 0.1; // for residual and times

using KokkosKernels::Performance;

// Create an archiver - steps are create, fill with members, then run
Performance archiver;

// Example of how to set customized machine config - to be developed
// Change to generate new entries in the yaml under MachineConfiguration
archiver.set_machine_config("Kokkos Config", "some node type");

// Fill config
archiver.set_config("MPI_Ranks", 2);
archiver.set_config("Teams", 1); // just arbitrary right now
archiver.set_config("Threads", 1); // just arbitrary right now
archiver.set_config("Filename", "somefilename"); // arbitrary - example of a string

// Fill results
archiver.set_result("Time1", time1, tolerance);
archiver.set_result("Time2", time2, tolerance);
archiver.set_result("Residual", residual, tolerance);
archiver.set_result("Counter", some_exact_counter); // must match exactly

// run it
Performance::Result result = archiver.run(archiveName, testName, hostName);

// print the yaml file for inspection
Performance::print_archive(archiveName);

// Print results
switch (result) {
case Performance::Passed:
std::cout << "Archiver Passed" << std::endl;
break;
case Performance::Failed:
std::cout << "Archiver Failed" << std::endl;
break;
case Performance::NewMachine:
std::cout << "Archiver Passed. Adding new machine entry." << std::endl;
break;
case Performance::NewConfiguration:
std::cout << "Archiver Passed. Adding new machine configuration." << std::endl;
break;
case Performance::NewTest:
std::cout << "Archiver Passed. Adding new test entry." << std::endl;
break;
case Performance::NewTestConfiguration:
std::cout << "Archiver Passed. Adding new test entry configuration." << std::endl;
break;
case Performance::UpdatedTest:
std::cout << "Archiver Passed. Updating test entry." << std::endl;
break;
default:
throw std::logic_error("Unexpected result code.");
break;
}

return (result != Performance::Failed);
}

int main(int argc, char *argv[]) {
bool success = run_example();

if (success) {
std::cout << "End Result: TEST PASSED" << std::endl;
} else {
std::cout << "End Result: TEST FAILED" << std::endl;
}

return EXIT_SUCCESS;
}
Loading