From cbedba37111cadf773dc500ad13b590070b8375b Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Fri, 18 Sep 2020 18:08:47 -0600 Subject: [PATCH 1/8] Update rng tests to be compatible with Random123 ver 1.13.2. + Set `R123_USE_CXX11` in `rng/config.h`. + Replace kat_cpp and ut_Engine unit tests with updated versions from the Random123 release. --- src/rng/CMakeLists.txt | 1 + src/rng/config.h.in | 8 +- src/rng/test/kat_c.c | 54 ++++---- src/rng/test/kat_cpp.cpp | 142 +++++++++----------- src/rng/test/kat_main.h | 265 +++++++++++++++++++------------------ src/rng/test/ut_Engine.cpp | 147 ++++++++++---------- src/rng/test/ut_Engine.hh | 4 +- 7 files changed, 300 insertions(+), 321 deletions(-) diff --git a/src/rng/CMakeLists.txt b/src/rng/CMakeLists.txt index 38b03dd53f..5285f8fe83 100755 --- a/src/rng/CMakeLists.txt +++ b/src/rng/CMakeLists.txt @@ -19,6 +19,7 @@ string(CONCAT header_prefix_binary "$" # Generate config.h (only occurs when cmake is run) #--------------------------------------------------------------------------------------------------# set( R123_USE_CXX11 1 ) +set( R123_USE_STD_RANDOM 1) configure_file( config.h.in ${PROJECT_BINARY_DIR}/rng/config.h ) set( pkg_config_h "${header_prefix_binary}/rng/config.h" ) diff --git a/src/rng/config.h.in b/src/rng/config.h.in index 13a8b73a01..1db7ec28eb 100644 --- a/src/rng/config.h.in +++ b/src/rng/config.h.in @@ -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 @@ -13,7 +12,10 @@ #include "ds++/config.h" /* Enable Random123 C++11 support */ -#cmakedefine R123_USE_CXX11 @R123_USE_CXX11@ +#cmakedefine R123_USE_CXX11 @R123_USE_CXX11 @ + +/* Use C++11 std::random */ +#cmakedefine R123_USE_STD_RANDOM @R123_USE_STD_RANDOM @ /* USE STANDARD C INTERFACE */ #ifndef _MSC_VER diff --git a/src/rng/test/kat_c.c b/src/rng/test/kat_c.c index 0b27cb5f05..00e10a9902 100644 --- a/src/rng/test/kat_c.c +++ b/src/rng/test/kat_c.c @@ -2,37 +2,31 @@ Copyright 2016, D. E. Shaw Research. All rights reserved. -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"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 THE COPYRIGHT -OWNER OR 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. +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions, + and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse + or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR +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. */ #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 @@ -48,9 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #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) { dev_execute_tests(tests, ntests); } #ifdef _MSC_FULL_VER #pragma warning(pop) diff --git a/src/rng/test/kat_cpp.cpp b/src/rng/test/kat_cpp.cpp index a1a88ddbdb..d6f2253916 100644 --- a/src/rng/test/kat_cpp.cpp +++ b/src/rng/test/kat_cpp.cpp @@ -1,36 +1,32 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions, + and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse + or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR +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. */ #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 @@ -41,17 +37,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "kat_main.h" -// With C++, it's a little trickier to create the mapping from -// method-name/round-count to functions because the round-counts are template -// arguments that have to be specified at compile-time. Thus, we can't just do -// #define RNGNxW_TPL and #include "rngNxW.h". We have to build a static map -// from: pair to functions that apply the right generator -// with the right number of rounds. +// With C++, it's a little trickier to create the mapping from method-name/round-count to functions +// because the round-counts are template arguments that have to be specified at compile-time. Thus, +// we can't just do #define RNGNxW_TPL and #include "rngNxW.h". We have to build a static map from: +// pair to functions that apply the right generator with the right number of +// rounds. #if (DBS_GNUC_VERSION >= 40204) && !defined(__ICC) && !defined(NVCC) -// Suppress GCC's "unused parameter" warning, about lhs and rhs in sse.h, and an -// "unused local typedef" warning, from a pre-C++11 implementation of a static -// assertion in compilerfeatures.h. +// Suppress GCC's "unused parameter" warning, about lhs and rhs in sse.h, and an "unused local +// typedef" warning, from a pre-C++11 implementation of a static assertion in compilerfeatures.h. #if (DBS_GNUC_VERSION >= 40600) #pragma GCC diagnostic push #endif @@ -94,19 +88,18 @@ typedef map, void (*)(kat_instance *)> genmap_t; genmap_t genmap; void dev_execute_tests(kat_instance *tests, unsigned ntests) { - size_t i; + unsigned i; for (i = 0; i < ntests; ++i) { kat_instance *ti = &tests[i]; genmap_t::iterator p = genmap.find(make_pair(ti->method, ti->nrounds)); if (p == genmap.end()) - throw std::runtime_error( - "pair not in map. You probably need to add " - "more genmap entries in kat_cpp.cpp"); + throw std::runtime_error("pair not in map. You probably need to add " + "more genmap entries in kat_cpp.cpp"); p->second(ti); - // TODO: check that the corresponding Engine and MicroURNG return the same - // values. Note that we have ut_Engine and ut_MicroURNG, which check basic - // functionality, but they don't have the breadth of the kat_vectors. + // TODO: check that the corresponding Engine and MicroURNG return the same values. Note + // that we have ut_Engine and ut_MicroURNG, which check basic functionality, but they don't + // have the breadth of the kat_vectors. } } @@ -126,19 +119,17 @@ template void do_test(kat_instance *ti) { memcpy(&data, &ti->u, sizeof(data)); data.computed = g(data.ctr, data.ukey); - // Before we return, let's make sure that MicroURNG and Engine - // work as expeccted. This doesn't really "fit" the execution model of kat.c, - // which just expects us to fill in ti->u.computed, so we report the error by - // failing to write back the computed data item in the (hopefully unlikely) - // event that things don't match up as expected. + // Before we return, let's make sure that MicroURNG and Engine work as expeccted. + // This doesn't really "fit" the execution model of kat.c, which just expects us to fill in + // ti->u.computed, so we report the error by failing to write back the computed data item in the + // (hopefully unlikely) event that things don't match up as expected. int errs = 0; - // MicroURNG: throws if the top 32 bits of the high word of ctr - // are non-zero. + // MicroURNG: throws if the top 32 bits of the high word of ctr are non-zero. typedef typename GEN::ctr_type::value_type value_type; - value_type hibits = data.ctr[data.ctr.size() - 1] >> - (std::numeric_limits::digits - 32); + value_type hibits = + data.ctr[data.ctr.size() - 1] >> (std::numeric_limits::digits - 32); try { r123::MicroURNG urng(data.ctr, data.ukey); if (hibits) @@ -155,8 +146,7 @@ template void do_test(kat_instance *ti) { errs++; } if (errs && (murng_reported++ == 0)) - cerr << "Error in MicroURNG, will appear as \"computed\" value " - << "of zero in error summary\n"; + cerr << "Error in MicroURNG, will appear as \"computed\" value of zero in error summary\n"; // Engine // N.B. exercising discard() arguably belongs in ut_Engine.cpp @@ -164,9 +154,18 @@ template void do_test(kat_instance *ti) { typedef typename GEN::ctr_type::value_type value_type; Etype e(data.ukey); typename GEN::ctr_type c = data.ctr; - value_type c0 = c[0]; + value_type c0; + if (c[0] > 0) { + c0 = c[0] - 1; + } else { + // N.B. Assume that if c[0] is 0, then so are all the others. Arrange to "roll over" to + // {0,..,0} on the first counter-increment. Alternatively, we could just skip the test for + // this case... + c.fill(std::numeric_limits::max()); + c0 = c[0]; + } c[0] /= 3; - e.setcounter(c, c.size()); + e.setcounter(c, 0); if (c0 > c[0]) { // skip one value by calling e() (void)e(); @@ -194,47 +193,45 @@ template void do_test(kat_instance *ti) { size_t j = data.expected.size() - i - 1; if (data.expected[j] != val) { cerr << hex; - cerr << "Engine check, j=" << j << " expected: " << data.expected[j] - << " val: " << val << "\n"; + cerr << "Engine check, j=" << j << " expected: " << data.expected[j] << " val: " << val + << "\n"; errs++; if (engine_reported++ == 0) - cerr << "Error in Engine, will appear as \"computed\" value of " - "zero in error summary\n"; + cerr << "Error in Engine, will appear as \"computed\" value of zero in error " + "summary\n"; } } - // Signal an error to the caller by *not* copying back the computed data - // object into the ti + // Signal an error to the caller by *not* copying back the computed data object into the ti if (errs == 0) memcpy(&ti->u, &data, sizeof(data)); } -void host_execute_tests(kat_instance *tests, size_t ntests) { +void host_execute_tests(kat_instance *tests, unsigned ntests) { // In C++1x, this could be staticly declared with an initializer list. genmap[make_pair(threefry2x32_e, 13u)] = do_test>; genmap[make_pair(threefry2x32_e, 20u)] = do_test>; genmap[make_pair(threefry2x32_e, 32u)] = do_test>; +#if R123_USE_64BIT genmap[make_pair(threefry2x64_e, 13u)] = do_test>; genmap[make_pair(threefry2x64_e, 20u)] = do_test>; genmap[make_pair(threefry2x64_e, 32u)] = do_test>; +#endif genmap[make_pair(threefry4x32_e, 13u)] = do_test>; genmap[make_pair(threefry4x32_e, 20u)] = do_test>; genmap[make_pair(threefry4x32_e, 72u)] = do_test>; +#if R123_USE_64BIT genmap[make_pair(threefry4x64_e, 13u)] = do_test>; genmap[make_pair(threefry4x64_e, 20u)] = do_test>; genmap[make_pair(threefry4x64_e, 72u)] = do_test>; +#endif genmap[make_pair(philox2x32_e, 7u)] = do_test>; genmap[make_pair(philox2x32_e, 10u)] = do_test>; genmap[make_pair(philox4x32_e, 7u)] = do_test>; genmap[make_pair(philox4x32_e, 10u)] = do_test>; -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wexpansion-to-defined" -#endif - #if R123_USE_PHILOX_64BIT genmap[make_pair(philox2x64_e, 7u)] = do_test>; genmap[make_pair(philox2x64_e, 10u)] = do_test>; @@ -242,20 +239,13 @@ void host_execute_tests(kat_instance *tests, size_t ntests) { genmap[make_pair(philox4x64_e, 10u)] = do_test>; #endif -#ifdef __clang__ -// Restore clang diagnostics to previous state. -#pragma clang diagnostic pop -#endif - #if R123_USE_AES_NI genmap[make_pair(aesni4x32_e, 10u)] = do_test; genmap[make_pair(ars4x32_e, 7u)] = do_test>; genmap[make_pair(ars4x32_e, 10u)] = do_test>; #endif - /* XXX ntests cannot be size_t because of OpenCL, seems unlikely it will - overflow an unsigned... */ - dev_execute_tests(tests, (unsigned)ntests); + dev_execute_tests(tests, ntests); } //------------------------------------------------------------------------------------------------// diff --git a/src/rng/test/kat_main.h b/src/rng/test/kat_main.h index 34959debb2..9a154a6378 100644 --- a/src/rng/test/kat_main.h +++ b/src/rng/test/kat_main.h @@ -1,61 +1,57 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions, + and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse + or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR +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. */ /* Known Answer Test */ -/* We use the same source files to implement the Known Answer Test (KAT) in C, - C++, OpenCL and CUDA. Supporting all four environments with a single source - file, and getting it all to work with 'make' is a bit involved: +/* We use the same source files to implement the Known Answer Test + (KAT) in C, C++, OpenCL and CUDA. Supporting all four environments + with a single source file, and getting it all to work with 'make' + is a bit involved: - There are four "top-level" files: + There are five "top-level" files: kat_c.c kat_cpp.cpp kat_cuda.c kat_opencl.c + kat_metal.m - These correspond to make targets: kat_c, kat_cpp, kat_cuda and kat_opencl. + These correspond to make targets: kat_c, kat_cpp, kat_cuda, kat_opencl and kat_metal. - Those four files are very simple. First, they #include this file, which - contains all the machinery for reading test vectors, complaining about - errors, etc.. Then they implement the function host_execute_tests() in the - appropriate environment. host_execute_tests looks very different in - C/C++/CUDA/OpenCL. + Those files are relatively simple. First, they #include this file, which contains all the + machinery for reading test vectors, complaining about errors, etc.. Then they implement the + function host_execute_tests() in the appropriate environment. host_execute_tests looks very + different in C/C++/CUDA/OpenCL/Metal. - host_execute_tests contrives to call/launch "dev_execute_tests" on the - device. Except for a few environment-specific keywords, (e.g., __global, - __kernel), which are #defined in kat_XXX.c, dev_execute_tests is obtained by - including a common source file: #include + host_execute_tests contrives to call/launch "dev_execute_tests" on the device. Except for a few + environment-specific keywords, (e.g., __global, __kernel), which are #defined in kat_XXX.c, + dev_execute_tests is obtained by including a common source file: #include - One final complication: in order to fully "bake" the source code into the - binary at compile-time, dev_execute_tests for opencl is implemented in - kat_opencl_kernel.ocl, which is processed by gencl.sh into - kat_opencl_kernel.i, which is thein #include-ed by kat_opencl.c. + One final complication: in order to fully "bake" the source code into the binary at compile-time, + dev_execute_tests for opencl is implemented in kat_opencl_kernel.ocl, which is processed by + gencl.sh into kat_opencl_kernel.i, which is thein #include-ed by kat_opencl.c. */ #include "kat.h" @@ -69,10 +65,9 @@ int debug = 0; size_t nfailed = 0; const char *progname; -extern void host_execute_tests(kat_instance *tests, size_t ntests); +extern void host_execute_tests(kat_instance *tests, unsigned ntests); -/* A little hack to keep track of the test vectors that we don't know how to - * deal with: */ +/* A little hack to keep track of the test vectors that we don't know how to deal with: */ int nunknowns = 0; #define MAXUNKNOWNS 20 const char *unknown_names[MAXUNKNOWNS]; @@ -98,38 +93,38 @@ void register_unknown(const char *name) { void report_unknowns() { int i; for (i = 0; i < nunknowns; ++i) { - printf("%d test vectors of type %s skipped\n", unknown_counts[i], - unknown_names[i]); + printf("%d test vectors of type %s skipped\n", unknown_counts[i], unknown_names[i]); } } /* read_NxW */ -#define RNGNxW_TPL(base, N, W) \ - int read_##base##N##x##W(const char *line, kat_instance *tinst) { \ - size_t i; \ - int nchar; \ - const char *p = line; \ - char *newp; \ - size_t nkey = sizeof(tinst->u.base##N##x##W##_data.ukey.v) / \ - sizeof(tinst->u.base##N##x##W##_data.ukey.v[0]); \ - tinst->method = base##N##x##W##_e; \ - sscanf(p, "%u%n", &tinst->nrounds, &nchar); \ - p += nchar; \ - for (i = 0; i < N; ++i) { \ - tinst->u.base##N##x##W##_data.ctr.v[i] = strtou##W(p, &newp, 16); \ - p = newp; \ - } \ - for (i = 0; i < nkey; ++i) { \ - tinst->u.base##N##x##W##_data.ukey.v[i] = strtou##W(p, &newp, 16); \ - p = newp; \ - } \ - for (i = 0; i < N; ++i) { \ - tinst->u.base##N##x##W##_data.expected.v[i] = strtou##W(p, &newp, 16); \ - p = newp; \ - } \ - memset(tinst->u.base##N##x##W##_data.computed.v, 0, \ - sizeof(tinst->u.base##N##x##W##_data.computed.v)); \ - return 1; \ +#define RNGNxW_TPL(base, N, W) \ + int read_##base##N##x##W(const char *line, kat_instance *tinst) { \ + size_t i; \ + int nchar; \ + const char *p = line; \ + char *newp; \ + size_t nkey = sizeof(tinst->u.base##N##x##W##_data.ukey.v) / \ + sizeof(tinst->u.base##N##x##W##_data.ukey.v[0]); \ + tinst->method = base##N##x##W##_e; \ + sscanf(p, "%u%n", &tinst->nrounds, &nchar); \ + p += nchar; \ + for (i = 0; i < N; ++i) { \ + tinst->u.base##N##x##W##_data.ctr.v[i] = strtou##W(p, &newp, 16); \ + p = newp; \ + } \ + for (i = 0; i < nkey; ++i) { \ + tinst->u.base##N##x##W##_data.ukey.v[i] = strtou##W(p, &newp, 16); \ + p = newp; \ + } \ + for (i = 0; i < N; ++i) { \ + tinst->u.base##N##x##W##_data.expected.v[i] = strtou##W(p, &newp, 16); \ + p = newp; \ + } \ + /* set the computed to 0xca. If the test fails to set computed, we'll see cacacaca in the FAILURE notices */ \ + memset(tinst->u.base##N##x##W##_data.computed.v, 0xca, \ + sizeof(tinst->u.base##N##x##W##_data.computed.v)); \ + return 1; \ } #include "rngNxW.h" #undef RNGNxW_TPL @@ -148,8 +143,8 @@ static int readtest(const char *line, kat_instance *tinst) { return 0; } } -#define RNGNxW_TPL(base, N, W) \ - if (strcmp(name, #base #N "x" #W) == 0) \ +#define RNGNxW_TPL(base, N, W) \ + if (strcmp(name, #base #N "x" #W) == 0) \ return read_##base##N##x##W(line + nchar, tinst); #include "rngNxW.h" #undef RNGNxW_TPL @@ -158,58 +153,63 @@ static int readtest(const char *line, kat_instance *tinst) { return 0; } -#define RNGNxW_TPL(base, N, W) \ - void report_##base##N##x##W##error(const kat_instance *ti) { \ - size_t i; \ - size_t nkey = sizeof(ti->u.base##N##x##W##_data.ukey.v) / \ - sizeof(ti->u.base##N##x##W##_data.ukey.v[0]); \ - fprintf(stderr, "FAIL: expected: "); \ - fprintf(stderr, #base #N "x" #W " %d", ti->nrounds); \ - for (i = 0; i < N; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.ctr.v[i]); \ - } \ - for (i = 0; i < nkey; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.ukey.v[i]); \ - } \ - for (i = 0; i < N; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.expected.v[i]); \ - } \ - fprintf(stderr, "\n"); \ - \ - fprintf(stderr, "FAIL: computed: "); \ - fprintf(stderr, #base #N "x" #W " %d", ti->nrounds); \ - for (i = 0; i < N; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.ctr.v[i]); \ - } \ - for (i = 0; i < nkey; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.ukey.v[i]); \ - } \ - for (i = 0; i < N; ++i) { \ - fprintf(stderr, " "); \ - prtu##W(ti->u.base##N##x##W##_data.computed.v[i]); \ - } \ - fprintf(stderr, "\n"); \ - nfailed++; \ +#define RNGNxW_TPL(base, N, W) \ + void report_##base##N##x##W##error(const kat_instance *ti) { \ + size_t i; \ + size_t nkey = \ + sizeof(ti->u.base##N##x##W##_data.ukey.v) / sizeof(ti->u.base##N##x##W##_data.ukey.v[0]); \ + fprintf(stderr, "FAIL: expected: "); \ + fprintf(stderr, #base #N "x" #W " %d", ti->nrounds); \ + for (i = 0; i < N; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.ctr.v[i]); \ + } \ + for (i = 0; i < nkey; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.ukey.v[i]); \ + } \ + for (i = 0; i < N; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.expected.v[i]); \ + } \ + fprintf(stderr, "\n"); \ + \ + fprintf(stderr, "FAIL: computed: "); \ + fprintf(stderr, #base #N "x" #W " %d", ti->nrounds); \ + for (i = 0; i < N; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.ctr.v[i]); \ + } \ + for (i = 0; i < nkey; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.ukey.v[i]); \ + } \ + for (i = 0; i < N; ++i) { \ + fprintf(stderr, " "); \ + prtu##W(ti->u.base##N##x##W##_data.computed.v[i]); \ + } \ + fprintf(stderr, "\n"); \ + nfailed++; \ } #include "rngNxW.h" #undef RNGNxW_TPL -/* dispatch to one of the report_NxW() functions */ -void analyze_tests(const kat_instance *tests, size_t ntests) { - size_t i; +// dispatch to one of the report_NxW() functions +void analyze_tests(const kat_instance *tests, unsigned ntests) { + unsigned i; + char zeros[512] = {0}; for (i = 0; i < ntests; ++i) { const kat_instance *ti = &tests[i]; switch (tests[i].method) { -#define RNGNxW_TPL(base, N, W) \ - case base##N##x##W##_e: \ - if (memcmp(ti->u.base##N##x##W##_data.computed.v, \ - ti->u.base##N##x##W##_data.expected.v, N * W / 8)) \ - report_##base##N##x##W##error(ti); \ +#define RNGNxW_TPL(base, N, W) \ + case base##N##x##W##_e: \ + if (memcmp(zeros, ti->u.base##N##x##W##_data.expected.v, N * W / 8) == 0) { \ + fprintf(stderr, "kat expected all zeros? Something is wrong with the test harness!\n"); \ + nfailed++; \ + } \ + if (memcmp(ti->u.base##N##x##W##_data.computed.v, ti->u.base##N##x##W##_data.expected.v, \ + N * W / 8)) \ + report_##base##N##x##W##error(ti); \ break; #include "rngNxW.h" #undef RNGNxW_TPL @@ -222,7 +222,7 @@ void analyze_tests(const kat_instance *tests, size_t ntests) { int main(int argc, char **argv) { kat_instance *tests; - size_t t, ntests = NTESTS; + unsigned t, ntests = NTESTS; char linebuf[LINESIZE]; FILE *inpfile; const char *p; @@ -249,8 +249,8 @@ int main(int argc, char **argv) { } else { inpfile = fopen(inname, "r"); if (inpfile == NULL) { - fprintf(stderr, "%s: error opening input file %s for reading: %s\n", - progname, inname, strerror(errno)); + fprintf(stderr, "%s: error opening input file %s for reading: %s\n", progname, inname, + strerror(errno)); exit(1); } } @@ -269,8 +269,7 @@ int main(int argc, char **argv) { tests = (kat_instance *)malloc(sizeof(tests[0]) * ntests); if (tests == NULL) { - fprintf(stderr, "Could not allocate %lu bytes for tests\n", - (unsigned long)ntests); + fprintf(stderr, "Could not allocate %lu bytes for tests\n", (unsigned long)ntests); exit(1); } t = 0; @@ -279,14 +278,18 @@ int main(int argc, char **argv) { ntests *= 2; tests = (kat_instance *)realloc(tests, sizeof(tests[0]) * ntests); if (tests == NULL) { - fprintf(stderr, "Could not grow tests to %lu bytes\n", - (unsigned long)ntests); + fprintf(stderr, "Could not grow tests to %lu bytes\n", (unsigned long)ntests); exit(1); } } if (readtest(linebuf, &tests[t])) ++t; } + if (t == ntests) { + fprintf(stderr, "No more space for tests? Recompile with a larger NTESTS\n"); + exit(1); + } + //kt tests[t].method = last; // N.B *not* t++ - the 'ntests' value passed to host_execute_tests does not count the 'last' one. report_unknowns(); printf("Perform %lu tests.\n", (unsigned long)t); @@ -295,14 +298,14 @@ int main(int argc, char **argv) { analyze_tests(tests, t); free(tests); if (nfailed != 0) { - printf("FAILED %lu out of %lu\n", (unsigned long)nfailed, (unsigned long)t); + printf("FAILED %lu out of %u\n", nfailed, t); return 1; } else { - printf("PASSED %lu known answer tests\n", (unsigned long)t); + printf("PASSED %u known answer tests\n", t); return 0; } } //------------------------------------------------------------------------------------------------// // end kat_cpp.cpp -//------------------------------------------------------------------------------------------------// +//------------------------------------------------------------------------------------------------/ diff --git a/src/rng/test/ut_Engine.cpp b/src/rng/test/ut_Engine.cpp index de1db6b504..fb1f7e040b 100644 --- a/src/rng/test/ut_Engine.cpp +++ b/src/rng/test/ut_Engine.cpp @@ -1,39 +1,36 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions, + and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse + or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR +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. */ + // TODO - really do a thorough and complete set of tests. #include "rng/config.h" #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 @@ -73,30 +70,27 @@ using namespace std; using namespace r123; template typename EType::result_type kat1000() { - // A zero return says that no KAT is known. This makes sense for the - // ReniterpretCtr-based engines which are expected to produce endian-specific - // results, so we don't have known answers for them. + // A zero return says that no KAT is known. This makes sense for the ReniterpretCtr-based engines + // which are expected to produce endian-specific results, so we don't have known answers for them. return 0; } +#if R123_USE_64BIT #if R123_USE_PHILOX_64BIT -template <> uint64_t kat1000>() { - return R123_64BIT(10575809911605703474); -} +template <> uint64_t kat1000>() { return R123_64BIT(10575809911605703474); } +#endif +template <> uint64_t kat1000>() { return R123_64BIT(17578122881062615727); } #endif template <> uint32_t kat1000>() { return 1721865298; } -template <> uint64_t kat1000>() { - return R123_64BIT(17578122881062615727); -} template <> uint32_t kat1000>() { return 874101813; } #if R123_USE_AES_OPENSSL template <> uint8_t kat1000>() { return 0237; } #endif -#define ASSERTEQ(A, B) \ - assert(A == B); \ - assert(A() == B()); \ - assert(A() == B()); \ +#define ASSERTEQ(A, B) \ + assert(A == B); \ + assert(A() == B()); \ + assert(A() == B()); \ assert(A() == B()) struct DummySeedSeq { @@ -115,36 +109,34 @@ template void doit() { EType ess(dummyss); assert(ess != e); - rngRemember(rtype r1 = e()); - rngRemember(rtype r2 = e()); - rngRemember(rtype r3 = e()); - + rtype r1 = e(); + rtype r2 = e(); assert(r1 != r2); + rtype r3 = e(); assert(r3 != r2 && r3 != r1); // We've elsewhere confirmed that the underlying bijections actually "work", // e.g., that they pass the Known Answer Test for some set of test vectors. - // Here, we simply check that the output of the Engine corresponds, in the - // expected way to the output of the underlying bijection. + // Here, we simply check that the output of the Engine corresponds, in the expected + // way to the output of the underlying bijection. - // Check that the first few values out of the engine correspond to output from - // the underlying bijection. + // Check that the first few values out of the engine correspond + // to output from the underlying bijection. BType b; ctype c1 = {{}}; - ktype k = e.getseed(); + ktype k = e.getkey(); e.seed(); for (int i = 0; i < 100; ++i) { c1[0]++; ctype rb = b(c1, k); - for (typename ctype::reverse_iterator p = rb.rbegin(); p != rb.rend(); - ++p) { - rngRemember(rtype re = e()); + for (typename ctype::reverse_iterator p = rb.rbegin(); p != rb.rend(); ++p) { + rtype re = e(); assert(*p == re); } } - // Check that discard work as expected, i.e., we can keep two engines "in - // sync" by discarding from one and stepping the other. + // Check that discard work as expected, i.e., we can keep two + // engines "in sync" by discarding from one and stepping the other. EType e2; assert(e2 != e); e2.discard(100 * c1.size()); @@ -158,20 +150,20 @@ template void doit() { ASSERTEQ(e2, e); } - // Check that saving and restoring state and the copy constructor works as - // expected. + // Check that saving and restoring state and the copy constructor + // works as expected. ostringstream oss; oss << e2; string s2 = oss.str(); int fiftyfive = 55; #if R123_USE_CXX11_TYPE_TRAITS - // With CXX11, the library has type_traits to prevent undesirable type - // resolution against the templated SeedSeq constructor + // With CXX11, the library has type_traits to prevent + // undesirable type resolution against the templated SeedSeq constructor EType e3(fiftyfive); #else - // Without CXX11, we have to be careful to pass in a bona fide rtype, and not - // just something that will promote to an rtype, if we want the rtype - // constructor. + // Without CXX11, we have to be careful to pass in + // a bona fide rtype, and not just something that will promote + // to an rtype, if we want the rtype constructor. EType e3((rtype(fiftyfive))); #endif EType esave(e); @@ -196,9 +188,8 @@ template void doit() { e5.seed((rtype)99); ASSERTEQ(e4, e5); -#ifdef R123_USE_STD_RANDOM - // Check that we can use an EType with a std::distribution. Obviously, this - // requires +#if R123_USE_STD_RANDOM + // Check that we can use an EType with a std::distribution. Obviously, this requires uniform_int_distribution dieroller(1, 6); vector hist(7); int NROLL = 10000; @@ -213,19 +204,17 @@ template void doit() { double delta = hist[pips] - expected; chisq += delta * delta / var; } - // The critical value of chisq with 6 degrees of freedom for P=0.01 is 16.81. - // For P=0.05, it is 12.59 + // The critical value of chisq with 6 degrees of freedom for P=0.01 is 16.81. For P=0.05, it is + // 12.59 const double chicrit = 12.59; if (chisq > chicrit) { - printf("std::uniform_int_distribution doesn't look random. Chisq = %g. " - "Does this look like the result of a fair set of dice rolls to " - "you?\n", + printf("std::uniform_int_distribution doesn't look random. Chisq = %g. Does this look like " + "the result of a fair set of dice rolls to you?\n", chisq); for (int pips = 1; pips <= 6; ++pips) { printf("%d pips %d times\n", pips, hist[pips]); } - abort(); // a bit harsh, no? It might just be a rare event at the 5% - // level... + abort(); // a bit harsh, no? It might just be a rare event at the 5% level... } #endif @@ -235,32 +224,34 @@ template void doit() { typename EType::result_type r = ekat(); typename EType::result_type knownanswer = kat1000(); if (knownanswer != 0 && r != knownanswer) - cerr << "KAT mismatch. The 1000th random from " << demangle(ekat) << " is " - << r << " it should be " << knownanswer << "\n"; + cerr << "KAT mismatch. The 1000th random from " << demangle(ekat) << " is " << r + << " it should be " << knownanswer << "\n"; assert(knownanswer == 0 || r == knownanswer); cout << " OK" << endl; } -//------------------------------------------------------------------------------------------------// int main(int, char **) { #if R123_USE_PHILOX_64BIT doit>(); doit>>(); #endif doit>(); - doit>(); doit>(); +#if R123_USE_64BIT doit>>(); + doit>(); doit>>(); +#endif #if R123_USE_AES_NI if (haveAESNI()) { doit>(); +#if R123_USE_64BIT doit>>(); +#endif doit>(); } else { - cout << "AES is compiled into the binary, but is not available on this " - "hardware\n"; + cout << "AES is compiled into the binary, but is not available on this hardware\n"; } #endif #if R123_USE_AES_OPENSSL @@ -271,6 +262,8 @@ int main(int, char **) { return 0; } +//------------------------------------------------------------------------------------------------// + #ifdef __clang__ // Restore clang diagnostics to previous state. #pragma clang diagnostic pop diff --git a/src/rng/test/ut_Engine.hh b/src/rng/test/ut_Engine.hh index 7776f1008d..e7a13b2c17 100644 --- a/src/rng/test/ut_Engine.hh +++ b/src/rng/test/ut_Engine.hh @@ -3,10 +3,8 @@ * \file rng/test/ut_Engine.hh * \author Gabriel M. Rockefeller * \brief ut_Engine header file. - * \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 rng_test_ut_Engine_hh #define rng_test_ut_Engine_hh From 29ef38f6676fda64df3aef3cb13ea093b1f8fca3 Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Sun, 20 Sep 2020 14:06:17 -0600 Subject: [PATCH 2/8] Disable tests when older R123 is used. + Two tests were modified for compatibility with Random123-1.13.2. Since these tests are no longer compatible with Random123-1.09, they will only be registered when using the newer R123 vendor. + Fix a typo in config.h.in. --- src/rng/CMakeLists.txt | 7 +++ src/rng/config.h.in | 4 +- src/rng/test/CMakeLists.txt | 106 +++++++++++++++++------------------- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/rng/CMakeLists.txt b/src/rng/CMakeLists.txt index 5285f8fe83..996efa9f6d 100755 --- a/src/rng/CMakeLists.txt +++ b/src/rng/CMakeLists.txt @@ -15,6 +15,13 @@ string(CONCAT header_prefix_source string(CONCAT header_prefix_binary "$" "$") +# 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) #--------------------------------------------------------------------------------------------------# diff --git a/src/rng/config.h.in b/src/rng/config.h.in index 1db7ec28eb..63ba0c9762 100644 --- a/src/rng/config.h.in +++ b/src/rng/config.h.in @@ -12,10 +12,10 @@ #include "ds++/config.h" /* Enable Random123 C++11 support */ -#cmakedefine R123_USE_CXX11 @R123_USE_CXX11 @ +#cmakedefine R123_USE_CXX11 @R123_USE_CXX11@ /* Use C++11 std::random */ -#cmakedefine R123_USE_STD_RANDOM @R123_USE_STD_RANDOM @ +#cmakedefine R123_USE_STD_RANDOM @R123_USE_STD_RANDOM@ /* USE STANDARD C INTERFACE */ #ifndef _MSC_VER diff --git a/src/rng/test/CMakeLists.txt b/src/rng/test/CMakeLists.txt index 6dbedff366..e15d8b4dd3 100755 --- a/src/rng/test/CMakeLists.txt +++ b/src/rng/test/CMakeLists.txt @@ -3,92 +3,84 @@ # author Kelly Thompson # date 2012 Aug 1 # brief Generate build project files for rng/test. -# note Copyright (C) 2016-2019, Triad National Security, LLC. -# All rights reserved. +# note Copyright (C) 2016-2019, Triad National Security, LLC., All rights reserved. #--------------------------------------------------------------------------------------------------# 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_gsl.c - ${PROJECT_SOURCE_DIR}/ut_M128.cpp - ${PROJECT_SOURCE_DIR}/ut_uniform.cpp -) - -if( R123_USE_CXX11 ) - list( APPEND random123_unit_tests - ${PROJECT_SOURCE_DIR}/ut_Engine.cpp ) + ${PROJECT_SOURCE_DIR}/ut_aes.cpp + ${PROJECT_SOURCE_DIR}/ut_ars.c + ${PROJECT_SOURCE_DIR}/ut_carray.cpp + ${PROJECT_SOURCE_DIR}/ut_gsl.c + ${PROJECT_SOURCE_DIR}/ut_M128.cpp + ${PROJECT_SOURCE_DIR}/ut_uniform.cpp ) + +# 2020 SEP - ut_Engine.cpp and kat_* tests updated to be compatible with Random123-1.13.2. They are +# no longer compatible with version 1.09. +if( R123_USE_CXX11 AND 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 -) +if( R123_VERSION VERSION_GREATER "1.09" ) + set( random123_known_answer_tests + ${PROJECT_SOURCE_DIR}/kat_c.c + ${PROJECT_SOURCE_DIR}/kat_cpp.cpp ) +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" ) - -add_scalar_tests( - SOURCES "${random123_known_answer_tests}" + SOURCES "${random123_unit_tests}" DEPS "Lib_rng" - PASS_REGEX "PASSED" - FAIL_REGEX "FAILED" ) -target_include_directories( Ut_rng_ut_uniform_exe - PRIVATE $ ) - - if( USE_CUDA AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL ) - - set( test_sources_cuda - ${PROJECT_SOURCE_DIR}/kat_cuda.cu) + PASS_REGEX "OK|SUCCESS" + FAIL_REGEX "failed;error;Failure" ) +target_include_directories( Ut_rng_ut_uniform_exe PRIVATE + $ ) + +if( R123_VERSION VERSION_GREATER "1.09" ) + add_scalar_tests( + SOURCES "${random123_known_answer_tests}" + DEPS "Lib_rng" + PASS_REGEX "PASSED" + FAIL_REGEX "FAILED" ) +endif() +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 - $ - $ - ${RANDOM123_INCLUDE_DIR} ) + NOEXPORT ) +target_include_directories( Exe_time_serial PRIVATE + $ + $ + ${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 From 7202713a0074630ccf4deb6abd709df8a7c0470d Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Fri, 25 Sep 2020 12:44:12 -0600 Subject: [PATCH 3/8] Cleanup CMakeLists.txt after merge. --- src/rng/test/CMakeLists.txt | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/rng/test/CMakeLists.txt b/src/rng/test/CMakeLists.txt index 64758b3bf9..89d49d1b35 100755 --- a/src/rng/test/CMakeLists.txt +++ b/src/rng/test/CMakeLists.txt @@ -34,27 +34,26 @@ 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 ) + 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() #--------------------------------------------------------------------------------------------------# @@ -66,20 +65,19 @@ add_scalar_tests( 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 $ ) 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 $ ) - if( USE_CUDA AND NOT CMAKE_CXX_COMPILER_ID MATCHES XL ) +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( From 487e2d334b649c6f2feea3e17f43f6dfe37c199e Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Fri, 25 Sep 2020 15:20:37 -0600 Subject: [PATCH 4/8] Fix a bad merge. --- src/rng/CMakeLists.txt | 1 + src/rng/config.h.in | 2 ++ src/rng/test/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rng/CMakeLists.txt b/src/rng/CMakeLists.txt index 996efa9f6d..e68647a556 100755 --- a/src/rng/CMakeLists.txt +++ b/src/rng/CMakeLists.txt @@ -27,6 +27,7 @@ endif() #--------------------------------------------------------------------------------------------------# 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" ) diff --git a/src/rng/config.h.in b/src/rng/config.h.in index 63ba0c9762..6ffb9e474a 100644 --- a/src/rng/config.h.in +++ b/src/rng/config.h.in @@ -17,6 +17,8 @@ /* 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__ diff --git a/src/rng/test/CMakeLists.txt b/src/rng/test/CMakeLists.txt index 89d49d1b35..ed4407dba6 100755 --- a/src/rng/test/CMakeLists.txt +++ b/src/rng/test/CMakeLists.txt @@ -36,7 +36,7 @@ set( random123_unit_tests if( NOT MSVC ) list(APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_gsl.c ) endif() -if( R123_USE_CXX11 ) +if( R123_VERSION VERSION_GREATER 1.09 ) list( APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_Engine.cpp ) endif() From c1c8de94015d1690907579faa69073110f9ef3d4 Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Sun, 4 Oct 2020 12:36:27 -0600 Subject: [PATCH 5/8] rng tests working with r123@1.13.2. --- environment/bashrc/.bashrc_darwin_fe | 2 +- src/rng/test/kat.h | 19 ++- src/rng/test/kat_c.c | 59 ++++--- src/rng/test/kat_cpp.cpp | 59 +++---- src/rng/test/kat_cuda.cu | 8 +- src/rng/test/kat_dev_execute.h | 31 ++-- src/rng/test/kat_main.h | 81 +++++----- src/rng/test/rngNxW.h | 69 ++++----- src/rng/test/time_initkeyctr.h | 214 ++++++++++++++------------ src/rng/test/time_misc.h | 2 +- src/rng/test/time_random123.h | 92 +++++------ src/rng/test/time_serial.c | 201 ++++++++++++------------ src/rng/test/ut_Engine.cpp | 47 +++--- src/rng/test/ut_M128.cpp | 4 +- src/rng/test/ut_aes.cpp | 3 +- src/rng/test/ut_ars.c | 18 +-- src/rng/test/ut_carray.cpp | 9 +- src/rng/test/ut_uniform.cpp | 92 +++++------ src/rng/test/ut_uniform_reference.hpp | 54 ++++--- src/rng/test/util.h | 103 ++++++------- src/rng/test/util_cpu.h | 19 ++- src/rng/test/util_cuda.h | 165 ++++++++++++-------- src/rng/test/util_demangle.hpp | 54 ++++--- src/rng/test/util_expandtpl.h | 57 +++---- src/rng/test/util_m128.h | 26 ++-- src/rng/test/util_print.h | 35 +++-- 26 files changed, 823 insertions(+), 700 deletions(-) diff --git a/environment/bashrc/.bashrc_darwin_fe b/environment/bashrc/.bashrc_darwin_fe index 602deb281b..4215d22f13 100644 --- a/environment/bashrc/.bashrc_darwin_fe +++ b/environment/bashrc/.bashrc_darwin_fe @@ -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" diff --git a/src/rng/test/kat.h b/src/rng/test/kat.h index c70704f223..0b577cb6bf 100644 --- a/src/rng/test/kat.h +++ b/src/rng/test/kat.h @@ -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 @@ -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 @@ -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; diff --git a/src/rng/test/kat_c.c b/src/rng/test/kat_c.c index 00e10a9902..9c2b548b37 100644 --- a/src/rng/test/kat_c.c +++ b/src/rng/test/kat_c.c @@ -1,28 +1,33 @@ /* -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 modification, are permitted -provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: -* Redistributions of source code must retain the above copyright notice, this list of conditions, - and the following disclaimer. +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. -* 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. +* 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. -* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse - or promote products derived from this software without specific prior written permission. +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR -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. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ #ifdef _MSC_FULL_VER @@ -35,15 +40,29 @@ THE USE 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, unsigned 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 +//------------------------------------------------------------------------------------------------// diff --git a/src/rng/test/kat_cpp.cpp b/src/rng/test/kat_cpp.cpp index d6f2253916..dfb5b21a64 100644 --- a/src/rng/test/kat_cpp.cpp +++ b/src/rng/test/kat_cpp.cpp @@ -2,27 +2,32 @@ Copyright 2010-2011, D. E. Shaw Research. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted -provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions, - and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse - or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR -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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ #ifdef _MSC_FULL_VER @@ -37,11 +42,13 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "kat_main.h" -// With C++, it's a little trickier to create the mapping from method-name/round-count to functions -// because the round-counts are template arguments that have to be specified at compile-time. Thus, -// we can't just do #define RNGNxW_TPL and #include "rngNxW.h". We have to build a static map from: -// pair to functions that apply the right generator with the right number of -// rounds. +// With C++, it's a little trickier to create the mapping from +// method-name/round-count to functions +// because the round-counts are template arguments that have to be +// specified at compile-time. Thus, we can't just do #define RNGNxW_TPL +// and #include "rngNxW.h". We have to build a static map from: +// pair to functions that apply the right generator +// with the right number of rounds. #if (DBS_GNUC_VERSION >= 40204) && !defined(__ICC) && !defined(NVCC) // Suppress GCC's "unused parameter" warning, about lhs and rhs in sse.h, and an "unused local diff --git a/src/rng/test/kat_cuda.cu b/src/rng/test/kat_cuda.cu index 690ad5b3ac..4b908a9aaa 100644 --- a/src/rng/test/kat_cuda.cu +++ b/src/rng/test/kat_cuda.cu @@ -37,23 +37,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define KAT_UINT size_t #include "kat_dev_execute.h" -void host_execute_tests(kat_instance *tests_host, size_t ntests){ +void host_execute_tests(kat_instance *tests_host, unsigned ntests){ CUDAInfo *infop; kat_instance *tests_dev; size_t tests_sz; infop = cuda_init(NULL); - tests_sz = ntests * sizeof(tests_host[0]); + tests_sz = sizeof(tests_host[0]) * (ntests+1); // +1 for sentinel test with method==last CHECKCALL(cudaMalloc(&tests_dev, tests_sz)); CHECKCALL(cudaMemcpy(tests_dev, tests_host, tests_sz, cudaMemcpyHostToDevice)); - printf("starting %zu tests on 1 blocks with 1 threads/block\n", ntests); + printf("starting %u tests on 1 blocks with 1 threads/block\n", ntests); fflush(stdout); // TO DO: call this with parallelism, <<blocks_per_grid, infop->threads_per_block>>> // and then insure that each of the threads got the same result. - dev_execute_tests<<<1, 1>>>(tests_dev, ntests); + dev_execute_tests<<<1, 1>>>(tests_dev); CHECKCALL(cudaDeviceSynchronize()); CHECKCALL(cudaMemcpy(tests_host, tests_dev, tests_sz, cudaMemcpyDeviceToHost)); diff --git a/src/rng/test/kat_dev_execute.h b/src/rng/test/kat_dev_execute.h index 09b9c3f0af..25ca6abb90 100644 --- a/src/rng/test/kat_dev_execute.h +++ b/src/rng/test/kat_dev_execute.h @@ -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 @@ -30,16 +30,27 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "kat.h" -KAT_KERNEL void dev_execute_tests(KAT_GLOBAL kat_instance *tests, KAT_UINT ntests){ - size_t i; - for(i=0; iphilox2x32_data.computed = philox2x32_R(ti->rounds, ti->philox2x32_data.ctr, ti->philox2x32_data.key); */ -#define RNGNxW_TPL(base, N, W) case base##N##x##W##_e: ti->u.base##N##x##W##_data.computed = base##N##x##W##_R(ti->nrounds, ti->u.base##N##x##W##_data.ctr, base##N##x##W##keyinit(ti->u.base##N##x##W##_data.ukey)); break; +#ifndef KAT_METAL_BUFFER0 +#define KAT_METAL_BUFFER0 /* non-empty only when compiling Metal kernel */ +#endif +KAT_KERNEL void dev_execute_tests(KAT_GLOBAL kat_instance *tests KAT_METAL_BUFFER0) { + size_t i; + int done = 0; + for (i = 0; !done; ++i) { + KAT_GLOBAL kat_instance *ti = &tests[i]; + switch (tests[i].method) { + //case philox2x32_e: ti->u.philox2x32_data.computed = philox2x32_R(ti->rounds, ti->u.philox2x32_data.ctr, ti->u.philox2x32_data.key); +#define RNGNxW_TPL(base, N, W) \ + case base##N##x##W##_e: \ + ti->u.base##N##x##W##_data.computed = \ + base##N##x##W##_R(ti->nrounds, ti->u.base##N##x##W##_data.ctr, \ + base##N##x##W##keyinit(ti->u.base##N##x##W##_data.ukey)); \ + break; #include "rngNxW.h" #undef RNGNxW_TPL - case unused: ; /* silence a warning */ - } + case last: + done = 1; + break; } + } } diff --git a/src/rng/test/kat_main.h b/src/rng/test/kat_main.h index 9a154a6378..e49c2e5ed2 100644 --- a/src/rng/test/kat_main.h +++ b/src/rng/test/kat_main.h @@ -2,27 +2,32 @@ Copyright 2010-2011, D. E. Shaw Research. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted -provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions, - and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse - or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR -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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ /* Known Answer Test */ @@ -38,20 +43,25 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. kat_opencl.c kat_metal.m - These correspond to make targets: kat_c, kat_cpp, kat_cuda, kat_opencl and kat_metal. + These correspond to make targets: kat_c, kat_cpp, kat_cuda, + kat_opencl and kat_metal. - Those files are relatively simple. First, they #include this file, which contains all the - machinery for reading test vectors, complaining about errors, etc.. Then they implement the - function host_execute_tests() in the appropriate environment. host_execute_tests looks very - different in C/C++/CUDA/OpenCL/Metal. + Those files are relatively simple. First, they #include this file, + which contains all the machinery for reading test vectors, + complaining about errors, etc.. Then they implement the function + host_execute_tests() in the appropriate environment. host_execute_tests + looks very different in C/C++/CUDA/OpenCL/Metal. - host_execute_tests contrives to call/launch "dev_execute_tests" on the device. Except for a few - environment-specific keywords, (e.g., __global, __kernel), which are #defined in kat_XXX.c, - dev_execute_tests is obtained by including a common source file: #include + host_execute_tests contrives to call/launch "dev_execute_tests" + on the device. Except for a few environment-specific keywords, + (e.g., __global, __kernel), which are #defined in kat_XXX.c, + dev_execute_tests is obtained by including a common source file: + #include - One final complication: in order to fully "bake" the source code into the binary at compile-time, - dev_execute_tests for opencl is implemented in kat_opencl_kernel.ocl, which is processed by - gencl.sh into kat_opencl_kernel.i, which is thein #include-ed by kat_opencl.c. + One final complication: in order to fully "bake" the source code + into the binary at compile-time, dev_execute_tests for opencl is implemented in + kat_opencl_kernel.ocl, which is processed by gencl.sh into + kat_opencl_kernel.i, which is thein #include-ed by kat_opencl.c. */ #include "kat.h" @@ -213,7 +223,7 @@ void analyze_tests(const kat_instance *tests, unsigned ntests) { break; #include "rngNxW.h" #undef RNGNxW_TPL - case unused:; /* silence a warning */ + case last:; } } } @@ -289,7 +299,8 @@ int main(int argc, char **argv) { fprintf(stderr, "No more space for tests? Recompile with a larger NTESTS\n"); exit(1); } - //kt tests[t].method = last; // N.B *not* t++ - the 'ntests' value passed to host_execute_tests does not count the 'last' one. + tests[t].method = + last; // N.B *not* t++ - the 'ntests' value passed to host_execute_tests does not count the 'last' one. report_unknowns(); printf("Perform %lu tests.\n", (unsigned long)t); @@ -308,4 +319,4 @@ int main(int argc, char **argv) { //------------------------------------------------------------------------------------------------// // end kat_cpp.cpp -//------------------------------------------------------------------------------------------------/ +//------------------------------------------------------------------------------------------------// diff --git a/src/rng/test/rngNxW.h b/src/rng/test/rngNxW.h index 510f4d0fdb..0224f558c1 100644 --- a/src/rng/test/rngNxW.h +++ b/src/rng/test/rngNxW.h @@ -1,31 +1,33 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ #ifdef __clang__ @@ -33,19 +35,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma clang diagnostic ignored "-Wexpansion-to-defined" #endif -RNGNxW_TPL(philox, 2, 32) -RNGNxW_TPL(philox, 4, 32) +RNGNxW_TPL(philox, 2, 32) RNGNxW_TPL(philox, 4, 32) RNGNxW_TPL(threefry, 2, 32) + RNGNxW_TPL(threefry, 4, 32) +#if R123_USE_64BIT #if R123_USE_PHILOX_64BIT -RNGNxW_TPL(philox, 2, 64) -RNGNxW_TPL(philox, 4, 64) + RNGNxW_TPL(philox, 2, 64) RNGNxW_TPL(philox, 4, 64) +#endif + RNGNxW_TPL(threefry, 2, 64) RNGNxW_TPL(threefry, 4, 64) #endif -RNGNxW_TPL(threefry, 2, 32) -RNGNxW_TPL(threefry, 2, 64) -RNGNxW_TPL(threefry, 4, 32) -RNGNxW_TPL(threefry, 4, 64) #if R123_USE_AES_NI -RNGNxW_TPL(ars, 4, 32) -RNGNxW_TPL(aesni, 4, 32) + RNGNxW_TPL(ars, 4, 32) RNGNxW_TPL(aesni, 4, 32) #endif #ifdef __clang__ diff --git a/src/rng/test/time_initkeyctr.h b/src/rng/test/time_initkeyctr.h index d336e37be6..b64033e138 100644 --- a/src/rng/test/time_initkeyctr.h +++ b/src/rng/test/time_initkeyctr.h @@ -1,31 +1,33 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ #ifndef TIME_INITKEYCTR_H__ #define TIME_INITKEYCTR_H__ 1 @@ -43,6 +45,30 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma clang diagnostic ignored "-Wexpansion-to-defined" #endif +/* + * EXAMPLE_KEY* and EXAMPLE_CTR* values are just arbitrary numbers + * with some bits set, they have no special importance, they do + * not even have to be different. If they are changed, then the + * good_* values further below will need to be updated to match. + */ + +#define EXAMPLE_KEY0 0xdeadbeefU +#define EXAMPLE_KEY1 0x12345678U +#define EXAMPLE_KEY2 0xc0debad1U +#define EXAMPLE_KEY3 0x31415926U + +#define EXAMPLE_CTR0 0x00000000U +#define EXAMPLE_CTR1 0x10000000U +#define EXAMPLE_CTR2 0x20000000U +#define EXAMPLE_CTR3 0x30000000U + +/* + * The magic hex numbers below are just known good values that + * result from the arbitrary EXAMPLE* inputs above. We check that + * we got these results at the end of timing tests to ensure that + * we didn't accidentally let a compiler optimize away some loop. + */ + #if defined(TRY_OTHER) static mrg1x32_ctr_t good_mrg1x32_1 = {{0x4b2cd7ee}}; static mt1x32_ctr_t good_mt1x32_1 = {{0x39037a7d}}; @@ -50,97 +76,95 @@ static mtsmall1x32_ctr_t good_mtsmall1x32_1 = {{0x7afd2a98}}; static cmrg1x32_ctr_t good_cmrg1x32_1 = {{0x032b54e2}}; static xorwow1x32_ctr_t good_xorwow1x32_1 = {{0xed1b6264}}; #endif - #if R123_USE_PHILOX_64BIT static philox2x64_ctr_t good_philox2x64_6 = { {R123_64BIT(0xdd40cdb81af968d2), R123_64BIT(0x0cb57d6d5f7b68dc)}}; static philox2x64_ctr_t good_philox2x64_10 = { {R123_64BIT(0x539e5b3d18faf5da), R123_64BIT(0x838ca1328d07d3ba)}}; static philox4x64_ctr_t good_philox4x64_7 = { - {R123_64BIT(0xcf492074862957a2), R123_64BIT(0x7057627260938584), - R123_64BIT(0x676e23214a14901d), R123_64BIT(0xefa2c5df3848e3fe)}}; + {R123_64BIT(0xcf492074862957a2), R123_64BIT(0x7057627260938584), R123_64BIT(0x676e23214a14901d), + R123_64BIT(0xefa2c5df3848e3fe)}}; static philox4x64_ctr_t good_philox4x64_10 = { - {R123_64BIT(0x1b64f56b381a5a89), R123_64BIT(0x940a282a8add45e1), - R123_64BIT(0x53c936376ac7d5df), R123_64BIT(0x6147e87ec9bd9caa)}}; + {R123_64BIT(0x1b64f56b381a5a89), R123_64BIT(0x940a282a8add45e1), R123_64BIT(0x53c936376ac7d5df), + R123_64BIT(0x6147e87ec9bd9caa)}}; #endif -static philox4x32_ctr_t good_philox4x32_7 = { - {0x40ba6a95, 0x799e6a43, 0x7dcabe10, 0xa7a81636}}; -static philox4x32_ctr_t good_philox4x32_10 = { - {0xf16d828e, 0xa1c5962d, 0xacac820c, 0x58113d7a}}; +static philox4x32_ctr_t good_philox4x32_7 = {{0x40ba6a95, 0x799e6a43, 0x7dcabe10, 0xa7a81636}}; +static philox4x32_ctr_t good_philox4x32_10 = {{0xf16d828e, 0xa1c5962d, 0xacac820c, 0x58113d7a}}; +static threefry4x32_ctr_t good_threefry4x32_12 = {{0xe461db1c, 0xfdfa62a7, 0x0b10cd2a, 0xa3679758}}; +static threefry4x32_ctr_t good_threefry4x32_20 = {{0xf82cf576, 0x162ca116, 0x3afefe23, 0x54cc64ac}}; +#if R123_USE_64BIT static threefry2x64_ctr_t good_threefry2x64_13 = { {R123_64BIT(0xdf0f096c179ad798), R123_64BIT(0x077862fbaa1a0d11)}}; static threefry2x64_ctr_t good_threefry2x64_20 = { {R123_64BIT(0xb91153d59815d50e), R123_64BIT(0xdb0dd45e5b0eab81)}}; static threefry4x64_ctr_t good_threefry4x64_12 = { - {R123_64BIT(0x416d1802da0a4a0f), R123_64BIT(0xabd4d80749306281), - R123_64BIT(0x62c6b120b542bff0), R123_64BIT(0xefb28dc80c6fc36c)}}; + {R123_64BIT(0x416d1802da0a4a0f), R123_64BIT(0xabd4d80749306281), R123_64BIT(0x62c6b120b542bff0), + R123_64BIT(0xefb28dc80c6fc36c)}}; static threefry4x64_ctr_t good_threefry4x64_20 = { - {R123_64BIT(0xad8f0b8c18ed5187), R123_64BIT(0xd80146a6961e1880), - R123_64BIT(0x7fce9d950d8acbc4), R123_64BIT(0x782948d5203519f1)}}; -static threefry4x32_ctr_t good_threefry4x32_12 = { - {0xe461db1c, 0xfdfa62a7, 0x0b10cd2a, 0xa3679758}}; -static threefry4x32_ctr_t good_threefry4x32_20 = { - {0xf82cf576, 0x162ca116, 0x3afefe23, 0x54cc64ac}}; + {R123_64BIT(0xad8f0b8c18ed5187), R123_64BIT(0xd80146a6961e1880), R123_64BIT(0x7fce9d950d8acbc4), + R123_64BIT(0x782948d5203519f1)}}; static threefry4x64_ctr_t good_threefry4x64_72 = { - {R123_64BIT(0x73ff3f7a0b878f68), R123_64BIT(0x6668f6bbaba83f31), - R123_64BIT(0x088eb85d40fbdb56), R123_64BIT(0xd1f39136adc96552)}}; + {R123_64BIT(0x73ff3f7a0b878f68), R123_64BIT(0x6668f6bbaba83f31), R123_64BIT(0x088eb85d40fbdb56), + R123_64BIT(0xd1f39136adc96552)}}; +#endif #if R123_USE_AES_NI -static ars4x32_ctr_t good_ars4x32_5 = { - {0x279f6b0b, 0xd0b1edf6, 0x6044b433, 0x66c06817}}; -static ars4x32_ctr_t good_ars4x32_7 = { - {0xa9cd8055, 0x80272a47, 0x4b7ab914, 0x5351d78e}}; -static aesni4x32_ctr_t good_aesni4x32_10 = { - {0x1e68c9fd, 0x347b0858, 0x503d8d91, 0x9e73460a}}; +static ars4x32_ctr_t good_ars4x32_5 = {{0x279f6b0b, 0xd0b1edf6, 0x6044b433, 0x66c06817}}; +static ars4x32_ctr_t good_ars4x32_7 = {{0xa9cd8055, 0x80272a47, 0x4b7ab914, 0x5351d78e}}; +static aesni4x32_ctr_t good_aesni4x32_10 = {{0x1e68c9fd, 0x347b0858, 0x503d8d91, 0x9e73460a}}; #endif /* - * Initializes a ukey and counter to known values with a known offset and calls - * the test function with that ukey, ctr and a count and closure. keyctroffset - * should be a variable initialized from the environment to avoid compiler - * optimization from known constants (after inlining). + * template code initializes a ukey and counter to known values + * with a known offset and calls a Random123 test function with + * that ukey, ctr and a count and closure. keyctroffset is + * a variable initialized from runtime environment (e.g. argv, argc, + * getenv(), etc) to avoid compile-time optimization + * caused by constants, so we get worst-case numbers. Users may, + * of course, benefit from compile-time optimization if they + * have some constants for key or ctr values. + * */ -#define TEST_TPL(NAME, N, W, R) \ - if ((strncmp(#NAME, "aes", 3) == 0 || strncmp(#NAME, "ars", 3) == 0) && \ - !haveAESNI()) { \ - printf("AESNI not available on this hardware\n"); \ - } else { \ - NAME##N##x##W##_ukey_t ukey = {{0}}; \ - NAME##N##x##W##_ctr_t ctr = {{0}}; \ - size_t xi; \ - for (xi = 0; xi < sizeof(ukey) / sizeof(ukey.v[0]); xi++) { \ - switch (xi) { \ - case 0: \ - ukey.v[xi] = 0xdeadbeef + keyctroffset; \ - break; \ - case 1: \ - ukey.v[xi] = 0x12345678 + keyctroffset; \ - break; \ - case 2: \ - ukey.v[xi] = 0xc0debad1 + keyctroffset; \ - break; \ - case 3: \ - ukey.v[xi] = 0x31415926 + keyctroffset; \ - break; \ - } \ - } \ - for (xi = 0; xi < N; xi++) { \ - switch (xi) { \ - case 0: \ - ctr.v[xi] = 0x00000000 + keyctroffset; \ - break; \ - case 1: \ - ctr.v[xi] = 0x10000000 + keyctroffset; \ - break; \ - case 2: \ - ctr.v[xi] = 0x20000000 + keyctroffset; \ - break; \ - case 3: \ - ctr.v[xi] = 0x30000000 + keyctroffset; \ - break; \ - } \ - } \ - NAME##N##x##W##_##R(ukey, ctr, good_##NAME##N##x##W##_##R, count, infop); \ +#define TEST_TPL(NAME, N, W, R) \ + if ((strncmp(#NAME, "aes", 3) == 0 || strncmp(#NAME, "ars", 3) == 0) && !haveAESNI()) { \ + printf("AESNI not available on this hardware\n"); \ + } else { \ + NAME##N##x##W##_ukey_t ukey = {{0}}; \ + NAME##N##x##W##_ctr_t ctr = {{0}}; \ + size_t xi; \ + for (xi = 0; xi < sizeof(ukey) / sizeof(ukey.v[0]); xi++) { \ + switch (xi) { \ + case 0: \ + ukey.v[xi] = EXAMPLE_KEY0 + keyctroffset; \ + break; \ + case 1: \ + ukey.v[xi] = EXAMPLE_KEY1 + keyctroffset; \ + break; \ + case 2: \ + ukey.v[xi] = EXAMPLE_KEY2 + keyctroffset; \ + break; \ + case 3: \ + ukey.v[xi] = EXAMPLE_KEY3 + keyctroffset; \ + break; \ + } \ + } \ + for (xi = 0; xi < N; xi++) { \ + switch (xi) { \ + case 0: \ + ctr.v[xi] = EXAMPLE_CTR0 + keyctroffset; \ + break; \ + case 1: \ + ctr.v[xi] = EXAMPLE_CTR1 + keyctroffset; \ + break; \ + case 2: \ + ctr.v[xi] = EXAMPLE_CTR2 + keyctroffset; \ + break; \ + case 3: \ + ctr.v[xi] = EXAMPLE_CTR3 + keyctroffset; \ + break; \ + } \ + } \ + NAME##N##x##W##_##R(ctr, ukey, good_##NAME##N##x##W##_##R, count, infop); \ } #include "util_expandtpl.h" diff --git a/src/rng/test/time_misc.h b/src/rng/test/time_misc.h index c9d379e3f4..4dd2fb0749 100644 --- a/src/rng/test/time_misc.h +++ b/src/rng/test/time_misc.h @@ -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 diff --git a/src/rng/test/time_random123.h b/src/rng/test/time_random123.h index 7d19f9e9f8..7eda1e7637 100644 --- a/src/rng/test/time_random123.h +++ b/src/rng/test/time_random123.h @@ -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 @@ -49,6 +49,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef __OPENCL_VERSION__ #define KERNEL __kernel #define MEMTYPE __global +#define xprintf(x) +#elif defined(__CUDA_ARCH__) +#define xprintf(x) +#else +#define xprintf(x) printf x #endif #ifndef KERNEL @@ -69,52 +74,51 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. unrepresentative of the kinds of optimizations that are possible in practice. I.e., we could not find any "real" use of the output of the RNG that permitted SSE-ization of the RNG. */ -#define LOOK_AT(A, I, N) \ - do { \ - if (N == 4) \ - if (R123_BUILTIN_EXPECT(!(A.v[N > 2 ? 3 : 0] ^ A.v[N > 2 ? 2 : 0] ^ \ - A.v[N > 1 ? 1 : 0] ^ A.v[0]), \ - 0)) \ - ++I; \ - if (N == 2) \ - if (R123_BUILTIN_EXPECT(!(A.v[N > 1 ? 1 : 0] ^ A.v[0]), 0)) \ - ++I; \ - if (N == 1) \ - if (R123_BUILTIN_EXPECT(!(A.v[0]), 0)) \ - ++I; \ +#define LOOK_AT(A, I, N) \ + do { \ + if (N == 4) \ + if (R123_BUILTIN_EXPECT( \ + !(A.v[N > 2 ? 3 : 0] ^ A.v[N > 2 ? 2 : 0] ^ A.v[N > 1 ? 1 : 0] ^ A.v[0]), 0)) \ + ++I; \ + if (N == 2) \ + if (R123_BUILTIN_EXPECT(!(A.v[N > 1 ? 1 : 0] ^ A.v[0]), 0)) \ + ++I; \ + if (N == 1) \ + if (R123_BUILTIN_EXPECT(!(A.v[0]), 0)) \ + ++I; \ } while (0) /* Macro that will expand later into all the Random123 PRNGs for NxW_R */ -/* Note that making the first argument uint seems to expose some - argument marshalling bugs in version 2.4 of the AMDAPPSDK. Passing - a 64-bit (ulong) seems to fix things, but since we know the value - fits in 32 bits, we assign it to a 32-bit (uint) to reduce loop - overhead. -*/ -#define TEST_TPL(NAME, N, W, R) \ - KERNEL void test_##NAME##N##x##W##_##R( \ - uint64_t n64, NAME##N##x##W##_ukey_t uk, NAME##N##x##W##_ctr_t ctrinit, \ - MEMTYPE NAME##N##x##W##_ctr_t *ctr) { \ - uint n = (uint)n64; \ - unsigned tid = get_global_id(0); \ - uint i; \ - NAME##N##x##W##_ctr_t c, v = {{0}}; \ - NAME##N##x##W##_key_t k = NAME##N##x##W##keyinit(uk); \ - c = ctrinit; \ - if (R == NAME##N##x##W##_rounds) { \ - for (i = 0; i < n; ++i) { \ - v = NAME##N##x##W(c, k); \ - LOOK_AT(v, i, N); \ - c.v[0]++; \ - } \ - } else { \ - for (i = 0; i < n; ++i) { \ - v = NAME##N##x##W##_R(R, c, k); \ - LOOK_AT(v, i, N); \ - c.v[0]++; \ - } \ - } \ - ctr[tid] = v; \ +/* XXX AMDAPPSDK 2.4 seemed unhappy with the first arg being uint, but + was ok when it was changed to uint64_t. It's now back to unsigned + because that seems more correct and generic. Nobody's using 2.4 + any more, are they? Note that this macro is expanded into CPU, + CUDA and OpenCL "kernels", so it has to be generic. */ +#define TEST_TPL(NAME, N, W, R) \ + KERNEL void test_##NAME##N##x##W##_##R(unsigned n, NAME##N##x##W##_ctr_t ctrinit, \ + NAME##N##x##W##_ukey_t uk, \ + MEMTYPE NAME##N##x##W##_ctr_t *ctr) { \ + unsigned tid = get_global_id(0); \ + unsigned i; \ + NAME##N##x##W##_ctr_t c, v = {{0}}; \ + NAME##N##x##W##_key_t k = NAME##N##x##W##keyinit(uk); \ + c = ctrinit; \ + if (R == NAME##N##x##W##_rounds) { \ + for (i = 0; i < n; ++i) { \ + v = NAME##N##x##W(c, k); \ + LOOK_AT(v, i, N); \ + c.v[0]++; \ + } \ + } else { \ + for (i = 0; i < n; ++i) { \ + v = NAME##N##x##W##_R(R, c, k); \ + /*xprintf(("1: %s k[0] %lx c[0] %lx v[0] %lx\n", #NAME #N "x" #W "_" #R, (unsigned long) k.v[0], (unsigned long) c.v[0], (unsigned long) v.v[0]));*/ \ + /*if (c.v[0] == 0) printline_##NAME##N##x##W##_##R(k, c, &v, 1);*/ \ + LOOK_AT(v, i, N); \ + c.v[0]++; \ + } \ + } \ + ctr[tid] = v; \ } /* diff --git a/src/rng/test/time_serial.c b/src/rng/test/time_serial.c index 0aa93669a7..e7d1dbea1f 100644 --- a/src/rng/test/time_serial.c +++ b/src/rng/test/time_serial.c @@ -1,41 +1,46 @@ /* -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 modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ /* - * Single-core CPU test and timing harness for Random123 RNGs. Uses macros and - * util_expandtpl.h to "templatize" over all the different permutations of RNGs - * and NxW and R. + * Single-core CPU test and timing harness for Random123 RNGs. + * Uses macros and util_expandtpl.h to "templatize" over all the + * different permutations of RNGs and NxW and R. */ #include "util.h" -#include "time_serial.h" +#include "Random123/aes.h" +#include "Random123/ars.h" +#include "Random123/philox.h" +#include "Random123/threefry.h" #include "time_misc.h" #include "util_print.h" @@ -57,76 +62,74 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma GCC diagnostic ignored "-Wfloat-equal" #endif -#define TEST_TPL(NAME, N, W, R) \ - void NAME##N##x##W##_##R( \ - NAME##N##x##W##_ukey_t ukey, NAME##N##x##W##_ctr_t ctr, \ - NAME##N##x##W##_ctr_t kactr, uint count, CPUInfo *tp) { \ - const char *kernelname = #NAME #N "x" #W "_" #R; \ - double cur_time; \ - int n, \ - niterations = \ - numtrials; /* we make niterations + 2 (warmup, overhead) calls to the kernel */ \ - uint kcount = 0; \ - double basetime = 0., dt = 0., mindt = 0.; \ - NAME##N##x##W##_ctr_t C, *hC = &C; \ - \ - for (n = -2; n < niterations; n++) { \ - if (n == -2) { \ - if (count == 0) { \ - /* try to set a good guess for count */ \ - count = (uint)(tp->hz ? tp->hz * 1e-5 : 100000); \ - dprintf(("starting with count = %u\n", count)); \ - } \ - kcount = count; \ - } else if (n == -1) { \ - /* use first iteration time to calibrate count to get approximately sec_per_trial */ \ - if (count > 1) { \ - count = (uint)(count * sec_per_trial / dt); \ - dprintf(("scaled count = %u\n", count)); \ - } \ - /* second iteration is to calculate overhead after warmup */ \ - kcount = 1; \ - } else if (n == 0) { \ - int xj; \ - /* Check that we got the expected value */ \ - for (xj = 0; xj < N; xj++) { \ - if (kactr.v[xj] != hC[0].v[xj]) { \ - printf("%s mismatch: xj = %d, expected\n", kernelname, xj); \ - printline_##NAME##N##x##W##_##R(ukey, ctr, &kactr, 1); \ - printf(" but got\n"); \ - printline_##NAME##N##x##W##_##R(ukey, ctr, hC, 1); \ - if (!debug) \ - exit(1); \ - else \ - break; \ - } else { \ - dprintf(("%s matched word %d\n", kernelname, xj)); \ - } \ - } \ - basetime = dt; \ - if (debug || verbose) { \ - dprintf(("%s %.3f secs\n", kernelname, basetime)); \ - printline_##NAME##N##x##W##_##R(ukey, ctr, hC, 1); \ - } \ - kcount = count + 1; \ - } \ - dprintf(("call function %s\n", kernelname)); \ - (void)timer(&cur_time); \ - test_##NAME##N##x##W##_##R(kcount, ukey, ctr, hC); \ - dt = timer(&cur_time); \ - dprintf(("iteration %d took %.3f secs\n", n, dt)); \ - ALLZEROS(hC, 1, N); \ - if (n == 0 || dt < mindt) \ - mindt = dt; \ - } \ - if (count > 1) { \ - double tpB = (mindt - basetime) / ((kcount - 1.) * (N * W / 8.)); \ - printf("%-17s %#5.3g cpB %#5.3g GB/s %u B granularity (best %u in %.3f " \ - "s - %.6f s)\n", \ - kernelname, tpB * tp->hz, 1e-9 / tpB, (uint)(N * W / 8), kcount, \ - mindt, basetime); \ - fflush(stdout); \ - } \ +#define TEST_TPL(NAME, N, W, R) \ + void NAME##N##x##W##_##R(NAME##N##x##W##_ctr_t ctr, NAME##N##x##W##_ukey_t ukey, \ + NAME##N##x##W##_ctr_t kactr, unsigned count, CPUInfo *tp) { \ + const char *kernelname = #NAME #N "x" #W "_" #R; \ + double cur_time; \ + int n, niterations = \ + numtrials; /* we make niterations + 2 (warmup, overhead) calls to the kernel */ \ + unsigned kcount = 0; \ + double basetime = 0., dt = 0., mindt = 0.; \ + NAME##N##x##W##_ctr_t C, *hC = &C; \ + \ + for (n = -2; n < niterations; n++) { \ + if (n == -2) { \ + if (count == 0) { \ + /* try to set a good guess for count */ \ + count = (unsigned)(tp->hz ? tp->hz * 1e-5 : 100000); \ + dprintf(("starting with count = %u\n", count)); \ + } \ + kcount = count; \ + } else if (n == -1) { \ + /* use first iteration time to calibrate count to get approximately sec_per_trial */ \ + if (count > 1) { \ + count = (unsigned)(count * sec_per_trial / dt); \ + dprintf(("scaled count = %u\n", count)); \ + } \ + /* second iteration is to calculate overhead after warmup */ \ + kcount = 1; \ + } else if (n == 0) { \ + int xj; \ + /* Check that we got the expected value */ \ + for (xj = 0; xj < N; xj++) { \ + if (kactr.v[xj] != hC[0].v[xj]) { \ + printf("%s mismatch: xj = %d, expected\n", kernelname, xj); \ + printline_##NAME##N##x##W##_##R(ukey, ctr, &kactr, 1); \ + printf(" but got\n"); \ + printline_##NAME##N##x##W##_##R(ukey, ctr, hC, 1); \ + if (!debug) \ + exit(1); \ + else \ + break; \ + } else { \ + dprintf(("%s matched word %d\n", kernelname, xj)); \ + } \ + } \ + basetime = dt; \ + if (debug || verbose) { \ + dprintf(("%s %.3f secs\n", kernelname, basetime)); \ + printline_##NAME##N##x##W##_##R(ukey, ctr, hC, 1); \ + } \ + kcount = count + 1; \ + } \ + /* calling timer *before* dprintf avoids an ARMv7 gcc 4.8.3 -O3 compiler bug! */ \ + (void)timer(&cur_time); \ + dprintf(("call function %s\n", kernelname)); \ + test_##NAME##N##x##W##_##R(kcount, ctr, ukey, hC); \ + dt = timer(&cur_time); \ + dprintf(("iteration %d took %.3f secs\n", n, dt)); \ + ALLZEROS(hC, 1, N); \ + if (n == 0 || dt < mindt) \ + mindt = dt; \ + } \ + if (count > 1) { \ + double tpB = (mindt - basetime) / ((kcount - 1.) * (N * W / 8.)); \ + printf("%-17s %#5.3g cpB %#5.3g GB/s %u B granularity (best %u in %.3f s - %.6f s)\n", \ + kernelname, tpB * tp->hz, 1e-9 / tpB, (unsigned)(N * W / 8), kcount, mindt, \ + basetime); \ + fflush(stdout); \ + } \ } #include "util_expandtpl.h" diff --git a/src/rng/test/ut_Engine.cpp b/src/rng/test/ut_Engine.cpp index fb1f7e040b..994d5ab4ec 100644 --- a/src/rng/test/ut_Engine.cpp +++ b/src/rng/test/ut_Engine.cpp @@ -2,27 +2,32 @@ Copyright 2010-2011, D. E. Shaw Research. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted -provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions, - and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may be used to endorse - or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR -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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ // TODO - really do a thorough and complete set of tests. diff --git a/src/rng/test/ut_M128.cpp b/src/rng/test/ut_M128.cpp index d89846047f..ae461b131a 100644 --- a/src/rng/test/ut_M128.cpp +++ b/src/rng/test/ut_M128.cpp @@ -138,7 +138,7 @@ int main(int, char **) { // exception test in ut_carray.cpp bool b(false); -#if ! ( defined(_MSC_VER) && ! defined(DEBUG) ) +#if !(defined(_MSC_VER) && !defined(DEBUG)) rngRemember(bool caught); rngRemember(caught = false); try { @@ -147,7 +147,7 @@ int main(int, char **) { rngRemember(caught = true); } assert(caught); - + rngRemember(caught = false); try { b = One <= AnotherOne; diff --git a/src/rng/test/ut_aes.cpp b/src/rng/test/ut_aes.cpp index ab3d261499..226b584e76 100644 --- a/src/rng/test/ut_aes.cpp +++ b/src/rng/test/ut_aes.cpp @@ -82,8 +82,7 @@ int main(int, char **) { #endif // From FIPS-197, this is the official "right answer" r123array1xm128i right_answer; - right_answer[0] = - m128i_from_charbuf("69c4 e0d8 6a7b 0430 d8cd b780 70b4 c55a"); + right_answer[0] = m128i_from_charbuf("69c4 e0d8 6a7b 0430 d8cd b780 70b4 c55a"); (void) right_answer; /* don't complain about an unused variable if neither NI nor OPENSSL are enabled. */ #if R123_USE_AES_NI diff --git a/src/rng/test/ut_ars.c b/src/rng/test/ut_ars.c index f8aa7c7bbe..31554a2836 100644 --- a/src/rng/test/ut_ars.c +++ b/src/rng/test/ut_ars.c @@ -62,27 +62,21 @@ int main(int argc, char **argv) { char m128str[M128_STR_SIZE], *kat; if (haveAESNI()) { - c.v[0].m = - m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - k.v[0].m = - m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); + c.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); + k.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); ret = ars1xm128i_R(7, c, k); kat = "2b1623350cd214dc 7740187993411872"; if (strcmp(m128i_to_charbuf(ret.v[0].m, m128str), kat) != 0) { - fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, - m128str); + fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, m128str); exit(1); } printf("%s: OK, got %s\n", argv[0], kat); - c.v[0].m = - m128i_from_charbuf("00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); - k.v[0].m = - m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); + c.v[0].m = m128i_from_charbuf("00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); + k.v[0].m = m128i_from_charbuf("01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"); ret = ars1xm128i_R(7, c, k); kat = "2de6b66fa461b668 f380126f32b9cd22"; if (strcmp(m128i_to_charbuf(ret.v[0].m, m128str), kat) != 0) { - fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, - m128str); + fprintf(stderr, "%s: error, expected %s, got %s\n", argv[0], kat, m128str); exit(1); } printf("%s: OK, got %s\n", argv[0], kat); diff --git a/src/rng/test/ut_carray.cpp b/src/rng/test/ut_carray.cpp index 5a76ff03d9..c8164e9ac6 100644 --- a/src/rng/test/ut_carray.cpp +++ b/src/rng/test/ut_carray.cpp @@ -209,20 +209,17 @@ template void doit(size_t N, size_t W) { assert((int)ull(*p) == 1 + (p - iota.begin())); } // cbegin/cend - for (typename atype::const_iterator p = iota.cbegin(); p != iota.cend(); - ++p) { + for (typename atype::const_iterator p = iota.cbegin(); p != iota.cend(); ++p) { assert((int)ull(*p) == 1 + (p - iota.cbegin())); } // rbegin/rend - for (typename atype::reverse_iterator p = iota.rbegin(); p != iota.rend(); - ++p) { + for (typename atype::reverse_iterator p = iota.rbegin(); p != iota.rend(); ++p) { assert((int)ull(*p) == iota.rend() - p); } // crbegin/crend - for (typename atype::const_reverse_iterator p = iota.crbegin(); - p != iota.crend(); ++p) { + for (typename atype::const_reverse_iterator p = iota.crbegin(); p != iota.crend(); ++p) { assert((int)ull(*p) == iota.crend() - p); } diff --git a/src/rng/test/ut_uniform.cpp b/src/rng/test/ut_uniform.cpp index 36dcd84fec..28e1165632 100644 --- a/src/rng/test/ut_uniform.cpp +++ b/src/rng/test/ut_uniform.cpp @@ -2,46 +2,49 @@ Copyright 2013, D. E. Shaw Research. All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. - -* 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. - -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. + +* 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. + +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ -/* ut_uniform.cpp: unit test for uniform.hpp. +/* ut_uniform.cpp: unit test for uniform.hpp. - This is a "sanity test" of u01, uneg11 and u01fixedpt. We confirm that a - histogram of few thousand calls to each of the functions matches a reference - histogram. This verifies that the results are generally sane i.e., they - fall within the expected range, and that they are close to a correct - distribution. It is *not* a foolproof test of correctness, but it should - catch portability issues like errors in r123::make_signed or - r123::make_unsigned or r123::maxTvalue or misunderstandings about - std::numeric_limits. + This is a "sanity test" of u01, uneg11 and u01fixedpt. We confirm + that a histogram of few thousand calls to each of the functions + matches a reference histogram. This verifies that the results are + generally sane i.e., they fall within the expected range, and that + they are close to a correct distribution. It is *not* a foolproof + test of correctness, but it should catch portability issues + like errors in r123::make_signed or r123::make_unsigned + or r123::maxTvalue or misunderstandings about std::numeric_limits. There is a "known answer test" for uniform.hpp in ut_uniform_IEEEkat.cpp, - but it is only expected to work on machines with strict IEEE arithmetic and - no high-precicision intermediates. See its own comments for more details. + but it is only expected to work on machines with strict IEEE arithmetic + and no high-precicision intermediates. See its own comments for + more details. */ #include "rng/config.h" @@ -105,16 +108,14 @@ template typename r123::make_unsigned::type U(T x) { return x; } template typename r123::make_signed::type S(T x) { return x; } -#define Chk(u, Rng, Ftype) \ - do { \ - chk(#u, #Rng, #Ftype, &u); \ +#define Chk(u, Rng, Ftype) \ + do { \ + chk(#u, #Rng, #Ftype, &u); \ } while (0) std::map refmap; -void RefHist(const char *k, const char *v) { - refmap[std::string(k)] = std::string(v); -} +void RefHist(const char *k, const char *v) { refmap[std::string(k)] = std::string(v); } void fillrefhist() { #include "ut_uniform_reference.hpp" @@ -124,8 +125,8 @@ bool checking = true; int nfail = 0; template -void chk(const std::string &fname, const std::string &rngname, - const std::string &ftypename, Utype f) { +void chk(const std::string &fname, const std::string &rngname, const std::string &ftypename, + Utype f) { std::string key = fname + " " + rngname + " " + ftypename; RNG rng; typedef typename RNG::ukey_type ukey_type; @@ -159,9 +160,8 @@ void chk(const std::string &fname, const std::string &rngname, } if (checking) { if (oss.str() != refmap[key]) { - printf( - "MISMATCH: %s:\n\tcomputed histogram=%s\n\treference histogram=%s\n", - key.c_str(), oss.str().c_str(), refmap[key].c_str()); + printf("MISMATCH: %s:\n\tcomputed histogram=%s\n\treference histogram=%s\n", key.c_str(), + oss.str().c_str(), refmap[key].c_str()); nfail++; } } else { diff --git a/src/rng/test/ut_uniform_reference.hpp b/src/rng/test/ut_uniform_reference.hpp index d53d959ed6..6700bffd75 100644 --- a/src/rng/test/ut_uniform_reference.hpp +++ b/src/rng/test/ut_uniform_reference.hpp @@ -1,19 +1,37 @@ -RefHist("u01 Threefry4x32 float", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01 Threefry4x32 double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01 Threefry4x32 long double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01 Threefry4x64 float", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); -RefHist("u01 Threefry4x64 double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); -RefHist("u01 Threefry4x64 long double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); -RefHist("uneg11 Threefry4x32 float", " 156 139 148 146 159 148 159 168 142 160 156 161 153 143 158 150 180 174 152 163 157 129 166 151 140 142"); -RefHist("uneg11 Threefry4x32 double", " 156 139 148 146 159 148 159 168 142 160 156 161 153 143 158 150 180 174 152 163 157 129 166 151 140 142"); -RefHist("uneg11 Threefry4x32 long double", " 156 139 148 146 159 148 159 168 142 160 156 161 153 143 158 150 180 174 152 163 157 129 166 151 140 142"); -RefHist("uneg11 Threefry4x64 float", " 159 141 148 184 162 142 155 137 173 187 153 140 135 164 144 146 149 151 171 152 148 137 179 146 145 152"); -RefHist("uneg11 Threefry4x64 double", " 159 141 148 184 162 142 155 137 173 187 153 140 135 164 144 146 149 151 171 152 148 137 179 146 145 152"); -RefHist("uneg11 Threefry4x64 long double", " 159 141 148 184 162 142 155 137 173 187 153 140 135 164 144 146 149 151 171 152 148 137 179 146 145 152"); -RefHist("u01fixedpt Threefry4x32 float", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01fixedpt Threefry4x32 double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01fixedpt Threefry4x32 long double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); -RefHist("u01fixedpt Threefry4x64 float", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); -RefHist("u01fixedpt Threefry4x64 double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); -RefHist("u01fixedpt Threefry4x64 long double", " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("u01 Threefry4x32 float", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01 Threefry4x32 double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01 Threefry4x32 long double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01 Threefry4x64 float", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("u01 Threefry4x64 double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("u01 Threefry4x64 long double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("uneg11 Threefry4x32 float", " 156 139 148 146 159 148 159 168 142 160 156 161 153 143 158 " + "150 180 174 152 163 157 129 166 151 140 142"); +RefHist("uneg11 Threefry4x32 double", " 156 139 148 146 159 148 159 168 142 160 156 161 153 143 " + "158 150 180 174 152 163 157 129 166 151 140 142"); +RefHist("uneg11 Threefry4x32 long double", " 156 139 148 146 159 148 159 168 142 160 156 161 153 " + "143 158 150 180 174 152 163 157 129 166 151 140 142"); +RefHist("uneg11 Threefry4x64 float", " 159 141 148 184 162 142 155 137 173 187 153 140 135 164 144 " + "146 149 151 171 152 148 137 179 146 145 152"); +RefHist("uneg11 Threefry4x64 double", " 159 141 148 184 162 142 155 137 173 187 153 140 135 164 " + "144 146 149 151 171 152 148 137 179 146 145 152"); +RefHist("uneg11 Threefry4x64 long double", " 159 141 148 184 162 142 155 137 173 187 153 140 135 " + "164 144 146 149 151 171 152 148 137 179 146 145 152"); +RefHist("u01fixedpt Threefry4x32 float", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01fixedpt Threefry4x32 double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01fixedpt Threefry4x32 long double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 301 330 326 320 295 291 298 287 305 307 310 316 314"); +RefHist("u01fixedpt Threefry4x64 float", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("u01fixedpt Threefry4x64 double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); +RefHist("u01fixedpt Threefry4x64 long double", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 308 295 322 300 316 291 311 289 346 297 310 340 275"); // ./ut_uniform: SUCCESS diff --git a/src/rng/test/util.h b/src/rng/test/util.h index 4273e9c028..060c6bfb69 100644 --- a/src/rng/test/util.h +++ b/src/rng/test/util.h @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------------*/ /* -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 @@ -227,51 +227,49 @@ double hextod(const char *cp) { return d; } -#define CHECKNOTEQUAL(x, y) \ - do { \ - if ((x) != (y)) \ - ; \ - else { \ - fprintf(stderr, "%s: %s line %d error %s == %s (%s)\n", progname, \ - __FILE__, __LINE__, #x, #y, strerror(errno)); \ - exit(1); \ - } \ +#define CHECKNOTEQUAL(x, y) \ + do { \ + if ((x) != (y)) \ + ; \ + else { \ + fprintf(stderr, "%s: %s line %d error %s == %s (%s)\n", progname, __FILE__, __LINE__, #x, \ + #y, strerror(errno)); \ + exit(1); \ + } \ } while (0) -#define CHECKEQUAL(x, y) \ - do { \ - if ((x) == (y)) \ - ; \ - else { \ - fprintf(stderr, "%s: %s line %d error %s != %s (%s)\n", progname, \ - __FILE__, __LINE__, #x, #y, strerror(errno)); \ - exit(1); \ - } \ +#define CHECKEQUAL(x, y) \ + do { \ + if ((x) == (y)) \ + ; \ + else { \ + fprintf(stderr, "%s: %s line %d error %s != %s (%s)\n", progname, __FILE__, __LINE__, #x, \ + #y, strerror(errno)); \ + exit(1); \ + } \ } while (0) #define CHECKZERO(x) CHECKEQUAL((x), 0) #define CHECKNOTZERO(x) CHECKNOTEQUAL((x), 0) -#define dprintf(x) \ - do { \ - if (debug < 1) \ - ; \ - else { \ - printf x; \ - fflush(stdout); \ - } \ +#define dprintf(x) \ + do { \ + if (debug < 1) \ + ; \ + else { \ + printf x; \ + fflush(stdout); \ + } \ } while (0) -#define ALLZEROS(x, K, N) \ - do { \ - int allzeros = 1; \ - unsigned xi, xj; \ - for (xi = 0; xi < (unsigned)(K); xi++) \ - for (xj = 0; xj < (unsigned)(N); xj++) \ - allzeros = allzeros & ((x)[xi].v[xj] == 0); \ - if (allzeros) \ - fprintf(stderr, \ - "%s: Unexpected, all %lu elements of %ux%u had all zeros!\n", \ - progname, (unsigned long)K, (unsigned)N, \ - (unsigned)sizeof(x[0].v[0])); \ +#define ALLZEROS(x, K, N) \ + do { \ + int allzeros = 1; \ + unsigned xi, xj; \ + for (xi = 0; xi < (unsigned)(K); xi++) \ + for (xj = 0; xj < (unsigned)(N); xj++) \ + allzeros = allzeros & ((x)[xi].v[xj] == 0); \ + if (allzeros) \ + fprintf(stderr, "%s: Unexpected, all %lu elements of %ux%u had all zeros!\n", progname, \ + (unsigned long)K, (unsigned)N, (unsigned)sizeof(x[0].v[0])); \ } while (0) /* Read in N words of width W into ARR */ @@ -287,12 +285,9 @@ double hextod(const char *cp) { if (debug > 1) \ printf("line %d: xfmt for W=%d is \"%s\", got ret=%d xj=%d, " \ "%s[%d]=%llx cp=%s", \ - linenum, W, xfmt, ret, xj, #ARR, xi, \ - (unsigned long long)ARR.v[xi], cp); \ + linenum, W, xfmt, ret, xj, #ARR, xi, (unsigned long long)ARR.v[xi], cp); \ if (ret < 1) { \ - fprintf(stderr, \ - "%s: ran out of words reading %s on line %d: " #NAME #N "x" #W \ - " %2d %s", \ + fprintf(stderr, "%s: ran out of words reading %s on line %d: " #NAME #N "x" #W " %2d %s", \ progname, #ARR, linenum, rounds, line); \ errs++; \ return; \ @@ -312,16 +307,16 @@ double hextod(const char *cp) { } \ } while (0) -#define PRINTLINE(NAME, N, W, R, ictr, ukey, octr, fp) \ - do { \ - fprintf(fp, "%s %d ", #NAME #N "x" #W, R); \ - PRINTARRAY(ictr, fp); \ - putc(' ', fp); \ - PRINTARRAY(ukey, fp); \ - putc(' ', fp); \ - PRINTARRAY(octr, fp); \ - putc('\n', fp); \ - fflush(fp); \ +#define PRINTLINE(NAME, N, W, R, ictr, ukey, octr, fp) \ + do { \ + fprintf(fp, "%s %d ", #NAME #N "x" #W, R); \ + PRINTARRAY(ictr, fp); \ + putc(' ', fp); \ + PRINTARRAY(ukey, fp); \ + putc(' ', fp); \ + PRINTARRAY(octr, fp); \ + putc('\n', fp); \ + fflush(fp); \ } while (0) #endif /* UTIL_H */ diff --git a/src/rng/test/util_cpu.h b/src/rng/test/util_cpu.h index 89d62282d7..85f408dc78 100644 --- a/src/rng/test/util_cpu.h +++ b/src/rng/test/util_cpu.h @@ -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 @@ -50,13 +50,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * before reading /proc/cpuinfo, might fool * energy-saving CPU into showing its true speed */ -static void warmupCPU(long n) { +static double warmupCPU(long n) { double d = 0.3; int i; for (i = 0; i < n; i++) { d = 3.6 * d * (1. - d); } dprintf(("logistic map produced %f\n", d)); + return d; } #if defined(_MSC_VER) @@ -99,7 +100,7 @@ static double clockspeedHz(int *ncores, char **modelnamep) { static double clockspeedHz(int *ncores, char **modelnamep) { FILE *fp = popen("sysctl hw.cpufrequency", "r"); double hz = 0.; - warmupCPU(100L * 1000L * 1000L); + double d = warmupCPU(100L * 1000L * 1000L); if (fscanf(fp, "%*s %lf", &hz) != 1) return 0.; pclose(fp); @@ -109,12 +110,11 @@ static double clockspeedHz(int *ncores, char **modelnamep) { *modelnamep = ntcsdup("Apple"); return hz; } -#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) || \ - (defined(__GNUC__) && defined(__sun__)) +#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) || (defined(__GNUC__) && defined(__sun__)) static double clockspeedHz(int *ncores, char **modelnamep) { FILE *fp = popen("kstat -p -s current_clock_Hz", "r"); double hz = 0.; - warmupCPU(100L * 1000L * 1000L); + double d = warmupCPU(100L * 1000L * 1000L); /* To-do: get a model name from kstat too */ if (modelnamep) *modelnamep = ntcsdup("Solaris"); @@ -133,7 +133,7 @@ static double clockspeedHz(int *ncores, char **modelnamep) { double Mhz = 0.; double xMhz; int i; - warmupCPU(100L * 1000L * 1000L); + double d = warmupCPU(100L * 1000L * 1000L); FILE *fp; if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) { if (ncores) @@ -170,7 +170,7 @@ static double clockspeedHz(int *ncores, char **modelnamep) { *ncores += 1; } } - double d = Mhz * 1e6; + d = Mhz * 1e6; dprintf(("clockspeed is %f\n", d)); return d; } @@ -213,8 +213,7 @@ CPUInfo *cpu_init(const char *arg) { CPUInfo *tp; tp = (CPUInfo *)malloc(sizeof(CPUInfo)); tp->hz = clockspeedHz(&tp->ncores, &tp->cpuname); - printf("%d cores, %.3f Ghz, cpu %s\n", tp->ncores, tp->hz * 1e-9, - tp->cpuname); + printf("%d cores, %.3f Ghz, cpu %s\n", tp->ncores, tp->hz * 1e-9, tp->cpuname); if (arg) { int n = atoi(arg); if (n) { diff --git a/src/rng/test/util_cuda.h b/src/rng/test/util_cuda.h index ae87cf45d4..417106918d 100644 --- a/src/rng/test/util_cuda.h +++ b/src/rng/test/util_cuda.h @@ -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 @@ -38,79 +38,114 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // utility macros to check return codes and complain/exit on failure -#define CHECKLAST(MSG) do { cudaError_t e = cudaGetLastError(); if (e != cudaSuccess) {fprintf(stderr, "%s:%d: CUDA Error: %s: %s\n", __FILE__, __LINE__, (MSG), cudaGetErrorString(e)); exit(1); }} while(0) -#define CHECKCALL(RET) do { cudaError_t e = (RET); if (e != cudaSuccess) { fprintf(stderr, "%s:%d: CUDA Error: %s\n", __FILE__, __LINE__, cudaGetErrorString(e)); exit(1); } } while(0) +#define CHECKLAST(MSG) \ + do { \ + cudaError_t e = cudaGetLastError(); \ + if (e != cudaSuccess) { \ + fprintf(stderr, "%s:%d: CUDA Error: %s: %s\n", __FILE__, __LINE__, (MSG), \ + cudaGetErrorString(e)); \ + exit(1); \ + } \ + } while (0) +#define CHECKCALL(RET) \ + do { \ + cudaError_t e = (RET); \ + if (e != cudaSuccess) { \ + fprintf(stderr, "%s:%d: CUDA Error: %s\n", __FILE__, __LINE__, cudaGetErrorString(e)); \ + exit(1); \ + } \ + } while (0) typedef struct cuda_info { - int devnum, cores, blocks_per_grid, threads_per_block; - double cycles; - struct cudaDeviceProp dev; + int devnum, cores, blocks_per_grid, threads_per_block; + double cycles; + struct cudaDeviceProp dev; } CUDAInfo; // If devstr is none, chooses device with most cores. -static CUDAInfo *cuda_init(const char *devstr) -{ - CUDAInfo *tp; - int i, ndev, cores, devcores; - double cycles; - CHECKNOTZERO(tp = (CUDAInfo *) malloc(sizeof(CUDAInfo))); - CHECKCALL( cudaGetDeviceCount(&ndev) ); - devcores = 0; - for (i = 0; i < ndev; i++) { - struct cudaDeviceProp cu; - CHECKCALL( cudaGetDeviceProperties (&cu, i) ); - // Number of cores is not available from a query, have to hardwire - // some knowledge here! - cores = cu.multiProcessorCount; - if (cu.major == 1 && cu.minor >= 0 && cu.minor <= 3) { - // 1.0 (G80, G92, aka GTX880, Tesla [CSD]870) to 1.3 (GT200, aka GTX280, Tesla [CS]10xx) have 8 cores per MP - cores *= 8; - } else if (cu.major == 2 && cu.minor == 0) { - // 2.0 (G100, aka GTX480, Tesla/Fermi [CSM]20[567]0, and GF110, aka GTX580, M2090) - cores *= 32; - } else if (cu.major == 2 && cu.minor == 1) { - // 2.1 (GF104, GF114, GF116 aka GTX [45][56]0) - cores *= 48; - } else if (cu.major == 3 && (cu.minor == 0||cu.minor==5)) { - // 3.0 (Kepler GK104 aka GTX 680) - cores *= 192; - } else { - fprintf(stderr, "Unknown # of cores per MP for this device, assuming 1, so cpb will be wrong\n"); - } - /* clockrate is in KHz */ - cycles = 1e3 * cu.clockRate * cores; - printf(" %d: maj %d min %d %s%s ( %d units @ %g MHz ECC=%d %d cores %g Gcycles/s)\n", - i, cu.major, cu.minor, nameclean(cu.name), cu.integrated ? " integrated" : "", - cu.multiProcessorCount, cu.clockRate*1e-3, cu.ECCEnabled, cores, cycles*1e-9); - if (devstr && strstr(cu.name, devstr) == NULL) { - dprintf(("skipping device %s\n", cu.name)); - continue; - } - if (cores > devcores) { - devcores = cores; - tp->devnum = i; - tp->cores = cores; - tp->cycles = cycles; - tp->dev = cu; - } +static CUDAInfo *cuda_init(const char *devstr) { + CUDAInfo *tp; + int i, ndev, cores, devcores; + double cycles; + CHECKNOTZERO(tp = (CUDAInfo *)malloc(sizeof(CUDAInfo))); + CHECKCALL(cudaGetDeviceCount(&ndev)); + devcores = 0; + if (devstr == NULL) + devstr = getenv("R123EXAMPLE_ENVCONF_CUDA_DEVICE"); + for (i = 0; i < ndev; i++) { + struct cudaDeviceProp cu; + CHECKCALL(cudaGetDeviceProperties(&cu, i)); + // Number of cores is not available from a query, have to hardwire + // some knowledge here, from web articles about the various generations + // SM or SMX, might also find this info in + // CUDA SDK $CUDA_SAMPLES_DIR/common/inc/helper_cuda.h + // or https://github.com/NVIDIA/nvidia-docker/blob/master/tools/src/cuda/cuda.go + cores = cu.multiProcessorCount; + if (cu.major == 1 && cu.minor >= 0 && cu.minor <= 3) { + // 1.0 (G80, G92, aka GTX880, Tesla [CSD]870) to 1.3 (GT200, aka GTX280, Tesla [CS]10xx) have 8 cores per MP + cores *= 8; + } else if (cu.major == 2 && cu.minor == 0) { + // 2.0 (G100, aka GTX480, Tesla/Fermi [CSM]20[567]0, and GF110, aka GTX580, M2090) + cores *= 32; + } else if (cu.major == 2 && cu.minor == 1) { + // 2.1 (GF104, GF114, GF116 aka GTX [45][56]0) + cores *= 48; + } else if (cu.major == 3) { + // 3.0 (Kepler GK104 aka GTX 680), 3.2 (TK1), 3.5 (GK11x, GK20x), 3.7 (GK21x) + cores *= 192; + } else if (cu.major == 5) { + // 5.0 (Maxwell GM10x), 5.2 (GM20x), 5.3 (TX1) + cores *= 128; + } else if (cu.major == 6 && cu.minor == 0) { + // 6.0 (Pascal P100) + cores *= 64; + } else if (cu.major == 6) { + // 6.1 (Pascal 10xx, Titan Xp, P40), 6.2 (Drive PX2 and Tegra) + cores *= 128; + } else if (cu.major == 7) { + // 7.[025] (Volta and Turing RTX 20[678]0, Titan RTX, Quadro RTX) + cores *= 128; + } else { + int coremultguess = 384; + cores *= coremultguess; + fprintf(stderr, + "WARNING: Unknown number of cores per MP for this device: assuming %d, so cpb " + "calculation will be wrong and choice of blocks/grid might be suboptimal\n", + coremultguess); } - if (devcores == 0) { - fprintf(stderr, "could not find specified device\n"); - exit(1); + /* clockrate is in KHz */ + cycles = 1e3 * cu.clockRate * cores; + printf(" %d: maj %d min %d %s%s ( %d units @ %g MHz ECC=%d %d cores %g Gcycles/s)\n", i, + cu.major, cu.minor, nameclean(cu.name), cu.integrated ? " integrated" : "", + cu.multiProcessorCount, cu.clockRate * 1e-3, cu.ECCEnabled, cores, cycles * 1e-9); + if (devstr && strstr(cu.name, devstr) == NULL) { + dprintf(("skipping device %s\n", cu.name)); + continue; } - tp->blocks_per_grid = tp->cores; /* seems like a good guess */ - tp->threads_per_block = tp->dev.warpSize * 2; - dprintf(("Using CUDA device %d, %d cores, %g cycles, will try %d blocks/grid %d threads/block\n", - tp->devnum, tp->cores, tp->cycles, tp->blocks_per_grid, tp->threads_per_block)); - CHECKCALL(cudaSetDevice(tp->devnum)); - dprintf(("cuda_init done\n")); - return tp; + if (cores > devcores) { + devcores = cores; + tp->devnum = i; + tp->cores = cores; + tp->cycles = cycles; + tp->dev = cu; + } + } + if (devcores == 0) { + fprintf(stderr, "could not find specified device\n"); + exit(1); + } + tp->blocks_per_grid = tp->cores; /* seems like a good guess */ + tp->threads_per_block = tp->dev.warpSize * 2; + printf("Using CUDA device %d, %d cores, %g cycles, will try %d blocks/grid %d threads/block\n", + tp->devnum, tp->cores, tp->cycles, tp->blocks_per_grid, tp->threads_per_block); + CHECKCALL(cudaSetDevice(tp->devnum)); + dprintf(("cuda_init done\n")); + return tp; } -static void cuda_done(CUDAInfo *tp) -{ - dprintf(("cuda_done\n")); - free(tp); +static void cuda_done(CUDAInfo *tp) { + dprintf(("cuda_done\n")); + free(tp); } #endif /* UTIL_CUDA_H__ */ diff --git a/src/rng/test/util_demangle.hpp b/src/rng/test/util_demangle.hpp index 0cd2bfded1..63439f22b4 100644 --- a/src/rng/test/util_demangle.hpp +++ b/src/rng/test/util_demangle.hpp @@ -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 @@ -36,39 +36,37 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // all different... #ifdef __GNUC__ - // Clang defines __GNUC__, but clang3.1 with -stdlib=libc++ can't - // find a even though it *can* find the symbols at link - // time. I suspect this is a bug/oversight in the installation - // process (which, in June 2012 is still pretty fluid for libc++), so - // it might be fixed in the future. On the other hand, the API in - // cxxabi.h is locked down pretty tightly, so writing out an explicit - // extern declaration is pretty safe, and avoids a rats nest of - // ifdefs. It is tempting to use clang's __has_include(), - // but it feels like more #ifdefs with no obvious upside. - // - // #include -extern "C"{ - char* - __cxa_demangle(const char* __mangled_name, char* __output_buffer, - size_t* __length, int* __status); +// Clang defines __GNUC__, but clang3.1 with -stdlib=libc++ can't +// find a even though it *can* find the symbols at link +// time. I suspect this is a bug/oversight in the installation +// process (which, in June 2012 is still pretty fluid for libc++), so +// it might be fixed in the future. On the other hand, the API in +// cxxabi.h is locked down pretty tightly, so writing out an explicit +// extern declaration is pretty safe, and avoids a rats nest of +// ifdefs. It is tempting to use clang's __has_include(), +// but it feels like more #ifdefs with no obvious upside. +// +// #include +extern "C" { +char *__cxa_demangle(const char *__mangled_name, char *__output_buffer, size_t *__length, + int *__status); } #endif #include -template -std::string demangle(const T& ignored){ +template std::string demangle(const T &ignored) { #ifdef __GNUC__ - int status; - char *realname = __cxa_demangle(typeid(ignored).name(), 0, 0, &status); - std::string ret; - if(status!=0 || realname==0) - ret = typeid(ignored).name(); - else - ret = realname; - free(realname); - return ret; + int status; + char *realname = __cxa_demangle(typeid(ignored).name(), 0, 0, &status); + std::string ret; + if (status != 0 || realname == 0) + ret = typeid(ignored).name(); + else + ret = realname; + free(realname); + return ret; #else - return typeid(ignored).name(); + return typeid(ignored).name(); #endif } diff --git a/src/rng/test/util_expandtpl.h b/src/rng/test/util_expandtpl.h index ac5af84e9e..71589d72e0 100644 --- a/src/rng/test/util_expandtpl.h +++ b/src/rng/test/util_expandtpl.h @@ -1,40 +1,43 @@ /* -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 modification, -are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: -* Redistributions of source code must retain the above copyright notice, this - list of conditions, and the following disclaimer. +* Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer. -* 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. +* 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. -* Neither the name of D. E. Shaw Research nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. +* Neither the name of D. E. Shaw Research nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR 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. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"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 THE COPYRIGHT +OWNER OR 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. */ #ifndef TEST_TPL #error "TEST_TPL not defined before including util_expandtpl.h" #else /* - * This is included by various files after defining TEST_TPL to expand TEST_TPL - * for each of the RNGs we want to test. TEST_TPL args are the name of the RNG, - * N, W, and R, N being the number of words, W being the wordsize in bits, and R - * being the number of rounds. + * This is included by various files after defining TEST_TPL to + * expand TEST_TPL for each of the RNGs we want to test. + * TEST_TPL args are the name of the RNG, N, W, and R, + * N being the number of words, W being the wordsize in bits, + * and R being the number of rounds. */ #ifdef __GNUC__ @@ -75,13 +78,15 @@ TEST_TPL(philox, 2, 64, 10) TEST_TPL(philox, 4, 64, 7) TEST_TPL(philox, 4, 64, 10) #endif +#if R123_USE_64BIT TEST_TPL(threefry, 2, 64, 13) TEST_TPL(threefry, 2, 64, 20) TEST_TPL(threefry, 4, 64, 12) TEST_TPL(threefry, 4, 64, 20) +TEST_TPL(threefry, 4, 64, 72) +#endif TEST_TPL(threefry, 4, 32, 12) TEST_TPL(threefry, 4, 32, 20) -TEST_TPL(threefry, 4, 64, 72) #if R123_USE_AES_NI TEST_TPL(ars, 4, 32, 5) diff --git a/src/rng/test/util_m128.h b/src/rng/test/util_m128.h index da774a9f79..779a53c3e9 100644 --- a/src/rng/test/util_m128.h +++ b/src/rng/test/util_m128.h @@ -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 @@ -48,13 +48,12 @@ __m128i m128i_from_charbuf(const char *s) { "%02x%02x%02x%02x" "%02x%02x%02x%02x" "%02x%02x%02x%02x", - &bytes[0], &bytes[1], &bytes[2], &bytes[3], &bytes[4], &bytes[5], - &bytes[6], &bytes[7], &bytes[8], &bytes[9], &bytes[10], &bytes[11], - &bytes[12], &bytes[13], &bytes[14], &bytes[15]); - return _mm_set_epi8(bytes[15], bytes[14], bytes[13], bytes[12], bytes[11], - bytes[10], bytes[9], bytes[8], bytes[7], bytes[6], - bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], - bytes[0]); + &bytes[0], &bytes[1], &bytes[2], &bytes[3], &bytes[4], &bytes[5], &bytes[6], &bytes[7], + &bytes[8], &bytes[9], &bytes[10], &bytes[11], &bytes[12], &bytes[13], &bytes[14], + &bytes[15]); + return _mm_set_epi8(bytes[15], bytes[14], bytes[13], bytes[12], bytes[11], bytes[10], bytes[9], + bytes[8], bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], + bytes[1], bytes[0]); } #define M128_STR_SIZE 34 /* minimum size of the charbuf "hex" argument */ @@ -71,10 +70,9 @@ char *m128i_to_charbuf(__m128i m, char *hex) { " " "%02x%02x%02x%02x" "%02x%02x%02x%02x", - u.bytes[0], u.bytes[1], u.bytes[2], u.bytes[3], u.bytes[4], - u.bytes[5], u.bytes[6], u.bytes[7], u.bytes[8], u.bytes[9], - u.bytes[10], u.bytes[11], u.bytes[12], u.bytes[13], u.bytes[14], - u.bytes[15]); + u.bytes[0], u.bytes[1], u.bytes[2], u.bytes[3], u.bytes[4], u.bytes[5], u.bytes[6], + u.bytes[7], u.bytes[8], u.bytes[9], u.bytes[10], u.bytes[11], u.bytes[12], u.bytes[13], + u.bytes[14], u.bytes[15]); return hex; } @@ -82,9 +80,7 @@ char *m128i_to_charbuf(__m128i m, char *hex) { #ifdef __cplusplus #include -__m128i m128i_from_string(const std::string &s) { - return m128i_from_charbuf(s.c_str()); -} +__m128i m128i_from_string(const std::string &s) { return m128i_from_charbuf(s.c_str()); } std::string m128i_to_string(__m128i m) { char hex[M128_STR_SIZE]; diff --git a/src/rng/test/util_print.h b/src/rng/test/util_print.h index b744a807ba..e59590c958 100644 --- a/src/rng/test/util_print.h +++ b/src/rng/test/util_print.h @@ -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 @@ -36,22 +36,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extern int verbose; -#define TEST_TPL(NAME, N, W, R) \ -void printline_##NAME##N##x##W##_##R(NAME##N##x##W##_ukey_t ukey, NAME##N##x##W##_ctr_t ictr, NAME##N##x##W##_ctr_t *octrs, size_t nctr) \ -{ \ - size_t i; \ - for (i = 0; i < nctr; i++) { \ - if (i > 0) { \ - printf(" [%lu]", (unsigned long)i); \ - PRINTARRAY(octrs[i], stdout); \ - putc('\n', stdout); \ - fflush(stdout); \ - } else { \ - PRINTLINE(NAME, N, W, R, ictr, ukey, octrs[0], stdout); \ - } \ - if (verbose < 2) break; \ - } \ -} +#define TEST_TPL(NAME, N, W, R) \ + void printline_##NAME##N##x##W##_##R(NAME##N##x##W##_ukey_t ukey, NAME##N##x##W##_ctr_t ictr, \ + NAME##N##x##W##_ctr_t *octrs, size_t nctr) { \ + size_t i; \ + for (i = 0; i < nctr; i++) { \ + if (i > 0) { \ + printf(" [%lu]", (unsigned long)i); \ + PRINTARRAY(octrs[i], stdout); \ + putc('\n', stdout); \ + fflush(stdout); \ + } else { \ + PRINTLINE(NAME, N, W, R, ictr, ukey, octrs[0], stdout); \ + } \ + if (verbose < 2) \ + break; \ + } \ + } #include "util_expandtpl.h" From 9818e974806c88879b2ca206abc54f6ca3b1ca9b Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Sun, 4 Oct 2020 12:52:22 -0600 Subject: [PATCH 6/8] fix linter --- .github/workflows/linter.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6381b6c6bb..89f1ac1171 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -59,7 +59,6 @@ jobs: VALIDATE_ENV: true VALIDATE_HTML: true VALIDATE_JSON: true - VALIDATE_JSON: true VALIDATE_LATEX: true VALIDATE_LUA: true VALIDATE_PERL: true From 75df166d848d2b036be93e7fe9069ae16aa395e5 Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Sun, 4 Oct 2020 15:09:16 -0600 Subject: [PATCH 7/8] MSVC fixes --- src/rng/test/kat_main.h | 2 +- src/rng/test/ut_carray.hh | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/rng/test/kat_main.h b/src/rng/test/kat_main.h index e49c2e5ed2..de809cb348 100644 --- a/src/rng/test/kat_main.h +++ b/src/rng/test/kat_main.h @@ -309,7 +309,7 @@ int main(int argc, char **argv) { analyze_tests(tests, t); free(tests); if (nfailed != 0) { - printf("FAILED %lu out of %u\n", nfailed, t); + printf("FAILED %lu out of %u\n", (unsigned long)nfailed, t); return 1; } else { printf("PASSED %u known answer tests\n", t); diff --git a/src/rng/test/ut_carray.hh b/src/rng/test/ut_carray.hh index 7809dc7ffe..5bfc510295 100644 --- a/src/rng/test/ut_carray.hh +++ b/src/rng/test/ut_carray.hh @@ -3,10 +3,7 @@ * \file rng/test/ut_carray.hh * \author Gabriel M. Rockefeller * \brief ut_carray header file. - * \note Copyright (C) 2016-2020 Triad National Security, LLC - */ -//------------------------------------------------------------------------------------------------// - + * \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */ //------------------------------------------------------------------------------------------------// #ifndef rng_test_ut_carray_hh @@ -16,10 +13,20 @@ #pragma GCC system_header #endif +#ifdef _MSC_FULL_VER +// - 4127: conditional expression is constant +#pragma warning(push) +#pragma warning(disable : 4127) +#endif + #include +#ifdef _MSC_FULL_VER +#pragma warning(pop) +#endif + #endif // rng_test_ut_carray_hh //------------------------------------------------------------------------------------------------// -// end of rng/test/ut_carray.hh +// End of rng/test/ut_carray.hh //------------------------------------------------------------------------------------------------// From 80007f9dd692fd2cabaef57aa3b13e1bcab640dd Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Sun, 4 Oct 2020 17:29:12 -0600 Subject: [PATCH 8/8] Fix msvc warning. --- src/rng/test/time_serial.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/rng/test/time_serial.c b/src/rng/test/time_serial.c index e7d1dbea1f..5ade89b9ef 100644 --- a/src/rng/test/time_serial.c +++ b/src/rng/test/time_serial.c @@ -37,10 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "util.h" -#include "Random123/aes.h" -#include "Random123/ars.h" -#include "Random123/philox.h" -#include "Random123/threefry.h" +#include "time_serial.h" #include "time_misc.h" #include "util_print.h"