Skip to content

Commit

Permalink
Merge pull request #911 from KineticTheory/r123_1132_compat_update
Browse files Browse the repository at this point in the history
Update rng tests to be compatible with Random123 ver 1.13.2.
  • Loading branch information
alexrlongne authored Oct 8, 2020
2 parents dd74714 + 80007f9 commit 84bf498
Show file tree
Hide file tree
Showing 31 changed files with 1,048 additions and 944 deletions.
2 changes: 1 addition & 1 deletion environment/bashrc/.bashrc_darwin_fe
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if test -n "$MODULESHOME"; then
cflavor="gcc-8.2.0"
mflavor="$cflavor-openmpi-3.1.3"
lflavor="lapack-3.8.0"
noflavor="git gcc/8.2.0"
noflavor="git gcc/8.2.0 ndi"
compflavor="cmake/3.17.0 gsl/2.5-$cflavor netlib-lapack/3.8.0-$cflavor numdiff/5.9.0-$cflavor random123/1.09-$cflavor metis/5.1.0-$cflavor eospac/6.4.0-$cflavor openmpi/3.1.3-gcc_8.2.0"
mpiflavor="libquo/1.3-$mflavor parmetis/4.0.3-$mflavor superlu-dist/5.2.2-$mflavor-$lflavor trilinos/12.14.1-$mflavor-$lflavor"
ec_mf="csk/0.5.0-$cflavor ndi/2.1.3-$cflavor"
Expand Down
9 changes: 9 additions & 0 deletions src/rng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ string(CONCAT header_prefix_source
string(CONCAT header_prefix_binary "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${DBSCFG_IMPORT_PREFIX}>")

# Determine if Random123 version > 1.09.
if( EXISTS ${RANDOM123_INCLUDE_DIR}/Random123/u01fixedpt.h )
set( R123_VERSION 1.13.2 )
else()
set( R123_VERSION 1.09 )
endif()

#--------------------------------------------------------------------------------------------------#
# Generate config.h (only occurs when cmake is run)
#--------------------------------------------------------------------------------------------------#
set( R123_USE_CXX11 1 )
set( R123_USE_STD_RANDOM 1)
set( R123_USE_64BIT 1)
configure_file( config.h.in ${PROJECT_BINARY_DIR}/rng/config.h )
set( pkg_config_h "${header_prefix_binary}/rng/config.h" )

Expand Down
8 changes: 6 additions & 2 deletions src/rng/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* \author Thomas M. Evans
* \date Mon Jan 11 10:20:29 1999
* \brief rng package defines
* \note Copyright (C) 2016-2020 Triad National Security, LLC.
* All rights reserved. */
* \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */
/*------------------------------------------------------------------------------------------------*/

#ifndef rtt_rng_config_h
Expand All @@ -15,6 +14,11 @@
/* Enable Random123 C++11 support */
#cmakedefine R123_USE_CXX11 @R123_USE_CXX11@

/* Use C++11 std::random */
#cmakedefine R123_USE_STD_RANDOM @R123_USE_STD_RANDOM@

#cmakedefine R123_USE_64BIT @R123_USE_64BIT@

/* USE STANDARD C INTERFACE */
#ifndef _MSC_VER
#ifndef __STDC__
Expand Down
90 changes: 39 additions & 51 deletions src/rng/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ project( rng_test C CXX )
#--------------------------------------------------------------------------------------------------#
# Source files
#--------------------------------------------------------------------------------------------------#

set( test_sources
${PROJECT_SOURCE_DIR}/tstRnd_Control_Inline.cc
${PROJECT_SOURCE_DIR}/tstSubrandom_Sequence.cc
${PROJECT_SOURCE_DIR}/tstCounter_RNG.cc
)
${PROJECT_SOURCE_DIR}/tstRnd_Control_Inline.cc
${PROJECT_SOURCE_DIR}/tstSubrandom_Sequence.cc
${PROJECT_SOURCE_DIR}/tstCounter_RNG.cc )

# Random123 unit tests (these tests have special PASS/FAIL REGEX conditions)
set( random123_unit_tests
${PROJECT_SOURCE_DIR}/ut_aes.cpp
${PROJECT_SOURCE_DIR}/ut_ars.c
${PROJECT_SOURCE_DIR}/ut_carray.cpp
${PROJECT_SOURCE_DIR}/ut_M128.cpp
${PROJECT_SOURCE_DIR}/ut_uniform.cpp
)
${PROJECT_SOURCE_DIR}/ut_aes.cpp
${PROJECT_SOURCE_DIR}/ut_ars.c
${PROJECT_SOURCE_DIR}/ut_carray.cpp
${PROJECT_SOURCE_DIR}/ut_M128.cpp
${PROJECT_SOURCE_DIR}/ut_uniform.cpp )

# [2020-08-21 KT] The code in ut_gsl.c is not valid C++. Because this test is a mix of C and C++,
# it causes issues. Most compilers are happy to compile this code with C, visual studio is not.
# When marked as C++, this test fails with:
Expand All @@ -36,79 +34,69 @@ set( random123_unit_tests
# first on line 68 and then again on line 125 (with an assignment this time). We can continue
# building and running this tests on platforms that can processs it (all but MSVC right now).
if( NOT MSVC )
list(APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_gsl.c )
list(APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_gsl.c )
endif()
if( R123_USE_CXX11 )
list( APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_Engine.cpp )
if( R123_VERSION VERSION_GREATER 1.09 )
list( APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_Engine.cpp )
endif()

# Random123 known-answer tests
set( random123_known_answer_tests
${PROJECT_SOURCE_DIR}/kat_c.c
${PROJECT_SOURCE_DIR}/kat_cpp.cpp
)
${PROJECT_SOURCE_DIR}/kat_c.c
${PROJECT_SOURCE_DIR}/kat_cpp.cpp )

# Some compilers (esp. MSVC) have trouble with compiling these files as C11 code, so tell cmake
# to treat them as C++14. ut_gsl.c has a bug that prevents it from compiling as C++, so we omit it
# from this list.
if( MSVC )
set_source_files_properties(
${PROJECT_SOURCE_DIR}/time_serial.c
${PROJECT_SOURCE_DIR}/ut_ars.c
${PROJECT_SOURCE_DIR}/kat_c.c
PROPERTIES LANGUAGE CXX )
${PROJECT_SOURCE_DIR}/time_serial.c
${PROJECT_SOURCE_DIR}/ut_ars.c
${PROJECT_SOURCE_DIR}/kat_c.c
PROPERTIES LANGUAGE CXX )
endif()

#--------------------------------------------------------------------------------------------------#
# Build Unit tests
#--------------------------------------------------------------------------------------------------#

add_scalar_tests(
SOURCES "${test_sources}"
DEPS "Lib_rng" )
SOURCES "${test_sources}"
DEPS "Lib_rng" )

add_scalar_tests(
SOURCES "${random123_unit_tests}"
DEPS "Lib_rng"
PASS_REGEX "OK|SUCCESS"
FAIL_REGEX "failed;error;Failure" )
SOURCES "${random123_unit_tests}"
DEPS "Lib_rng"
PASS_REGEX "OK|SUCCESS"
FAIL_REGEX "failed;error;Failure" )
target_include_directories( Ut_rng_ut_uniform_exe PRIVATE $<BUILD_INTERFACE:${rng_SOURCE_DIR}> )

add_scalar_tests(
SOURCES "${random123_known_answer_tests}"
DEPS "Lib_rng"
PASS_REGEX "PASSED"
FAIL_REGEX "FAILED" )
target_include_directories( Ut_rng_ut_uniform_exe
PRIVATE $<BUILD_INTERFACE:${rng_SOURCE_DIR}> )

if( USE_CUDA AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL )

set( test_sources_cuda
${PROJECT_SOURCE_DIR}/kat_cuda.cu)

if( USE_CUDA AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL )
set( test_sources_cuda ${PROJECT_SOURCE_DIR}/kat_cuda.cu)
set( test_deps_cuda "Lib_rng" )

add_scalar_tests(
SOURCES "${test_sources_cuda}"
DEPS "${test_deps_cuda}"
PASS_REGEX "PASSED"
FAIL_REGEX "FAILED" )

endif()
add_scalar_tests(
SOURCES "${test_sources_cuda}"
DEPS "${test_deps_cuda}"
PASS_REGEX "PASSED"
FAIL_REGEX "FAILED" )
endif()

add_component_executable(
TARGET Exe_time_serial
SOURCES ${PROJECT_SOURCE_DIR}/time_serial.c
NOEXPORT
)
target_include_directories( Exe_time_serial
PRIVATE
$<BUILD_INTERFACE:${rng_BINARY_DIR}>
$<BUILD_INTERFACE:${dsxx_BINARY_DIR}>
${RANDOM123_INCLUDE_DIR} )
NOEXPORT )
target_include_directories( Exe_time_serial PRIVATE
$<BUILD_INTERFACE:${rng_BINARY_DIR}>
$<BUILD_INTERFACE:${dsxx_BINARY_DIR}>
${RANDOM123_INCLUDE_DIR} )

configure_file( ${PROJECT_SOURCE_DIR}/kat_vectors
${PROJECT_BINARY_DIR}/kat_vectors COPYONLY )
configure_file( ${PROJECT_SOURCE_DIR}/kat_vectors ${PROJECT_BINARY_DIR}/kat_vectors COPYONLY )

#--------------------------------------------------------------------------------------------------#
# end rng/test/CMakeLists.txt
Expand Down
19 changes: 11 additions & 8 deletions src/rng/test/kat.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016, D. E. Shaw Research.
Copyright 2010-2011, D. E. Shaw Research.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -47,15 +47,15 @@ enum method_e {
#define RNGNxW_TPL(base, N, W) base##N##x##W##_e,
#include "rngNxW.h"
#undef RNGNxW_TPL
unused /* silences warning about dangling comma */
last
};

#define RNGNxW_TPL(base, N, W) \
typedef struct { \
base##N##x##W##_ctr_t ctr; \
base##N##x##W##_ukey_t ukey; \
base##N##x##W##_ctr_t expected; \
base##N##x##W##_ctr_t computed; \
#define RNGNxW_TPL(base, N, W) \
typedef struct { \
base##N##x##W##_ctr_t ctr; \
base##N##x##W##_ukey_t ukey; \
base##N##x##W##_ctr_t expected; \
base##N##x##W##_ctr_t computed; \
} base##N##x##W##_kat;
#include "rngNxW.h"
#undef RNGNxW_TPL
Expand All @@ -67,6 +67,9 @@ typedef struct {
#define RNGNxW_TPL(base, N, W) base##N##x##W##_kat base##N##x##W##_data;
#include "rngNxW.h"
#undef RNGNxW_TPL
/* Sigh... For those platforms that lack uint64_t, carve
out 128 bytes for the counter, key, expected, and computed. */
char justbytes[128];
} u;
} kat_instance;

Expand Down
23 changes: 17 additions & 6 deletions src/rng/test/kat_c.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016, D. E. Shaw Research.
Copyright 2010-2011, D. E. Shaw Research.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,8 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef _MSC_FULL_VER
// - 4521: Engines have multiple copy constructors, quite legal C++, disable
// MSVC complaint.
// - 4521: Engines have multiple copy constructors, quite legal C++, disable MSVC complaint.
// - 4244: possible loss of data when converting between int types.
// - 4204: nonstandard extension used - non-constant aggregate initializer
// - 4127: conditional expression is constant
Expand All @@ -41,17 +40,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma warning(disable : 4521 4244 4204 4127 4100)
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

#include "kat_main.h"

#define KAT_KERNEL
#define KAT_GLOBAL
#define KAT_UINT size_t
#include "kat_dev_execute.h"

void host_execute_tests(kat_instance *tests, size_t ntests) {
dev_execute_tests(tests, ntests);
void host_execute_tests(kat_instance *tests, unsigned ntests) {
(void)ntests; /* unused */
dev_execute_tests(tests);
}

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

#ifdef _MSC_FULL_VER
#pragma warning(pop)
#endif

//------------------------------------------------------------------------------------------------//
// End kat_c.c
//------------------------------------------------------------------------------------------------//
Loading

0 comments on commit 84bf498

Please sign in to comment.