├── src ├── tests │ ├── philox432_ut.c │ ├── ctest │ │ ├── mrg31k3p_dispatch.c │ │ ├── mrg32k3a_dispatch.c │ │ ├── philox432_dispatch.c │ │ ├── lfsr113_dispatch.c │ │ ├── lfsr113_checks_s.c │ │ ├── mrg31k3p_checks_s.c │ │ ├── mrg32k3a_checks_s.c │ │ ├── philox432_checks_s.c │ │ ├── lfsr113_common.c │ │ ├── util.h │ │ ├── philox432_common.c │ │ ├── mrg31k3p_common.c │ │ ├── mrg32k3a_common.c │ │ ├── checks.h │ │ ├── dispatch.c.h │ │ ├── philox432_checks_d.c │ │ ├── lfsr113_checks_d.c │ │ ├── util.c │ │ ├── cli.c │ │ ├── mrg31k3p_checks_d.c │ │ ├── mrg32k3a_checks_d.c │ │ └── mangle.h │ └── CMakeLists.txt ├── library │ ├── clRNG.pc.in │ ├── clRNGConfig.cmake.in │ ├── private.h │ ├── private.c │ ├── clRNG.c │ ├── modularHost.c.h │ └── CMakeLists.txt ├── include │ └── clRNG │ │ ├── clRNG.version.h.in │ │ ├── private │ │ ├── Random123 │ │ │ └── features │ │ │ │ ├── open64features.h │ │ │ │ ├── clangfeatures.h │ │ │ │ ├── openclfeatures.h │ │ │ │ ├── msvcfeatures.h │ │ │ │ └── gccfeatures.h │ │ └── modular.c.h │ │ ├── clRNG.clh │ │ ├── lfsr113.clh │ │ ├── philox432.clh │ │ ├── mrg32k3a.clh │ │ └── mrg31k3p.clh ├── client │ ├── WorkItem │ │ ├── workitem_kernel.cl │ │ └── workitem.c │ ├── Inventory │ │ ├── Policies.h │ │ ├── SimulateRuns.h │ │ ├── Types.h │ │ ├── inventory.c │ │ └── InventoryKernels.cl │ ├── HostOnly │ │ └── hostonly.c │ ├── CMakeLists.txt │ ├── anyrng.h │ ├── common.h │ └── RandomArray │ │ └── randomarray.c └── FindOpenCL.cmake ├── NOTICE ├── CHANGELOG ├── .gitignore ├── docs ├── Makefile └── clRNG.bib ├── ReleaseNotes.txt └── LICENSE /src/tests/philox432_ut.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clMathLibraries/clRNG/HEAD/src/tests/philox432_ut.c -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | AMD clRNG 2 | Copyright (c) 2015 Advanced Micro Devices, Inc. 3 | 4 | This product includes software developed at 5 | Advanced Micro Devices, Inc. (http://www.amd.com). 6 | 7 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | Name: clRNG 3 | Version: 1.0 Beta 4 | Release Date: April 2015 5 | 6 | ChangeLog: 7 | 8 | ____________ 9 | Current Version: 10 | * This is the initial beta release of clRNG 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | Debug 3 | Release 4 | x64 5 | *.opensdf 6 | 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | 12 | # Compiled Dynamic libraries 13 | *.so 14 | *.dylib 15 | 16 | # Compiled Static libraries 17 | *.lai 18 | *.la 19 | *.a 20 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all html latex install clean 2 | 3 | 4 | all: html latex 5 | 6 | html: 7 | doxygen clRNG.doxy 8 | 9 | latex: 10 | $(MAKE) -C out/latex 11 | 12 | install: html latex 13 | mkdir -p "$(PREFIX)/doc" 14 | install -d out/html "$(PREFIX)/doc" 15 | install --mode=0644 out/latex/refman.pdf "$(PREFIX)/doc" 16 | 17 | clean: 18 | rm -rf out/html out/latex 19 | -------------------------------------------------------------------------------- /src/library/clRNG.pc.in: -------------------------------------------------------------------------------- 1 | 2 | prefix=@CMAKE_INSTALL_PREFIX@ 3 | exec_prefix=${prefix}/bin@SUFFIX_BIN@ 4 | includedir=${prefix}/include 5 | libdir=${prefix}/lib@SUFFIX_LIB@ 6 | 7 | Name: clRNG 8 | Description: Open source OpenCL RNG Streams library 9 | Version: @CLFFT_VERSION@ 10 | URL: https://github.com/clMathLibraries/clRNG 11 | 12 | Cflags: -I${includedir} 13 | Libs: -L${libdir} -lclFFT 14 | -------------------------------------------------------------------------------- /ReleaseNotes.txt: -------------------------------------------------------------------------------- 1 | 2 | clRNG Contents 3 | -------------- 4 | 5 | clRNG is a library for uniform random number generation in OpenCL. 6 | 7 | Streams of random numbers act as virtual random number generators. 8 | They can be created on the host computer in unlimited numbers, and 9 | then used either on the host or on computing devices by work items 10 | to generate random numbers. Each stream also has equally-spaced 11 | substreams, which are occasionally useful. 12 | 13 | 14 | clRNG - Release Notes - version 1.0.0 beta 15 | ------------------------------------------ 16 | 17 | The is the first public version of clRNG. 18 | 19 | * The API is currently implemented for four base RNGs, namely 20 | the MRG31k3p, MRG32k3a, LFSR113 and Philox-4×32-10 generators. 21 | 22 | Driver notes: 23 | 24 | * This library version has been tested with Catalyst 25 | Pro driver version 14.301 on Firepro W9100. 26 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg31k3p_dispatch.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg31k3p 34 | #define CTEST_RNG_HEADER mrg31k3p 35 | #include "dispatch.c.h" 36 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg32k3a_dispatch.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg32k3a 34 | #define CTEST_RNG_HEADER mrg32k3a 35 | #include "dispatch.c.h" 36 | -------------------------------------------------------------------------------- /src/tests/ctest/philox432_dispatch.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Philox432 34 | #define CTEST_RNG_HEADER philox432 35 | #include "dispatch.c.h" 36 | -------------------------------------------------------------------------------- /src/tests/ctest/lfsr113_dispatch.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Lfsr113 34 | #define CTEST_RNG_HEADER lfsr113 35 | #define CTEST_NO_ADVANCE 36 | #include "dispatch.c.h" 37 | -------------------------------------------------------------------------------- /src/library/clRNGConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # ######################################################################## 2 | # Copyright 2015 Advanced Micro Devices, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ######################################################################## 16 | 17 | # Configure the clRNG package to be used in another cmake project. 18 | # 19 | # Defines the following variables: 20 | # 21 | # clRNG_INCLUDE_DIRS - include directories for clRNG 22 | # 23 | # Also defines the library variables below as normal 24 | # variables. These contain debug/optimized keywords when 25 | # a debugging library is found. 26 | # 27 | # Accepts the following variables as input: 28 | # 29 | #----------------------- 30 | # Example Usage: 31 | # 32 | # find_package( clRNG REQUIRED CONFIG 33 | # HINTS /package ) 34 | # 35 | # add_executable( foo foo.cc ) 36 | 37 | # # uses imported targets from package, including setting header paths 38 | # target_link_libraries( foo clRNG ) 39 | # 40 | #----------------------- 41 | 42 | @PACKAGE_INIT@ 43 | 44 | set_and_check( clRNG_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@" ) 45 | set_and_check( clRNG_INCLUDE_DIRS "${clRNG_INCLUDE_DIR}" ) 46 | set_and_check( clRNG_LIB_INSTALL_DIR "@PACKAGE_LIB_INSTALL_DIR@" ) 47 | 48 | include( "${CMAKE_CURRENT_LIST_DIR}/clRNG-Targets.cmake" ) 49 | 50 | -------------------------------------------------------------------------------- /src/include/clRNG/clRNG.version.h.in: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | 34 | 35 | 36 | /* the configured version and settings for clRNG 37 | */ 38 | #define clrngVersionMajor @CLRNG_VERSION_MAJOR@ 39 | #define clrngVersionMinor @CLRNG_VERSION_MINOR@ 40 | #define clrngVersionPatch @CLRNG_VERSION_PATCH@ 41 | -------------------------------------------------------------------------------- /src/tests/ctest/lfsr113_checks_s.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CLRNG_SINGLE_PRECISION 34 | #define CTEST_RNG_TYPE Lfsr113 35 | #define CTEST_RNG_HEADER lfsr113 36 | #include "mangle.h" 37 | 38 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 39.0364952087402343f; 39 | 40 | #include "checks_prec.c.h" 41 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg31k3p_checks_s.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CLRNG_SINGLE_PRECISION 34 | #define CTEST_RNG_TYPE Mrg31k3p 35 | #define CTEST_RNG_HEADER mrg31k3p 36 | #include "mangle.h" 37 | 38 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 40.0170440673828125f; 39 | 40 | #include "checks_prec.c.h" 41 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg32k3a_checks_s.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CLRNG_SINGLE_PRECISION 34 | #define CTEST_RNG_TYPE Mrg32k3a 35 | #define CTEST_RNG_HEADER mrg32k3a 36 | #include "mangle.h" 37 | 38 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 39.6731758117675781f; 39 | 40 | #include "checks_prec.c.h" 41 | -------------------------------------------------------------------------------- /src/tests/ctest/philox432_checks_s.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CLRNG_SINGLE_PRECISION 34 | #define CTEST_RNG_TYPE Philox432 35 | #define CTEST_RNG_HEADER philox432 36 | #include "mangle.h" 37 | 38 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 38.672428131103515625f; 39 | 40 | #include "checks_prec.c.h" 41 | -------------------------------------------------------------------------------- /src/library/private.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #pragma once 34 | #ifndef PRIVATE_H 35 | #define PRIVATE_H 36 | 37 | 38 | /*! @brief Set the current error string 39 | * 40 | * The error string will be constructed based on the error code \c err and on 41 | * the optional message \c msg. 42 | * 43 | * @param[in] err Error code. 44 | * @param[in] msg Additional error message (format string). Can be `NULL`. 45 | * @param[in] ... Additional arguments for the format string. 46 | * @return The value of err (for convenience). 47 | */ 48 | clrngStatus clrngSetErrorString(cl_int err, const char* msg, ...); 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/include/clRNG/private/Random123/features/open64features.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010-2011, D. E. Shaw Research. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions, and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions, and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of D. E. Shaw Research nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef __open64features_dot_hpp 33 | #define __open64features_dot_hpp 34 | 35 | /* The gcc features are mostly right. We just override a few and then include gccfeatures.h */ 36 | 37 | /* Open64 4.2.3 and 4.2.4 accept the __uint128_t code without complaint 38 | but produce incorrect code for 64-bit philox. The MULHILO64_ASM 39 | seems to work fine */ 40 | #ifndef R123_USE_GNU_UINT128 41 | #define R123_USE_GNU_UINT128 0 42 | #endif 43 | 44 | #ifndef R123_USE_MULHILO64_ASM 45 | #define R123_USE_MULHILO64_ASM 1 46 | #endif 47 | 48 | #include "gccfeatures.h" 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/tests/ctest/lfsr113_common.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Lfsr113 34 | #define CTEST_RNG_HEADER lfsr113 35 | #include "mangle.h" 36 | 37 | void CTEST_MANGLE(writeState)(FILE* file, const clrngStreamState* state) 38 | { 39 | fprintf(file, "[ "); 40 | for (size_t i = 0; i < 4; i++) { 41 | if (i > 0) fprintf(file, ", "); 42 | fprintf(file, "%12u", state->g[i]); 43 | } 44 | fprintf(file, " ]\n"); 45 | } 46 | 47 | cl_long CTEST_MANGLE(compareState)(const clrngStreamState* state1, const clrngStreamState* state2) 48 | { 49 | for (size_t i = 0; i < 4; i++) { 50 | cl_int diff = state1->g[i] - state2->g[i]; 51 | if (diff) 52 | return diff; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /src/client/WorkItem/workitem_kernel.cl: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /* optional definitions 34 | #define CLRNG_SINGLE_PRECISION 35 | #define CLRNG_ENABLE_SUBSTREAMS 36 | */ 37 | 38 | /*! [clRNG header] */ 39 | #include 40 | /*! [clRNG header] */ 41 | 42 | /*! [kernel] */ 43 | __kernel void example(__global clrngMrg31k3pHostStream* streams, __global float* out) { 44 | int gid = get_global_id(0); 45 | clrngMrg31k3pStream private_stream_d; // This is not a pointer! 46 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &private_stream_d, &streams[gid]); 47 | out[gid] = clrngMrg31k3pRandomU01(&private_stream_d) + 48 | clrngMrg31k3pRandomU01(&private_stream_d); 49 | } 50 | /*! [kernel] */ 51 | -------------------------------------------------------------------------------- /src/client/Inventory/Policies.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef POLICIES_SS_H 34 | #define POLICIES_SS_H 35 | 36 | #include "Types.h" 37 | #include "../common.h" 38 | 39 | typedef struct OnePolicyData_ { 40 | int n; 41 | int n1; 42 | int m; 43 | int s; 44 | int S; 45 | ExecType execType; 46 | simResult * SimResults; 47 | } OnePolicyData; 48 | 49 | typedef struct SeveralPoliciesData_ { 50 | int n; 51 | int n1; 52 | int m; 53 | int* s; 54 | int* S; 55 | int P; 56 | ExecOption optionType; 57 | simResult * SimResults; 58 | } SeveralPoliciesData; 59 | 60 | int one_Policy(cl_context context, cl_device_id device, cl_command_queue queue, void* data_); 61 | int several_Policies(cl_context context, cl_device_id device, cl_command_queue queue, void* data_); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/client/Inventory/SimulateRuns.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef SIMULATERUNS_SS_H 34 | #define SIMULATERUNS_SS_H 35 | 36 | #include 37 | #include "../common.h" 38 | 39 | //Device Simulation 40 | clrngStatus inventorySimulateRunsGPU(cl_context context, cl_device_id device, cl_command_queue queue, int m, int* s, int* S, int P, int n, int n1, int n2, ExecOption Option, const char * kernelName, size_t streamsBufSize, clrngMrg31k3pStream * streams_demand, clrngMrg31k3pStream * streams_order, double *stat, simResult * results); 41 | 42 | //CPU Simulation 43 | clrngStatus inventorySimulateRunsCPU(int m, int s, int S, int n, clrngMrg31k3pStream* streams_demand, clrngMrg31k3pStream* streams_order, double *stat_profit, ExecType execType, simResult * results); 44 | 45 | 46 | 47 | #endif -------------------------------------------------------------------------------- /src/client/Inventory/Types.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef INVENTORY_TYPES_SS_H 34 | #define INVENTORY_TYPES_SS_H 35 | 36 | typedef enum ExecType_ { 37 | basic = 1, 38 | Case_a = 2, //Simulate n runs on n workitems using two streams and their substreams 39 | Case_b = 3, //Simulate n runs on n workitems using n distinct streams 40 | Case_c = 4, //Simulate n2 runs on n1 workitmes using 2n1 streams and their substreams 41 | Case_d = 5 //Simulate n2 runs on n1 workitems using 2n2 streams 42 | } ExecType; 43 | 44 | typedef enum ExecOption_ { 45 | OnePolicy = 0, 46 | Option1 = 1, // Simulate n = n1.n2 runs for p policies, with n1 work items and n2 runs per work item 47 | Option2 = 2 // Simulate n = n1.n2 runs for p policies, with n1p work items and n2 runs per work item, 48 | } ExecOption; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/client/HostOnly/hostonly.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #include 34 | 35 | /*! [clRNG header] */ 36 | #include 37 | /*! [clRNG header] */ 38 | 39 | int main() { 40 | /*! [create streams] */ 41 | clrngMrg31k3pStream* streams = clrngMrg31k3pCreateStreams(NULL, 2, NULL, NULL); 42 | clrngMrg31k3pStream* single = clrngMrg31k3pCreateStreams(NULL, 1, NULL, NULL); 43 | /*! [create streams] */ 44 | /*! [iterate streams] */ 45 | int count = 0; 46 | for (int i = 0; i < 100; i++) { 47 | double u = clrngMrg31k3pRandomU01(&streams[i % 2]); 48 | int x = clrngMrg31k3pRandomInteger(single, 1, 6); 49 | if (x * u < 2) count++; 50 | } 51 | /*! [iterate streams] */ 52 | /*! [output] */ 53 | printf("Average of indicators = %f\n", (double)count / 100.0); 54 | /*! [output] */ 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/tests/ctest/util.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef CTEST_UTIL_H 34 | #define CTEST_UTIL_H 35 | 36 | #include 37 | 38 | #ifdef __APPLE__ 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | 45 | 46 | // globals 47 | extern int ctestVerbose; 48 | 49 | typedef struct DeviceSelect_ { 50 | size_t platform_index; 51 | cl_device_type device_type; 52 | size_t device_index; 53 | } DeviceSelect; 54 | 55 | const DeviceSelect* parse_device_select(size_t nargs, const long* args); 56 | 57 | void write_array_cl_float (FILE* file, size_t num_cols, const char* format, size_t array_size, const cl_float* array); 58 | void write_array_cl_double(FILE* file, size_t num_cols, const char* format, size_t array_size, const cl_double* array); 59 | 60 | char *portable_basename(char *path); 61 | 62 | int clinfo(const DeviceSelect* dev); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/tests/ctest/philox432_common.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Philox432 34 | #define CTEST_RNG_HEADER philox432 35 | #include "mangle.h" 36 | 37 | void CTEST_MANGLE(writeState)(FILE* file, const clrngStreamState* state) 38 | { 39 | fprintf(file, "[ %u, %u, %u, %u ; [%u] ]\n", 40 | state->ctr.H.msb, 41 | state->ctr.H.lsb, 42 | state->ctr.L.msb, 43 | state->ctr.L.lsb, 44 | state->deckIndex); 45 | } 46 | 47 | cl_long CTEST_MANGLE(compareState)(const clrngStreamState* state1, const clrngStreamState* state2) 48 | { 49 | cl_long ret; 50 | ret = state1->ctr.H.msb - state2->ctr.H.msb; 51 | if (ret) return ret; 52 | ret = state1->ctr.H.lsb - state2->ctr.H.lsb; 53 | if (ret) return ret; 54 | ret = state1->ctr.L.msb - state2->ctr.L.msb; 55 | if (ret) return ret; 56 | ret = state1->ctr.L.lsb - state2->ctr.L.lsb; 57 | if (ret) return ret; 58 | ret = state1->deckIndex - state2->deckIndex; 59 | return ret; 60 | } 61 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg31k3p_common.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg31k3p 34 | #define CTEST_RNG_HEADER mrg31k3p 35 | #include "mangle.h" 36 | 37 | void CTEST_MANGLE(writeState)(FILE* file, const clrngStreamState* state) 38 | { 39 | fprintf(file, "[ "); 40 | for (size_t i = 0; i < 3; i++) { 41 | if (i > 0) fprintf(file, ", "); 42 | fprintf(file, "%12d", state->g1[i]); 43 | } 44 | for (size_t i = 0; i < 3; i++) { 45 | fprintf(file, ", "); 46 | fprintf(file, "%12d", state->g2[i]); 47 | } 48 | fprintf(file, " ]\n"); 49 | } 50 | 51 | cl_long CTEST_MANGLE(compareState)(const clrngStreamState* state1, const clrngStreamState* state2) 52 | { 53 | for (size_t i = 0; i < 3; i++) { 54 | cl_int diff = state1->g1[i] - state2->g1[i]; 55 | if (diff) 56 | return diff; 57 | } 58 | for (size_t i = 0; i < 3; i++) { 59 | cl_int diff = state1->g2[i] - state2->g2[i]; 60 | if (diff) 61 | return diff; 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg32k3a_common.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg32k3a 34 | #define CTEST_RNG_HEADER mrg32k3a 35 | #include "mangle.h" 36 | 37 | void CTEST_MANGLE(writeState)(FILE* file, const clrngStreamState* state) 38 | { 39 | fprintf(file, "[ "); 40 | for (size_t i = 0; i < 3; i++) { 41 | if (i > 0) fprintf(file, ", "); 42 | fprintf(file, "%12lu", state->g1[i]); 43 | } 44 | for (size_t i = 0; i < 3; i++) { 45 | fprintf(file, ", "); 46 | fprintf(file, "%12lu", state->g2[i]); 47 | } 48 | fprintf(file, " ]\n"); 49 | } 50 | 51 | cl_long CTEST_MANGLE(compareState)(const clrngStreamState* state1, const clrngStreamState* state2) 52 | { 53 | for (size_t i = 0; i < 3; i++) { 54 | cl_long diff = state1->g1[i] - state2->g1[i]; 55 | if (diff) 56 | return diff; 57 | } 58 | for (size_t i = 0; i < 3; i++) { 59 | cl_long diff = state1->g2[i] - state2->g2[i]; 60 | if (diff) 61 | return diff; 62 | } 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/tests/ctest/checks.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef CTEST_ACTIONS_H 34 | #define CTEST_ACTIONS_H 35 | 36 | #include "mangle.h" 37 | #include "util.h" 38 | 39 | int CTEST_MANGLE(checkSuccessiveStates)(); 40 | //int CTEST_MANGLE_PREC(checkRandomU01,float)(); 41 | int CTEST_MANGLE_PREC(checkRandomU01,double)(); 42 | int CTEST_MANGLE_PREC(checkRandomInteger,double)(); 43 | int CTEST_MANGLE(checkCreateStreams)(); 44 | int CTEST_MANGLE(checkRewindStreamCreator)(); 45 | int CTEST_MANGLE(checkChangeStreamsSpacing)(); 46 | int CTEST_MANGLE(checkAdvanceStreams)(); 47 | int CTEST_MANGLE(checkRewindStreams)(); 48 | int CTEST_MANGLE(checkForwardToNextSubstreams)(); 49 | int CTEST_MANGLE(checkMakeSubstreams)(); 50 | int CTEST_MANGLE_PREC(checkCombinedOperations,float)(); 51 | int CTEST_MANGLE_PREC(checkCombinedOperations,double)(); 52 | int CTEST_MANGLE_PREC(checkDeviceOperations,float)(const DeviceSelect*); 53 | int CTEST_MANGLE_PREC(checkDeviceOperations,double)(const DeviceSelect*); 54 | int CTEST_MANGLE_PREC(checkDeviceRandomArray,float)(const DeviceSelect*); 55 | int CTEST_MANGLE_PREC(checkDeviceRandomArray,double)(const DeviceSelect*); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/include/clRNG/private/Random123/features/clangfeatures.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010-2011, D. E. Shaw Research. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions, and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions, and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of D. E. Shaw Research nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef __clangfeatures_dot_hpp 33 | #define __clangfeatures_dot_hpp 34 | 35 | #ifndef R123_USE_X86INTRIN_H 36 | #define R123_USE_X86INTRIN_H ((defined(__x86_64__)||defined(__i386__))) 37 | #endif 38 | 39 | #ifndef R123_USE_CXX11_UNRESTRICTED_UNIONS 40 | #define R123_USE_CXX11_UNRESTRICTED_UNIONS __has_feature(cxx_unrestricted_unions) 41 | #endif 42 | 43 | #ifndef R123_USE_CXX11_STATIC_ASSERT 44 | #define R123_USE_CXX11_STATIC_ASSERT __has_feature(cxx_static_assert) 45 | #endif 46 | 47 | #ifndef R123_USE_CXX11_CONSTEXPR 48 | #define R123_USE_CXX11_CONSTEXPR __has_feature(cxx_constexpr) 49 | #endif 50 | 51 | #ifndef R123_USE_CXX11_EXPLICIT_CONVERSIONS 52 | #define R123_USE_CXX11_EXPLICIT_CONVERSIONS __has_feature(cxx_explicit_conversions) 53 | #endif 54 | 55 | // With clang-3.0, the apparently simpler: 56 | // #define R123_USE_CXX11_RANDOM __has_include() 57 | // dumps core. 58 | #ifndef R123_USE_CXX11_RANDOM 59 | #if __cplusplus>=201103L && __has_include() 60 | #define R123_USE_CXX11_RANDOM 1 61 | #else 62 | #define R123_USE_CXX11_RANDOM 0 63 | #endif 64 | #endif 65 | 66 | #ifndef R123_USE_CXX11_TYPE_TRAITS 67 | #if __cplusplus>=201103L && __has_include() 68 | #define R123_USE_CXX11_TYPE_TRAITS 1 69 | #else 70 | #define R123_USE_CXX11_TYPE_TRAITS 0 71 | #endif 72 | #endif 73 | 74 | #include "gccfeatures.h" 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/include/clRNG/clRNG.clh: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file clRNG.clh 34 | * @brief Common definitions for the device-side API of clRNG 35 | * 36 | * The definitions defined in this file are not documented here. Refer to the 37 | * documentation of clRNG.h. 38 | */ 39 | 40 | #pragma once 41 | #ifndef CLRNG_CLH 42 | #define CLRNG_CLH 43 | 44 | #ifndef __OPENCL_C_VERSION__ 45 | #error "clRNG.clh can be included in device code only" 46 | #endif 47 | 48 | #define __CLRNG_DEVICE_API 49 | 50 | #ifdef CLRNG_SINGLE_PRECISION 51 | #define _CLRNG_FPTYPE cl_float 52 | #else 53 | #define _CLRNG_FPTYPE cl_double 54 | #pragma OPENCL EXTENSION cl_amd_fp64 : enable 55 | #endif 56 | 57 | typedef double cl_double; 58 | typedef float cl_float; 59 | typedef int cl_int; 60 | typedef uint cl_uint; 61 | typedef long cl_long; 62 | typedef ulong cl_ulong; 63 | 64 | 65 | #define _CLRNG_TAG_FPTYPE(name) _CLRNG_TAG_FPTYPE_(name,_CLRNG_FPTYPE) 66 | #define _CLRNG_TAG_FPTYPE_(name,fptype) _CLRNG_TAG_FPTYPE__(name,fptype) 67 | #define _CLRNG_TAG_FPTYPE__(name,fptype) name##_##fptype 68 | 69 | 70 | 71 | typedef enum clrngStatus_ { 72 | CLRNG_SUCCESS = 0, 73 | CLRNG_INVALID_VALUE = -1 74 | } clrngStatus; 75 | 76 | /*! This macro does nothing. 77 | * It is defined for convenience when adapting host code for the device. 78 | */ 79 | #define clrngSetErrorString(err, ...) (err) 80 | 81 | 82 | #endif 83 | 84 | /* 85 | vim: ft=c sw=4 86 | */ 87 | -------------------------------------------------------------------------------- /src/include/clRNG/private/Random123/features/openclfeatures.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010-2011, D. E. Shaw Research. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions, and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions, and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of D. E. Shaw Research nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef __openclfeatures_dot_hpp 33 | #define __openclfeatures_dot_hpp 34 | 35 | #ifndef R123_STATIC_INLINE 36 | #define R123_STATIC_INLINE inline 37 | #endif 38 | 39 | #ifndef R123_FORCE_INLINE 40 | #define R123_FORCE_INLINE(decl) decl __attribute__((always_inline)) 41 | #endif 42 | 43 | #ifndef R123_CUDA_DEVICE 44 | #define R123_CUDA_DEVICE 45 | #endif 46 | 47 | #ifndef R123_ASSERT 48 | #define R123_ASSERT(x) 49 | #endif 50 | 51 | #ifndef R123_BUILTIN_EXPECT 52 | #define R123_BUILTIN_EXPECT(expr,likely) expr 53 | #endif 54 | 55 | #ifndef R123_USE_GNU_UINT128 56 | #define R123_USE_GNU_UINT128 0 57 | #endif 58 | 59 | #ifndef R123_USE_MULHILO64_ASM 60 | #define R123_USE_MULHILO64_ASM 0 61 | #endif 62 | 63 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 64 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 65 | #endif 66 | 67 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 68 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 69 | #endif 70 | 71 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 72 | #define R123_USE_MULHILO64_OPENCL_INTRIN 1 73 | #endif 74 | 75 | #ifndef R123_USE_AES_NI 76 | #define R123_USE_AES_NI 0 77 | #endif 78 | 79 | // XXX ATI APP SDK 2.4 clBuildProgram SEGVs if one uses uint64_t instead of 80 | // ulong to mul_hi. And gets lots of complaints from stdint.h 81 | // on some machines. 82 | // But these typedefs mean we cannot include stdint.h with 83 | // these headers? Do we need R123_64T, R123_32T, R123_8T? 84 | typedef ulong uint64_t; 85 | typedef uint uint32_t; 86 | typedef uchar uint8_t; 87 | #define UINT64_C(x) ((ulong)(x##UL)) 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /src/library/private.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /* @file private.c 34 | * @brief Implementation of functions defined in clRNG.h and private.h 35 | */ 36 | #include 37 | #include "private.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #define CASE_ERR_(code,msg) case code: base = msg; break 44 | #define CASE_ERR(code) CASE_ERR_(CLRNG_ ## code, MSG_ ## code) 45 | 46 | char errorString[1024] = ""; 47 | 48 | static const char MSG_DEFAULT[] = "unknown status"; 49 | static const char MSG_SUCCESS[] = "success"; 50 | static const char MSG_OUT_OF_RESOURCES[] = "out of resources"; 51 | static const char MSG_INVALID_VALUE[] = "invalid value"; 52 | static const char MSG_INVALID_RNG_TYPE[] = "invalid type of RNG"; 53 | static const char MSG_INVALID_STREAM_CREATOR[] = "invalid stream creator"; 54 | static const char MSG_INVALID_SEED[] = "invalid seed"; 55 | 56 | 57 | clrngStatus clrngSetErrorString(cl_int err, const char* msg, ...) 58 | { 59 | char formatted[1024]; 60 | const char* base; 61 | switch (err) { 62 | CASE_ERR(SUCCESS); 63 | CASE_ERR(OUT_OF_RESOURCES); 64 | CASE_ERR(INVALID_VALUE); 65 | CASE_ERR(INVALID_RNG_TYPE); 66 | CASE_ERR(INVALID_STREAM_CREATOR); 67 | CASE_ERR(INVALID_SEED); 68 | default: base = MSG_DEFAULT; 69 | } 70 | va_list args; 71 | va_start(args, msg); 72 | vsprintf(formatted, msg, args); 73 | sprintf(errorString, "[%s] %s", base, formatted); 74 | va_end(args); 75 | return (clrngStatus)err; 76 | } 77 | -------------------------------------------------------------------------------- /src/tests/ctest/dispatch.c.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #include "mangle.h" 34 | #include "checks.h" 35 | #include "util.h" 36 | 37 | #include 38 | #include 39 | 40 | #include "../client/common.h" 41 | 42 | #define _CTEST_WITH_NEW_STREAM(func, ...) \ 43 | do { \ 44 | clrngStatus _err; \ 45 | clrngStream* _new_stream = clrngCreateStreams(NULL, 1, NULL, &_err); \ 46 | check_error(_err, NULL); \ 47 | func(_new_stream, __VA_ARGS__); \ 48 | _err = clrngDestroyStreams(_new_stream); \ 49 | check_error(_err, NULL); \ 50 | } while (0) 51 | 52 | 53 | 54 | int CTEST_MANGLE(dispatch)(const DeviceSelect* dev) 55 | { 56 | int ret = 0; 57 | 58 | ret |= CTEST_MANGLE(checkSuccessiveStates)(); 59 | ret |= CTEST_MANGLE_PREC(checkRandomU01,double)(); 60 | ret |= CTEST_MANGLE(checkCreateStreams)(); 61 | ret |= CTEST_MANGLE(checkRewindStreamCreator)(); 62 | ret |= CTEST_MANGLE(checkChangeStreamsSpacing)(); 63 | ret |= CTEST_MANGLE_PREC(checkRandomInteger,double)(); 64 | ret |= CTEST_MANGLE(checkAdvanceStreams)(); 65 | ret |= CTEST_MANGLE(checkRewindStreams)(); 66 | ret |= CTEST_MANGLE(checkForwardToNextSubstreams)(); 67 | ret |= CTEST_MANGLE(checkMakeSubstreams)(); 68 | ret |= CTEST_MANGLE_PREC(checkCombinedOperations,float)(); 69 | ret |= CTEST_MANGLE_PREC(checkCombinedOperations,double)(); 70 | ret |= CTEST_MANGLE_PREC(checkDeviceOperations,float)(dev); 71 | ret |= CTEST_MANGLE_PREC(checkDeviceOperations,double)(dev); 72 | ret |= CTEST_MANGLE_PREC(checkDeviceRandomArray,float)(dev); 73 | ret |= CTEST_MANGLE_PREC(checkDeviceRandomArray,double)(dev); 74 | 75 | return ret; 76 | } 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2015 Advanced Micro Devices, Inc. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | *********************************************************************** 30 | clRNG uses the following software with their 31 | corresponding licenses printed below: 32 | *********************************************************************** 33 | 34 | Random123 software 35 | https://www.deshawresearch.com/resources_random123.html 36 | 37 | Copyright 2010-2011, D. E. Shaw Research. 38 | All rights reserved. 39 | 40 | Redistribution and use in source and binary forms, with or without 41 | modification, are permitted provided that the following conditions are 42 | met: 43 | 44 | * Redistributions of source code must retain the above copyright 45 | notice, this list of conditions, and the following disclaimer. 46 | 47 | * Redistributions in binary form must reproduce the above copyright 48 | notice, this list of conditions, and the following disclaimer in the 49 | documentation and/or other materials provided with the distribution. 50 | 51 | * Neither the name of D. E. Shaw Research nor the names of its 52 | contributors may be used to endorse or promote products derived from 53 | this software without specific prior written permission. 54 | 55 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 56 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 57 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 58 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 59 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 60 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 61 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 65 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 | 67 | 68 | **************************************************************************** -------------------------------------------------------------------------------- /src/tests/ctest/philox432_checks_d.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Philox432 34 | #define CTEST_RNG_HEADER philox432 35 | #include "mangle.h" 36 | 37 | #define CTEST_SUBSTREAM_STEP_LOG2 66 38 | #define CTEST_SUBSTREAM_STEP_LIN 0 39 | 40 | // The following values were generated using Random123: 41 | cl_double CTEST_MANGLE(expectedRandomU01Values)[] = { 42 | 0.037094080704264343, 43 | 0.693930919165723026, 44 | 0.362091115559451282, 45 | 0.972241201554425061, 46 | 0.271746986662037671, 47 | 0.140946607454679906, 48 | 0.319445768021978438, 49 | 0.019449422485195100, 50 | 0.426776767824776471, 51 | 0.604630667599849403, 52 | 0.415107050561346114, 53 | 0.787367770797573030 54 | }; 55 | 56 | clrngStreamState CTEST_MANGLE(expectedSuccessiveStates)[] = { 57 | {{{0,0},{0,1}}, {0,0,0,0}, 0}, 58 | {{{0,0},{0,1}}, {0,0,0,0}, 1}, 59 | {{{0,0},{0,1}}, {0,0,0,0}, 2}, 60 | {{{0,0},{0,1}}, {0,0,0,0}, 3}, 61 | {{{0,0},{0,2}}, {0,0,0,0}, 0}, 62 | {{{0,0},{0,2}}, {0,0,0,0}, 1}, 63 | {{{0,0},{0,2}}, {0,0,0,0}, 2}, 64 | {{{0,0},{0,2}}, {0,0,0,0}, 3}, 65 | {{{0,0},{0,3}}, {0,0,0,0}, 0}, 66 | {{{0,0},{0,3}}, {0,0,0,0}, 1} 67 | }; 68 | 69 | clrngStreamState CTEST_MANGLE(expectedCreateStreamsStates)[] = { 70 | {{{ 0,0},{0,1}}, {0,0,0,0}, 0}, 71 | {{{16,0},{0,1}}, {0,0,0,0}, 0}, 72 | {{{32,0},{0,1}}, {0,0,0,0}, 0}, 73 | {{{48,0},{0,1}}, {0,0,0,0}, 0}, 74 | {{{64,0},{0,1}}, {0,0,0,0}, 0}, 75 | {{{80,0},{0,1}}, {0,0,0,0}, 0} 76 | }; 77 | 78 | clrngStreamState CTEST_MANGLE(expectedForwardToNextSubstreamsStates)[] = { 79 | {{{0,1},{0,1}}, {0,0,0,0}, 0}, 80 | {{{0,2},{0,1}}, {0,0,0,0}, 0}, 81 | {{{0,3},{0,1}}, {0,0,0,0}, 0}, 82 | {{{0,4},{0,1}}, {0,0,0,0}, 0}, 83 | {{{0,5},{0,1}}, {0,0,0,0}, 0} 84 | }; 85 | 86 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 38.672370329515402432; 87 | 88 | #define CTEST_STREAMS_SPACING_MULTIPLE_OF_4 89 | 90 | #include "checks.c.h" 91 | #include "checks_prec.c.h" 92 | -------------------------------------------------------------------------------- /src/library/clRNG.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /* @file clRNG.c 34 | * @brief Implementation of functions defined in clRNG.h and private.h 35 | */ 36 | 37 | #include 38 | #include "private.h" 39 | #include 40 | #include 41 | #include 42 | #ifdef _MSC_VER 43 | #include 44 | #else 45 | #include 46 | #endif 47 | 48 | #define CASE_ERR_(code,msg) case code: base = msg; break 49 | #define CASE_ERR(code) CASE_ERR_(CLRNG_ ## code, MSG_ ## code) 50 | 51 | extern char errorString[1024]; 52 | 53 | const char* clrngGetErrorString() 54 | { 55 | return errorString; 56 | } 57 | 58 | 59 | static char lib_path_default1[] = "/usr"; 60 | static char lib_path_default1_check[] = "/usr/include/clRNG/clRNG.h"; 61 | static char lib_path_default2[] = "."; 62 | 63 | const char* clrngGetLibraryRoot() 64 | { 65 | const char* lib_path = getenv("CLRNG_ROOT"); 66 | 67 | if (lib_path == NULL) { 68 | // check if lib_path_default1_check exists 69 | if ( 70 | #ifdef _MSC_VER 71 | _access(lib_path_default1_check, 0) != -1 72 | #else 73 | access(lib_path_default1_check, F_OK) != -1 74 | #endif 75 | ) 76 | return lib_path_default1; 77 | // last resort 78 | return lib_path_default2; 79 | } 80 | else 81 | return lib_path; 82 | } 83 | 84 | 85 | static char lib_includes[1024]; 86 | 87 | const char* clrngGetLibraryDeviceIncludes(cl_int* err) 88 | { 89 | if (err) 90 | *err = CLRNG_SUCCESS; 91 | 92 | int nbytes; 93 | #ifdef _MSC_VER 94 | nbytes = sprintf_s( 95 | #else 96 | nbytes = snprintf( 97 | #endif 98 | lib_includes, 99 | sizeof(lib_includes), 100 | "-I\"%s/include\"", 101 | clrngGetLibraryRoot()); 102 | 103 | #ifdef _MSC_VER 104 | if (nbytes < 0) { 105 | #else 106 | if (nbytes >= sizeof(lib_includes)) { 107 | #endif 108 | if (err) 109 | *err = clrngSetErrorString(CLRNG_OUT_OF_RESOURCES, "value of CLRNG_ROOT too long (max = %u)", sizeof(lib_includes) - 16); 110 | return NULL; 111 | } 112 | return lib_includes; 113 | } 114 | -------------------------------------------------------------------------------- /src/tests/ctest/lfsr113_checks_d.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Lfsr113 34 | #define CTEST_RNG_HEADER lfsr113 35 | #include "mangle.h" 36 | 37 | #define CTEST_SUBSTREAM_STEP_LOG2 55 38 | #define CTEST_SUBSTREAM_STEP_LIN 0 39 | 40 | // The following values were generated using SSJ: 41 | cl_double CTEST_MANGLE(expectedRandomU01Values)[] = { 42 | 0.9202779277879097, 43 | 0.2777645708346356, 44 | 0.564335069953386, 45 | 0.28643811650424306, 46 | 0.18350138441112326, 47 | 0.13978629323193192, 48 | 0.6811267867029815, 49 | 0.41023648543976327, 50 | 0.34996541045839774, 51 | 0.34781615870357113 52 | }; 53 | 54 | // The following states were generated using SSJ: 55 | clrngStreamState CTEST_MANGLE(expectedSuccessiveStates)[] = { 56 | {{ 987654321U, 987654321U, 987654321U, 987654321U}}, 57 | {{2730781218U, 3950617306U, 1865703358U, 3441345234U}}, 58 | {{2827525879U, 2917567336U, 2586828582U, 3629801101U}}, 59 | {{2078037369U, 3080334755U, 401576718U, 1272031370U}}, 60 | {{1441031752U, 3731404429U, 4157179692U, 890328526U}}, 61 | {{2569103343U, 2040715828U, 3838023225U, 716822975U}} 62 | }; 63 | 64 | // The following states were generated using SSJ: 65 | clrngStreamState CTEST_MANGLE(expectedCreateStreamsStates)[] = { 66 | {{ 987654321U, 987654321U, 987654321U, 987654321U}}, 67 | {{1238817258U, 1756794174U, 3139831156U, 3929772541U}}, 68 | {{3976037797U, 2369672037U, 2206891917U, 1144859279U}}, 69 | {{2208361474U, 1399180856U, 300913405U, 1189142830U}}, 70 | {{3167838773U, 3459839895U, 905364637U, 3159382846U}} 71 | }; 72 | 73 | // The following states were generated using SSJ: 74 | clrngStreamState CTEST_MANGLE(expectedForwardToNextSubstreamsStates)[] = { 75 | {{3989748853U, 374484650U, 4095620850U, 2108357207U}}, 76 | {{1305638194U, 331955594U, 1865703358U, 3764226144U}}, 77 | {{2616441350U, 4073515993U, 253458839U, 1836613789U}}, 78 | {{2944495764U, 1975308653U, 2586828582U, 2828430838U}}, 79 | {{ 24859044U, 748969300U, 2377960193U, 703249964U}} 80 | }; 81 | 82 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 39.036461095189096682; 83 | 84 | #define CTEST_NO_ADVANCE 85 | 86 | 87 | #include "checks.c.h" 88 | #include "checks_prec.c.h" 89 | -------------------------------------------------------------------------------- /src/include/clRNG/private/modular.c.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file Modular arithmetic and linear algebra 34 | * 35 | * This file provides the code common to the host and device. 36 | * 37 | * The preprocessor symbol `MODULAR_NUMBER_TYPE` must be defined as the type 38 | * of number (cl_uint, cl_ulong, etc.) on which the modular functions operate. 39 | * 40 | * To use the fixed size variant, the preprocessor constant 41 | * `MODULAR_FIXED_SIZE` must be set to the size (number of rows or of columns) 42 | * of the matrix. 43 | * 44 | * @note If the project is migrated to C++, this could be rewritten much more 45 | * clearly using templates. 46 | */ 47 | 48 | #pragma once 49 | #ifndef PRIVATE_MODULAR_CH 50 | 51 | #ifndef MODULAR_NUMBER_TYPE 52 | #error "MODULAR_NUMBER_TYPE must be defined" 53 | #endif 54 | 55 | #ifdef MODULAR_FIXED_SIZE 56 | # define N MODULAR_FIXED_SIZE 57 | # define MATRIX_ELEM(mat, i, j) (mat[i][j]) 58 | #else 59 | # define MATRIX_ELEM(mat, i, j) (mat[i * N + j]) 60 | #endif // MODULAR_FIXED_SIZE 61 | 62 | //! Compute (a*s + c) % m 63 | #if 1 64 | #define modMult(a, s, c, m) ((MODULAR_NUMBER_TYPE)(((cl_ulong) a * s + c) % m)) 65 | #else 66 | static MODULAR_NUMBER_TYPE modMult(MODULAR_NUMBER_TYPE a, MODULAR_NUMBER_TYPE s, MODULAR_NUMBER_TYPE c, MODULAR_NUMBER_TYPE m) 67 | { 68 | MODULAR_NUMBER_TYPE v; 69 | v = (MODULAR_NUMBER_TYPE) (((cl_ulong) a * s + c) % m); 70 | return v; 71 | } 72 | #endif 73 | 74 | 75 | //! @brief Matrix-vector modular multiplication 76 | // @details Also works if v = s. 77 | // @return v = A*s % m 78 | #ifdef MODULAR_FIXED_SIZE 79 | static void modMatVec (MODULAR_NUMBER_TYPE A[N][N], MODULAR_NUMBER_TYPE s[N], MODULAR_NUMBER_TYPE v[N], MODULAR_NUMBER_TYPE m) 80 | #else 81 | void modMatVec (size_t N, MODULAR_NUMBER_TYPE* A, MODULAR_NUMBER_TYPE* s, MODULAR_NUMBER_TYPE* v, MODULAR_NUMBER_TYPE m) 82 | #endif 83 | { 84 | MODULAR_NUMBER_TYPE x[MODULAR_FIXED_SIZE]; // Necessary if v = s 85 | for (size_t i = 0; i < N; ++i) { 86 | x[i] = 0; 87 | for (size_t j = 0; j < N; j++) 88 | x[i] = modMult(MATRIX_ELEM(A,i,j), s[j], x[i], m); 89 | } 90 | for (size_t i = 0; i < N; ++i) 91 | v[i] = x[i]; 92 | } 93 | 94 | #undef MATRIX_ELEM 95 | #undef N 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /src/tests/ctest/util.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #include "util.h" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __APPLE__ 40 | #include 41 | #else 42 | #include 43 | #endif 44 | 45 | #include "../client/common.h" 46 | 47 | 48 | // globals 49 | int ctestVerbose = 0; 50 | 51 | // device select 52 | static DeviceSelect device_select; 53 | const DeviceSelect* parse_device_select(size_t nargs, const long* args) 54 | { 55 | device_select.platform_index = 0; 56 | device_select.device_type = CL_DEVICE_TYPE_CPU; 57 | device_select.device_index = 0; 58 | if (nargs > 0) { device_select.device_type = (cl_device_type) *args++; nargs--; } 59 | if (nargs > 0) { device_select.device_index = (size_t) *args++; nargs--; } 60 | if (nargs > 0) { device_select.platform_index = (size_t) *args++; nargs--; } 61 | return &device_select; 62 | } 63 | 64 | 65 | // write_array 66 | 67 | #define IMPLEMENT_WRITE_ARRAY(type) \ 68 | void write_array_##type(FILE* file, size_t num_cols, const char* format, size_t array_size, const type* array) \ 69 | { \ 70 | size_t num_rows = (array_size + num_cols - 1) / num_cols; \ 71 | for (size_t row = 0; row < num_rows; row++) { \ 72 | for (size_t col = 0; col < num_cols; col++) { \ 73 | size_t i = col * num_rows + row; \ 74 | if (i < array_size) \ 75 | fprintf(file, format, array[i]); \ 76 | } \ 77 | fprintf(file, "\n"); \ 78 | } \ 79 | } 80 | 81 | IMPLEMENT_WRITE_ARRAY(cl_float) 82 | IMPLEMENT_WRITE_ARRAY(cl_double) 83 | 84 | 85 | char *portable_basename(char *path) 86 | { 87 | #ifdef _MSC_VER 88 | char* p = strrchr(path, '\\'); 89 | #else 90 | char* p = strrchr(path, '/'); 91 | #endif 92 | return p ? p + 1 : path; 93 | } 94 | 95 | 96 | static int clinfo_helper(cl_context context, cl_device_id device, cl_command_queue queue, void* data_) 97 | { 98 | // Nothing to do; the call_with_opencl() wrapper will output platform and device 99 | // information. 100 | return EXIT_SUCCESS; 101 | } 102 | 103 | int clinfo(const DeviceSelect* dev) 104 | { 105 | return call_with_opencl(dev->platform_index, dev->device_type, dev->device_index, &clinfo_helper, NULL, true); 106 | } 107 | -------------------------------------------------------------------------------- /src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # *********************************************************************** 3 | # Copyright (c) 2015 Advanced Micro Devices, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions 8 | # are met: 9 | # 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | # *********************************************************************** 30 | 31 | set( clRNG.CTest.Source 32 | ctest/cli.c 33 | ctest/util.c 34 | ctest/mrg31k3p_dispatch.c 35 | ctest/mrg31k3p_common.c 36 | ctest/mrg31k3p_checks_d.c 37 | ctest/mrg31k3p_checks_s.c 38 | ctest/mrg32k3a_dispatch.c 39 | ctest/mrg32k3a_common.c 40 | ctest/mrg32k3a_checks_d.c 41 | ctest/mrg32k3a_checks_s.c 42 | ctest/lfsr113_dispatch.c 43 | ctest/lfsr113_common.c 44 | ctest/lfsr113_checks_d.c 45 | ctest/lfsr113_checks_s.c 46 | ctest/philox432_dispatch.c 47 | ctest/philox432_common.c 48 | ctest/philox432_checks_d.c 49 | ctest/philox432_checks_s.c 50 | ${PROJECT_SOURCE_DIR}/client/common.c 51 | ) 52 | set( clRNG.CTest.Headers 53 | ${PROJECT_SOURCE_DIR}/include/clRNG/clRNG.h 54 | ${PROJECT_SOURCE_DIR}/include/clRNG/mrg31k3p.h 55 | ${PROJECT_SOURCE_DIR}/include/clRNG/mrg32k3a.h 56 | ${PROJECT_SOURCE_DIR}/include/clRNG/lfsr113.h 57 | ${PROJECT_SOURCE_DIR}/include/clRNG/philox432.h 58 | ${PROJECT_SOURCE_DIR}/client/common.h 59 | ctest/util.h 60 | ctest/mangle.h 61 | ctest/checks.h 62 | ctest/dispatch.c.h 63 | ctest/checks.c.h 64 | ctest/checks_prec.c.h 65 | ) 66 | 67 | set( clRNG.CTest.Files ${clRNG.CTest.Source} ${clRNG.CTest.Headers} ) 68 | add_executable( CTest ${clRNG.CTest.Files} ) 69 | 70 | include_directories( 71 | ${OPENCL_INCLUDE_DIRS} 72 | ${PROJECT_SOURCE_DIR}/include 73 | ) 74 | 75 | set( Client.Source ${clRNG.CTest.Source} ) 76 | 77 | if( MSVC ) 78 | if( MSVC_VERSION LESS 1800 ) 79 | # Use C++ with Microsoft compiler 80 | SET_SOURCE_FILES_PROPERTIES( ${Client.Source} PROPERTIES LANGUAGE CXX) 81 | endif () 82 | endif( ) 83 | 84 | set( DL_LIB "" ) 85 | if( WIN32 ) 86 | add_definitions( "/D_CONSOLE" ) 87 | elseif( APPLE ) 88 | set( CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}" ) 89 | else( ) 90 | # To use the dlopen() and dlclose() functions, we should link with libdl 91 | set( DL_LIB "-ldl" ) 92 | endif( ) 93 | 94 | if( CMAKE_COMPILER_IS_GNUCC ) 95 | set( MATH_LIB "-lm" ) 96 | endif() 97 | 98 | if( NOT BUILD_RUNTIME ) 99 | message( ERROR "Building tests requires building runtime." ) 100 | endif( ) 101 | 102 | target_link_libraries( CTest clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 103 | 104 | set_target_properties( CTest PROPERTIES VERSION ${CLRNG_VERSION} ) 105 | set_target_properties( CTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 106 | 107 | # CPack configuration; include the executable into the package 108 | install( TARGETS CTest 109 | RUNTIME DESTINATION bin${SUFFIX_BIN} 110 | ) 111 | 112 | -------------------------------------------------------------------------------- /src/tests/ctest/cli.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #ifdef __APPLE__ 39 | #include 40 | #else 41 | #include 42 | #endif 43 | 44 | #include "util.h" 45 | 46 | // defined in cltest_.c 47 | int ctestMrg31k3p_dispatch (const DeviceSelect* dev); 48 | int ctestMrg32k3a_dispatch (const DeviceSelect* dev); 49 | int ctestLfsr113_dispatch (const DeviceSelect* dev); 50 | int ctestPhilox432_dispatch(const DeviceSelect* dev); 51 | 52 | // defined below in this file 53 | int usage(); 54 | 55 | // for use from within usage() 56 | static const char* global_prog; 57 | 58 | 59 | // main program: command line interface (CLI) 60 | int main(int argc, char** argv) 61 | { 62 | global_prog = portable_basename(*argv++); argc--; 63 | 64 | while (argc >= 1 && (*argv)[0] == '-') { 65 | if (strcmp(*argv, "-h") == 0) 66 | return usage(); 67 | else if (strcmp(*argv, "-v") == 0) 68 | ctestVerbose++; 69 | else { 70 | fprintf(stderr, "ERROR: unknown switch `%s'\n", *argv); 71 | return usage(); 72 | } 73 | argv++; argc--; 74 | } 75 | 76 | // parse integer arguments 77 | size_t nargs = 0; 78 | long args[10]; 79 | while (argc > 0 && nargs < (sizeof(args)/sizeof(args[0]))) { 80 | const char* s = *argv++; argc--; 81 | if (strcmp(s, "CPU") == 0) 82 | args[nargs++] = CL_DEVICE_TYPE_CPU; 83 | else if (strcmp(s, "GPU") == 0) 84 | args[nargs++] = CL_DEVICE_TYPE_GPU; 85 | else { 86 | args[nargs++] = strtol(s, (char**) NULL, 10); 87 | if (errno) { 88 | fprintf(stderr, "error interpreting %s as an integer\n", s); 89 | return EXIT_FAILURE; 90 | } 91 | } 92 | } 93 | 94 | const DeviceSelect* dev = parse_device_select(nargs, args); 95 | clinfo(dev); 96 | 97 | // launch tests 98 | int ret = 0; 99 | ret |= ctestMrg31k3p_dispatch (dev); 100 | ret |= ctestMrg32k3a_dispatch (dev); 101 | ret |= ctestLfsr113_dispatch (dev); 102 | ret |= ctestPhilox432_dispatch(dev); 103 | return ret; 104 | } 105 | 106 | 107 | // display usage directives 108 | int usage() 109 | { 110 | fprintf(stderr, "usage:\n"); 111 | fprintf(stderr, "\n run tests:\n"); 112 | fprintf(stderr, " %s [-v] [-v] [CPU|GPU] [] []\n", global_prog); 113 | fprintf(stderr, "\n display help:\n"); 114 | fprintf(stderr, " %s -h\n", global_prog); 115 | fprintf(stderr, "\nwhere:\n"); 116 | fprintf(stderr, " : device index (starting from 0)\n"); 117 | fprintf(stderr, " : device index (starting from 0)\n"); 118 | fprintf(stderr, " the `-v' switch: enables verbose output (can be used twice)\n"); 119 | return EXIT_FAILURE; 120 | } 121 | -------------------------------------------------------------------------------- /src/FindOpenCL.cmake: -------------------------------------------------------------------------------- 1 | 2 | # *********************************************************************** 3 | # Copyright (c) 2015 Advanced Micro Devices, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions 8 | # are met: 9 | # 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | # *********************************************************************** 30 | 31 | # ######################################################################## 32 | 33 | 34 | 35 | # Locate an OpenCL implementation. 36 | # Currently supports AMD APP SDK (http://developer.amd.com/sdks/AMDAPPSDK/Pages/default.aspx/) 37 | # 38 | # Defines the following variables: 39 | # 40 | # OPENCL_FOUND - Found the OPENCL framework 41 | # OPENCL_INCLUDE_DIRS - Include directories 42 | # 43 | # Also defines the library variables below as normal 44 | # variables. These contain debug/optimized keywords when 45 | # a debugging library is found. 46 | # 47 | # OPENCL_LIBRARIES - libopencl 48 | # 49 | # Accepts the following variables as input: 50 | # 51 | # OPENCL_ROOT - (as a CMake or environment variable) 52 | # The root directory of the OpenCL implementation found 53 | # 54 | # FIND_LIBRARY_USE_LIB64_PATHS - Global property that controls whether findOpenCL should search for 55 | # 64bit or 32bit libs 56 | #----------------------- 57 | # Example Usage: 58 | # 59 | # find_package(OPENCL REQUIRED) 60 | # include_directories(${OPENCL_INCLUDE_DIRS}) 61 | # 62 | # add_executable(foo foo.cc) 63 | # target_link_libraries(foo ${OPENCL_LIBRARIES}) 64 | # 65 | #----------------------- 66 | 67 | find_path(OPENCL_INCLUDE_DIRS 68 | NAMES OpenCL/cl.h CL/cl.h 69 | HINTS 70 | ${OPENCL_ROOT}/include 71 | $ENV{AMDAPPSDKROOT}/include 72 | $ENV{CUDA_PATH}/include 73 | PATHS 74 | /usr/include 75 | /usr/local/include 76 | DOC "OpenCL header file path" 77 | ) 78 | mark_as_advanced( OPENCL_INCLUDE_DIRS ) 79 | 80 | # Search for 64bit libs if FIND_LIBRARY_USE_LIB64_PATHS is set to true in the global environment, 32bit libs else 81 | get_property( LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ) 82 | 83 | if( LIB64 ) 84 | find_library( OPENCL_LIBRARIES 85 | NAMES OpenCL 86 | HINTS 87 | ${OPENCL_ROOT}/lib 88 | $ENV{AMDAPPSDKROOT}/lib 89 | $ENV{CUDA_PATH}/lib 90 | DOC "OpenCL dynamic library path" 91 | PATH_SUFFIXES x86_64 x64 92 | PATHS 93 | /usr/lib 94 | ) 95 | else( ) 96 | find_library( OPENCL_LIBRARIES 97 | NAMES OpenCL 98 | HINTS 99 | ${OPENCL_ROOT}/lib 100 | $ENV{AMDAPPSDKROOT}/lib 101 | $ENV{CUDA_PATH}/lib 102 | DOC "OpenCL dynamic library path" 103 | PATH_SUFFIXES x86 Win32 104 | PATHS 105 | /usr/lib 106 | ) 107 | endif( ) 108 | mark_as_advanced( OPENCL_LIBRARIES ) 109 | 110 | include( FindPackageHandleStandardArgs ) 111 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( OPENCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS ) 112 | 113 | if( NOT OPENCL_FOUND ) 114 | message( STATUS "FindOpenCL looked for libraries named: OpenCL" ) 115 | endif() 116 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg31k3p_checks_d.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg31k3p 34 | #define CTEST_RNG_HEADER mrg31k3p 35 | #include "mangle.h" 36 | 37 | #define CTEST_SUBSTREAM_STEP_LOG2 72 38 | #define CTEST_SUBSTREAM_STEP_LIN 0 39 | 40 | // The following values were generated using SSJ: 41 | cl_double CTEST_MANGLE(expectedRandomU01Values)[] = { 42 | 0.7353244530968368, 43 | 0.6142074400559068, 44 | 0.11007806099951267, 45 | 0.6487741703167558, 46 | 0.36619443260133266, 47 | 0.10882294131442904, 48 | 0.5330547927878797, 49 | 0.9783797566778958, 50 | 0.9151237849146128, 51 | 0.8509745532646775 52 | }; 53 | 54 | // The following states were generated using SSJ: 55 | clrngStreamState CTEST_MANGLE(expectedSuccessiveStates)[] = { 56 | {{ 12345U, 12345U, 12345U}, { 12345U, 12345U, 12345U}}, 57 | {{ 240667857U, 12345U, 12345U}, { 809054265U, 12345U, 12345U}}, 58 | {{ 240667857U, 240667857U, 12345U}, { 1069151070U, 809054265U, 12345U}}, 59 | {{ 878672095U, 240667857U, 240667857U}, { 642281259U, 1069151070U, 809054265U}}, 60 | {{1858462085U, 878672095U, 240667857U}, { 465230163U, 642281259U, 1069151070U}}, 61 | {{1918428443U, 1858462085U, 878672095U}, { 1132031887U, 465230163U, 642281259U}}, 62 | {{1167281028U, 1918428443U, 1858462085U}, { 933585541U, 1132031887U, 465230163U}}, 63 | {{ 414175463U, 1167281028U, 1918428443U}, { 1416932659U, 933585541U, 1132031887U}}, 64 | {{2146319539U, 414175463U, 1167281028U}, { 45265010U, 1416932659U, 933585541U}}, 65 | {{1225090482U, 2146319539U, 414175463U}, { 1407360765U, 45265010U, 1416932659U}}, 66 | {{ 496515998U, 1225090482U, 2146319539U}, { 816545707U, 1407360765U, 45265010U}} 67 | }; 68 | 69 | // The following states were generated using SSJ: 70 | clrngStreamState CTEST_MANGLE(expectedCreateStreamsStates)[] = { 71 | {{ 12345U, 12345U, 12345U}, { 12345U, 12345U, 12345U}}, 72 | {{ 336690377U, 597094797U, 1245771585U}, { 85196284U, 523477687U, 2094976052U}}, 73 | {{ 502033783U, 1322587635U, 1964121530U}, {1949818481U, 1607232546U, 1462898381U}}, 74 | {{ 739421137U, 1475938232U, 730262207U}, {1630192198U, 324551134U, 795289868U}}, 75 | {{1719768226U, 483121100U, 630243355U}, { 233387880U, 1309486499U, 955444484U}} 76 | }; 77 | 78 | // The following states were generated using SSJ: 79 | clrngStreamState CTEST_MANGLE(expectedForwardToNextSubstreamsStates)[] = { 80 | {{1613322692U, 623311037U, 1722317882U}, {1563970864U, 792350268U, 619030428U}}, 81 | {{ 951422716U, 416944718U, 1329311079U}, {1678647957U, 55905791U, 588091391U}}, 82 | {{ 633017320U, 754813095U, 1852802056U}, {1286382983U, 619510916U, 1985727270U}}, 83 | {{1917166970U, 1614507274U, 14454538U}, {2075550713U, 380800384U, 1297245527U}}, 84 | {{ 616391739U, 825560200U, 380717754U}, { 337850709U, 1365046996U, 233035748U}} 85 | }; 86 | 87 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 40.017101830525696471; 88 | 89 | 90 | #include "checks.c.h" 91 | #include "checks_prec.c.h" 92 | -------------------------------------------------------------------------------- /docs/clRNG.bib: -------------------------------------------------------------------------------- 1 | @manual{iLEC08j, 2 | author = {P. L'Ecuyer}, 3 | title = {{SSJ}: A {J}ava Library for Stochastic Simulation}, 4 | note = {Software {user's} guide, 5 | available at \url{http://www.iro.umontreal.ca/~lecuyer}}, 6 | institution = {D\'epartement d'Informatique et de Recherche 7 | Op\'erationnelle, Universit\'e de Montr\'eal}, 8 | year = {2008}, 9 | OPTannote = {} 10 | } 11 | 12 | @ARTICLE {rLEC91a, 13 | AUTHOR="P. L'Ecuyer and S. C{\^o}t{\'e}", 14 | TITLE="Implementing a Random Number Package with Splitting Facilities", 15 | JOURNAL={ACM Transactions on Mathematical Software}, 16 | VOLUME={17}, 17 | NUMBER={1}, 18 | YEAR={1991}, 19 | PAGES={98--111} } 20 | 21 | @article {rLEC99a, 22 | old = "rLEC97g", 23 | AUTHOR="P. L'Ecuyer", 24 | TITLE="Tables of Maximally Equidistributed Combined {LFSR} Generators", 25 | JOURNAL={Mathematics of Computation}, 26 | VOLUME={68}, 27 | NUMBER={225}, 28 | PAGES={261--269}, 29 | YEAR={1999} 30 | } 31 | 32 | @article {rLEC99b, 33 | old = "rLEC97f", 34 | AUTHOR="P. L'Ecuyer", 35 | TITLE="Good Parameters and Implementations for 36 | Combined Multiple Recursive Random Number Generators", 37 | JOURNAL={Operations Research}, 38 | VOLUME={47}, 39 | NUMBER={1}, 40 | PAGES={159--164}, 41 | YEAR={1999} 42 | } 43 | 44 | @INPROCEEDINGS {rLEC00b, 45 | AUTHOR="P. L'Ecuyer and R. Touzin", 46 | TITLE={Fast Combined Multiple Recursive Generators with Multipliers 47 | of the Form $a = \pm 2^q \pm 2^r$}, 48 | BOOKTITLE={Proceedings of the 2000 Winter Simulation Conference}, 49 | OPTeditor = {J. A. Joines and R. R. Barton and K. Kang 50 | and P. A. Fishwick}, 51 | PUBLISHER="{IEEE} Press", 52 | ADDRESS= {Piscataway, NJ}, 53 | YEAR={2000}, 54 | PAGES={683--689} } 55 | 56 | @article {rLEC02a, 57 | old = {rLEC01s}, 58 | AUTHOR="P. L'Ecuyer and R. Simard and E. J. Chen and W. D. Kelton", 59 | TITLE="An Object-Oriented Random-Number Package with Many 60 | Long Streams and Substreams", 61 | JOURNAL={Operations Research}, 62 | VOLUME={50}, 63 | NUMBER={6}, 64 | PAGES={1073--1075}, 65 | YEAR={2002} } 66 | 67 | @article{rLEC07b, 68 | OLD = {rLEC06b}, 69 | author = {P. L'Ecuyer and R. Simard}, 70 | title = {{TestU01}: A {C} Library for Empirical Testing of Random Number Generators}, 71 | journal = {{ACM} Transactions on Mathematical Software}, 72 | volume = {33}, 73 | number = {4}, 74 | pages = {Article 22}, 75 | month = {August}, 76 | year = {2007}, 77 | OPTdoi = {http://doi.acm.org/10.1145/1268776.1268777}, 78 | publisher = {ACM Press}, 79 | address = {New York, NY, USA}, 80 | OPTnote = {available at 81 | \url{http://www.simul.umontreal.ca/testu01/tu01.html}}, 82 | } 83 | 84 | @misc{rLEC14p, 85 | author = {P. L'Ecuyer and B. Oreshkin and R. Simard}, 86 | title = {Random Numbers for Parallel Computers: Requirements and Methods}, 87 | OPTjournal = {Mathematics and Computers in Simulation}, 88 | xvolume = {}, 89 | xnumber = {}, 90 | xpages = {}, 91 | year = {2014}, 92 | \url = {http://www.iro.umontreal.ca/~lecuyer/myftp/papers/parallel-rng-imacs.pdf}, 93 | note = {\url{http://www.iro.umontreal.ca/~lecuyer/myftp/papers/parallel-rng-imacs.pdf}} 94 | } 95 | 96 | @inproceedings{rSAL11a, 97 | author = {Salmon, J. K. and Moraes, M. A. and Dror, R. O. and Shaw, D. E.}, 98 | title = {Parallel random numbers: as easy as 1, 2, 3}, 99 | booktitle = {Proceedings of the 2011 International Conference for High Performance Computing, 100 | Networking, Storage and Analysis}, 101 | year = {2011}, 102 | isbn = {978-1-4503-0771-0}, 103 | Xlocation = {Seattle, Washington}, 104 | pages = {16:1--16:12}, 105 | articleno = {16}, 106 | numpages = {12}, 107 | OPTurl = {http://doi.acm.org/10.1145/2063384.2063405}, 108 | OPTdoi = {10.1145/2063384.2063405}, 109 | publisher = {ACM}, 110 | address = {New York} 111 | } 112 | 113 | @BOOK {sLAW14a, 114 | AUTHOR="A. M. Law", 115 | TITLE={Simulation Modeling and Analysis}, 116 | EDITION={Fifth}, 117 | PUBLISHER={McGraw-Hill}, 118 | ADDRESS={New York}, 119 | YEAR={2014} } 120 | 121 | @InProceedings{vLEC07e, 122 | author = {P. L'Ecuyer}, 123 | title = {Variance Reduction's Greatest Hits}, 124 | booktitle = {Proceedings of the 2007 European Simulation and Modeling Conference}, 125 | organization = {EUROSIS}, 126 | address = {Ghent, Belgium}, 127 | pages = {5--12}, 128 | year = {2007} 129 | } 130 | 131 | -------------------------------------------------------------------------------- /src/tests/ctest/mrg32k3a_checks_d.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CTEST_RNG_TYPE Mrg32k3a 34 | #define CTEST_RNG_HEADER mrg32k3a 35 | #include "mangle.h" 36 | 37 | #define CTEST_SUBSTREAM_STEP_LOG2 76 38 | #define CTEST_SUBSTREAM_STEP_LIN 0 39 | 40 | // The following values were generated using SSJ: 41 | cl_double CTEST_MANGLE(expectedRandomU01Values)[] = { 42 | 0.12701112204657714, 43 | 0.3185275653967945, 44 | 0.3091860155832701, 45 | 0.8258468629271136, 46 | 0.2216299157820229, 47 | 0.5333953879182788, 48 | 0.4807742033156181, 49 | 0.3555598794381262, 50 | 0.13598841039594017, 51 | 0.7558522371615436 52 | }; 53 | 54 | // The following states were generated using SSJ: 55 | clrngStreamState CTEST_MANGLE(expectedSuccessiveStates)[] = { 56 | {{ 12345UL, 12345UL, 12345UL}, { 12345UL, 12345UL, 12345UL}}, 57 | {{ 12345UL, 12345UL, 3023790853UL}, { 12345UL, 12345UL, 2478282264UL}}, 58 | {{ 12345UL, 3023790853UL, 3023790853UL}, { 12345UL, 2478282264UL, 1655725443UL}}, 59 | {{3023790853UL, 3023790853UL, 3385359573UL}, {2478282264UL, 1655725443UL, 2057415812UL}}, 60 | {{3023790853UL, 3385359573UL, 1322208174UL}, {1655725443UL, 2057415812UL, 2070190165UL}}, 61 | {{3385359573UL, 1322208174UL, 2930192941UL}, {2057415812UL, 2070190165UL, 1978299747UL}}, 62 | {{1322208174UL, 2930192941UL, 2462079208UL}, {2070190165UL, 1978299747UL, 171163572UL}}, 63 | {{2930192941UL, 2462079208UL, 2386811717UL}, {1978299747UL, 171163572UL, 321902337UL}}, 64 | {{2462079208UL, 2386811717UL, 2989318136UL}, { 171163572UL, 321902337UL, 1462200156UL}}, 65 | {{2386811717UL, 2989318136UL, 3378525425UL}, { 321902337UL, 1462200156UL, 2794459678UL}}, 66 | {{2989318136UL, 3378525425UL, 1773647758UL}, {1462200156UL, 2794459678UL, 2822254363UL}} 67 | }; 68 | 69 | // The following states were generated using SSJ: 70 | clrngStreamState CTEST_MANGLE(expectedCreateStreamsStates)[] = { 71 | {{ 12345UL, 12345UL, 12345UL}, { 12345UL, 12345UL, 12345UL}}, 72 | {{3692455944UL, 1366884236UL, 2968912127UL}, { 335948734UL, 4161675175UL, 475798818UL}}, 73 | {{1015873554UL, 1310354410UL, 2249465273UL}, { 994084013UL, 2912484720UL, 3876682925UL}}, 74 | {{2338701263UL, 1119171942UL, 2570676563UL}, { 317077452UL, 3194180850UL, 618832124UL}}, 75 | {{1597262096UL, 3906379055UL, 3312112953UL}, {1016013135UL, 4099474108UL, 275305423UL}} 76 | }; 77 | 78 | // The following states were generated using SSJ: 79 | clrngStreamState CTEST_MANGLE(expectedForwardToNextSubstreamsStates)[] = { 80 | {{ 870504860UL, 2641697727UL, 884013853UL}, { 339352413UL, 2374306706UL, 3651603887UL}}, 81 | {{ 460387934UL, 1532391390UL, 877287553UL}, { 120103512UL, 2153115941UL, 335837774UL}}, 82 | {{3775110060UL, 3208296044UL, 1257177538UL}, { 378684317UL, 2867112178UL, 2201306083UL}}, 83 | {{1870130441UL, 490396226UL, 1081325149UL}, {3685085721UL, 2348042618UL, 1094489500UL}}, 84 | {{ 934940479UL, 1950100692UL, 4183308048UL}, {1834563867UL, 1457690863UL, 2911850358UL}} 85 | }; 86 | 87 | fp_type CTEST_MANGLE_PREC2(expectedCombinedOperationsValue) = 39.673224313796254137; 88 | 89 | 90 | #include "checks.c.h" 91 | #include "checks_prec.c.h" 92 | -------------------------------------------------------------------------------- /src/client/WorkItem/workitem.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #if defined(__APPLE__) || defined(__MACOSX) 34 | #include 35 | #else 36 | #include 37 | #endif 38 | 39 | #include 40 | #include 41 | #include "../common.h" 42 | 43 | 44 | /*! [clRNG header] */ 45 | #include 46 | /*! [clRNG header] */ 47 | 48 | int task(cl_context context, cl_device_id device, cl_command_queue queue, void* data) 49 | { 50 | cl_int err; 51 | size_t numWorkItems = *(size_t*)data; 52 | 53 | /*! [create streams] */ 54 | size_t streamBufferSize; 55 | clrngMrg31k3pStream* streams = clrngMrg31k3pCreateStreams(NULL, numWorkItems, 56 | &streamBufferSize, (clrngStatus *)&err); 57 | check_error(err, "cannot create random stream array"); 58 | /*! [create streams] */ 59 | 60 | cl_program program = build_program_from_file(context, device, 61 | "client/WorkItem/workitem_kernel.cl", PATH_RELATIVE_TO_LIB, NULL); 62 | cl_kernel kernel = clCreateKernel(program, "example", &err); 63 | check_error(err, "cannot create kernel"); 64 | 65 | 66 | /*! [create streams buffer] */ 67 | // Create buffer to transfer streams to the device. 68 | cl_mem buf_in = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, 69 | streamBufferSize, streams, &err); 70 | /*! [create streams buffer] */ 71 | check_error(err, "cannot create input buffer"); 72 | /*! [create output buffer] */ 73 | // Create buffer to transfer output back from the device. 74 | cl_mem buf_out = clCreateBuffer(context, CL_MEM_WRITE_ONLY | CL_MEM_HOST_READ_ONLY, 75 | numWorkItems * sizeof(cl_float), NULL, &err); 76 | /*! [create output buffer] */ 77 | check_error(err, "cannot create output buffer"); 78 | 79 | // The kernel takes two arguments; set them to buf_in, buf_out. 80 | err = clSetKernelArg(kernel, 0, sizeof(buf_in), &buf_in); 81 | err |= clSetKernelArg(kernel, 1, sizeof(buf_out), &buf_out); 82 | check_error(err, "cannot create set kernel arguments"); 83 | 84 | // Enqueue the kernel on device. 85 | cl_event ev; 86 | err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &numWorkItems, NULL, 0, NULL, &ev); 87 | check_error(err, "cannot enqueue kernel"); 88 | 89 | // Wait for all work items to finish. 90 | err = clWaitForEvents(1, &ev); 91 | check_error(err, "error waiting for events"); 92 | 93 | cl_ulong t0, t1; 94 | clGetEventProfilingInfo(ev, CL_PROFILING_COMMAND_START, sizeof(t0), &t0, NULL); 95 | clGetEventProfilingInfo(ev, CL_PROFILING_COMMAND_END, sizeof(t1), &t1, NULL); 96 | cl_ulong total_time = t1 - t0; 97 | 98 | // Retrieve the contents of the output buffer from the device. 99 | cl_float* out = (cl_float*) malloc(numWorkItems * sizeof(cl_float)); 100 | err = clEnqueueReadBuffer(queue, buf_out, CL_TRUE, 0, 101 | numWorkItems * sizeof(out[0]), out, 0, NULL, NULL); 102 | check_error(err, "cannot read output buffer"); 103 | 104 | printf("output buffer:\n"); 105 | for (int j = 0; j < numWorkItems; j++) 106 | printf(" %f\n", out[j]); 107 | 108 | printf("\nprocessing time: %1.2f\n", total_time * 1e-9); 109 | 110 | clrngMrg31k3pDestroyStreams(streams); 111 | free(out); 112 | clReleaseEvent(ev); 113 | clReleaseMemObject(buf_in); 114 | clReleaseMemObject(buf_out); 115 | clReleaseKernel(kernel); 116 | clReleaseProgram(program); 117 | 118 | return EXIT_SUCCESS; 119 | } 120 | 121 | 122 | int main() 123 | { 124 | size_t numWorkItems = 8; 125 | return call_with_opencl(0, CL_DEVICE_TYPE_GPU, 0, &task, &numWorkItems, true); 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/tests/ctest/mangle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #pragma once 34 | #ifndef CTEST_COMMON_H 35 | #define CTEST_COMMON_H 36 | 37 | #ifdef __APPLE__ 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | 44 | #ifndef CTEST_RNG_TYPE 45 | #error "CTEST_RNG_TYPE undefined" 46 | #endif 47 | 48 | #ifndef CTEST_RNG_HEADER 49 | #error "CTEST_RNG_HEADER undefined" 50 | #endif 51 | 52 | #define RNG_HOST_HEADER 53 | #define RNG_DEVICE_HEADER 54 | 55 | #define _RNG_MANGLE(ident) _RNG_MANGLE_(ident,CTEST_RNG_TYPE) 56 | #define _RNG_MANGLE_(ident,rng) _RNG_MANGLE__(ident,rng) 57 | #define _RNG_MANGLE__(ident,rng) clrng ## rng ## ident 58 | 59 | #define CTEST_MANGLE(ident) CTEST_MANGLE_(ident,CTEST_RNG_TYPE) 60 | #define CTEST_MANGLE_(ident,rng) CTEST_MANGLE__(ident,rng) 61 | #define CTEST_MANGLE__(ident,rng) ctest ## rng ## _ ## ident 62 | 63 | #define CTEST_MANGLE_PREC(ident,fp) CTEST_MANGLE_PREC_(ident,CTEST_RNG_TYPE,fp) 64 | #define CTEST_MANGLE_PREC_(ident,rng,fp) CTEST_MANGLE_PREC__(ident,rng,fp) 65 | #define CTEST_MANGLE_PREC__(ident,rng,fp) ctest ## rng ## _ ## fp ## _ ## ident 66 | 67 | #ifdef CLRNG_SINGLE_PRECISION 68 | #define CTEST_MANGLE_PREC2(ident) CTEST_MANGLE_PREC_(ident,CTEST_RNG_TYPE,float) 69 | #define write_array write_array_cl_float 70 | typedef cl_float fp_type; 71 | #define DEVICE_FP_TYPE "float" 72 | #else 73 | #define CTEST_MANGLE_PREC2(ident) CTEST_MANGLE_PREC_(ident,CTEST_RNG_TYPE,double) 74 | #define write_array write_array_cl_double 75 | typedef cl_double fp_type; 76 | #define DEVICE_FP_TYPE "double" 77 | #endif 78 | 79 | // utility macro 80 | #define CTEST_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 81 | 82 | // for size types 83 | #if defined(_MSC_VER) || defined(__MINGW32__) 84 | #define SIZE_T_FORMAT "Iu" 85 | #elif defined(__GNUC__) 86 | #define SIZE_T_FORMAT "zu" 87 | #else 88 | #define SIZE_T_FORMAT "lu" 89 | #endif 90 | 91 | #define _CTEST_STR_(x) _CTEST_STR__(x) 92 | #define _CTEST_STR__(x) #x 93 | 94 | #define RNG_TYPE_S _CTEST_STR_(CTEST_RNG_TYPE) 95 | #define RNG_DEVICE_HEADER_S _CTEST_STR_(RNG_DEVICE_HEADER) 96 | 97 | #define clrngStreamState _RNG_MANGLE(StreamState) 98 | #define clrngStream _RNG_MANGLE(Stream) 99 | #define clrngStreamCreator _RNG_MANGLE(StreamCreator) 100 | #define clrngCopyStreamCreator _RNG_MANGLE(CopyStreamCreator) 101 | #define clrngDestroyStreamCreator _RNG_MANGLE(DestroyStreamCreator) 102 | #define clrngRewindStreamCreator _RNG_MANGLE(RewindStreamCreator) 103 | #define clrngSetBaseCreatorState _RNG_MANGLE(SetBaseCreatorState) 104 | #define clrngChangeStreamsSpacing _RNG_MANGLE(ChangeStreamsSpacing) 105 | #define clrngAllocStreams _RNG_MANGLE(AllocStreams) 106 | #define clrngDestroyStreams _RNG_MANGLE(DestroyStreams) 107 | #define clrngCreateStreams _RNG_MANGLE(CreateStreams) 108 | #define clrngCreateOverStreams _RNG_MANGLE(CreateOverStreams) 109 | #define clrngCopyStreams _RNG_MANGLE(CopyStreams) 110 | #define clrngCopyOverStreams _RNG_MANGLE(CopyOverStreams) 111 | #define clrngRandomU01 _RNG_MANGLE(RandomU01) 112 | #define clrngRandomInteger _RNG_MANGLE(RandomInteger) 113 | #define clrngRandomU01Array _RNG_MANGLE(RandomU01Array) 114 | #define clrngRandomIntegerArray _RNG_MANGLE(RandomIntegerArray) 115 | #define clrngRewindStreams _RNG_MANGLE(RewindStreams) 116 | #define clrngRewindSubstreams _RNG_MANGLE(RewindSubstreams) 117 | #define clrngForwardToNextSubstreams _RNG_MANGLE(ForwardToNextSubstreams) 118 | #define clrngMakeSubstreams _RNG_MANGLE(MakeSubstreams) 119 | #define clrngMakeOverSubstreams _RNG_MANGLE(MakeOverSubstreams) 120 | #define clrngAdvanceStreams _RNG_MANGLE(AdvanceStreams) 121 | #define clrngDeviceRandomU01Array _RNG_MANGLE(DeviceRandomU01Array) 122 | #define clrngWriteStreamInfo _RNG_MANGLE(WriteStreamInfo) 123 | 124 | #include RNG_HOST_HEADER 125 | 126 | // defined in ctest_cli.c 127 | extern int ctestVerbose; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/library/modularHost.c.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #pragma once 34 | #ifndef MODULAR_CH 35 | #define MODULAR_CH 36 | 37 | /*! @file Modular arithmetic and linear algebra 38 | * 39 | * This file provides the code specific to the host. There is another file 40 | * included by this file, modular.c.h, for the code shared by the host and the 41 | * device. 42 | * 43 | * The preprocessor symbol `MODULAR_NUMBER_TYPE` must be defined as the type 44 | * of number (cl_uint, cl_ulong, etc.) on which the modular functions operate. 45 | * 46 | * To use the fixed size variant, the preprocessor symbol 47 | * `MODULAR_FIXED_SIZE` must be set to the size (number of rows or of columns) 48 | * of the matrix. 49 | * 50 | * @note If the project is migrated to C++, this could be rewritten much more 51 | * clearly using templates. 52 | */ 53 | 54 | // code that is common to host and device 55 | #include "../include/clRNG/private/modular.c.h" 56 | 57 | #ifdef MODULAR_FIXED_SIZE 58 | # define N MODULAR_FIXED_SIZE 59 | # define MATRIX_ELEM(mat, i, j) (mat[i][j]) 60 | #else 61 | # define MATRIX_ELEM(mat, i, j) (mat[i * N + j]) 62 | #endif // MODULAR_FIXED_SIZE 63 | 64 | //! @brief Compute A*B % m 65 | // @details Also works if A = C or B = C or A = B = C. 66 | // @return C = A*B % m 67 | #ifdef MODULAR_FIXED_SIZE 68 | static void modMatMat (MODULAR_NUMBER_TYPE A[N][N], MODULAR_NUMBER_TYPE B[N][N], MODULAR_NUMBER_TYPE C[N][N], MODULAR_NUMBER_TYPE m) 69 | #else 70 | void modMatMat (size_t N, MODULAR_NUMBER_TYPE* A, MODULAR_NUMBER_TYPE* B, MODULAR_NUMBER_TYPE* C, MODULAR_NUMBER_TYPE m) 71 | #endif 72 | { 73 | MODULAR_NUMBER_TYPE V[N]; 74 | MODULAR_NUMBER_TYPE W[N][N]; 75 | for (size_t i = 0; i < N; ++i) { 76 | for (size_t j = 0; j < N; ++j) 77 | V[j] = MATRIX_ELEM(B,j,i); 78 | #ifdef MODULAR_FIXED_SIZE 79 | modMatVec (A, V, V, m); 80 | #else 81 | modMatVec (N, A, V, V, m); 82 | #endif 83 | for (size_t j = 0; j < N; ++j) 84 | W[j][i] = V[j]; 85 | } 86 | for (size_t i = 0; i < N; ++i) { 87 | for (size_t j = 0; j < N; ++j) 88 | MATRIX_ELEM(C,i,j) = W[i][j]; 89 | } 90 | } 91 | 92 | 93 | //! @brief Compute matrix B = (A^(2^e) % m) 94 | // @details Also works if A = B. 95 | #ifdef MODULAR_FIXED_SIZE 96 | static void modMatPowLog2 (MODULAR_NUMBER_TYPE A[N][N], MODULAR_NUMBER_TYPE B[N][N], MODULAR_NUMBER_TYPE m, cl_uint e) 97 | #else 98 | void modMatPowLog2 (size_t N, MODULAR_NUMBER_TYPE* A, MODULAR_NUMBER_TYPE* B, MODULAR_NUMBER_TYPE m, cl_uint e) 99 | #endif 100 | { 101 | // initialize: B = A 102 | if (A != B) { 103 | for (size_t i = 0; i < N; i++) { 104 | for (size_t j = 0; j < N; ++j) 105 | MATRIX_ELEM(B,i,j) = MATRIX_ELEM(A,i,j); 106 | } 107 | } 108 | // Compute B = A^{2^e}mod m 109 | for (cl_uint i = 0; i < e; i++) 110 | #ifdef MODULAR_FIXED_SIZE 111 | modMatMat (B, B, B, m); 112 | #else 113 | modMatMat (N, B, B, B, m); 114 | #endif 115 | } 116 | 117 | 118 | //! @brief Compute matrix B = A^n % m 119 | // @details Also works if A = B. 120 | #ifdef MODULAR_FIXED_SIZE 121 | static void modMatPow (MODULAR_NUMBER_TYPE A[N][N], MODULAR_NUMBER_TYPE B[N][N], MODULAR_NUMBER_TYPE m, cl_uint n) 122 | #else 123 | void modMatPow (size_t N, MODULAR_NUMBER_TYPE* A, MODULAR_NUMBER_TYPE* B, MODULAR_NUMBER_TYPE m, cl_uint n) 124 | #endif 125 | { 126 | MODULAR_NUMBER_TYPE W[N][N]; 127 | 128 | // initialize: W = A; B = I 129 | for (size_t i = 0; i < N; i++) { 130 | for (size_t j = 0; j < N; ++j) { 131 | W[i][j] = MATRIX_ELEM(A,i,j); 132 | MATRIX_ELEM(B,i,j) = 0; 133 | } 134 | } 135 | 136 | for (size_t j = 0; j < N; ++j) 137 | MATRIX_ELEM(B,j,j) = 1; 138 | 139 | // Compute B = A^n % m using the binary decomposition of n 140 | while (n > 0) { 141 | if (n & 1) // if n is odd 142 | #ifdef MODULAR_FIXED_SIZE 143 | modMatMat (W, B, B, m); 144 | modMatMat (W, W, W, m); 145 | #else 146 | modMatMat (N, &W[0][0], B, B, m); 147 | modMatMat (N, &W[0][0], &W[0][0], &W[0][0], m); 148 | #endif 149 | n >>= 1; 150 | } 151 | } 152 | 153 | #undef MATRIX_ELEM 154 | #undef N 155 | 156 | #endif // MODULAR_CH 157 | -------------------------------------------------------------------------------- /src/include/clRNG/private/Random123/features/msvcfeatures.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010-2011, D. E. Shaw Research. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions, and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions, and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of D. E. Shaw Research nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef __msvcfeatures_dot_hpp 33 | #define __msvcfeatures_dot_hpp 34 | 35 | //#if _MSVC_FULL_VER <= 15 36 | //#error "We've only tested MSVC_FULL_VER==15." 37 | //#endif 38 | 39 | #if !defined(_M_IX86) && !defined(_M_X64) 40 | # error "This code has only been tested on x86 platforms." 41 | { // maybe an unbalanced brace will terminate the compilation 42 | // You are invited to try Random123 on other architectures, by changing 43 | // the conditions that reach this error, but you should consider it a 44 | // porting exercise and expect to encounter bugs and deficiencies. 45 | // Please let the authors know of any successes (or failures). 46 | #endif 47 | 48 | #ifndef R123_STATIC_INLINE 49 | #define R123_STATIC_INLINE static __inline 50 | #endif 51 | 52 | #ifndef R123_FORCE_INLINE 53 | #define R123_FORCE_INLINE(decl) _forceinline decl 54 | #endif 55 | 56 | #ifndef R123_CUDA_DEVICE 57 | #define R123_CUDA_DEVICE 58 | #endif 59 | 60 | #ifndef R123_ASSERT 61 | #include 62 | #define R123_ASSERT(x) assert(x) 63 | #endif 64 | 65 | #ifndef R123_BUILTIN_EXPECT 66 | #define R123_BUILTIN_EXPECT(expr,likely) expr 67 | #endif 68 | 69 | // The basic idiom is: 70 | // #ifndef R123_SOMETHING 71 | // #if some condition 72 | // #define R123_SOMETHING 1 73 | // #else 74 | // #define R123_SOMETHING 0 75 | // #endif 76 | // #endif 77 | // This idiom allows an external user to override any decision 78 | // in this file with a command-line -DR123_SOMETHING=1 or -DR123_SOMETHINE=0 79 | 80 | // An alternative idiom is: 81 | // #ifndef R123_SOMETHING 82 | // #define R123_SOMETHING (some boolean expression) 83 | // #endif 84 | // where the boolean expression might contain previously-defined R123_SOMETHING_ELSE 85 | // pp-symbols. 86 | 87 | #ifndef R123_USE_AES_NI 88 | #if defined(_M_X64) 89 | #define R123_USE_AES_NI 1 90 | #else 91 | #define R123_USE_AES_NI 0 92 | #endif 93 | #endif 94 | 95 | #ifndef R123_USE_SSE4_2 96 | #if defined(_M_X64) 97 | #define R123_USE_SSE4_2 1 98 | #else 99 | #define R123_USE_SSE4_2 0 100 | #endif 101 | #endif 102 | 103 | #ifndef R123_USE_SSE4_1 104 | #if defined(_M_X64) 105 | #define R123_USE_SSE4_1 1 106 | #else 107 | #define R123_USE_SSE4_1 0 108 | #endif 109 | #endif 110 | 111 | #ifndef R123_USE_SSE 112 | #define R123_USE_SSE 1 113 | #endif 114 | 115 | #ifndef R123_USE_AES_OPENSSL 116 | #define R123_USE_AES_OPENSSL 0 117 | #endif 118 | 119 | #ifndef R123_USE_GNU_UINT128 120 | #define R123_USE_GNU_UINT128 0 121 | #endif 122 | 123 | #ifndef R123_USE_ASM_GNU 124 | #define R123_USE_ASM_GNU 0 125 | #endif 126 | 127 | #ifndef R123_USE_CPUID_MSVC 128 | #define R123_USE_CPUID_MSVC 1 129 | #endif 130 | 131 | #ifndef R123_USE_X86INTRIN_H 132 | #define R123_USE_X86INTRIN_H 0 133 | #endif 134 | 135 | #ifndef R123_USE_IA32INTRIN_H 136 | #define R123_USE_IA32INTRIN_H 0 137 | #endif 138 | 139 | #ifndef R123_USE_XMMINTRIN_H 140 | #define R123_USE_XMMINTRIN_H 0 141 | #endif 142 | 143 | #ifndef R123_USE_EMMINTRIN_H 144 | #define R123_USE_EMMINTRIN_H 1 145 | #endif 146 | 147 | #ifndef R123_USE_SMMINTRIN_H 148 | #define R123_USE_SMMINTRIN_H 1 149 | #endif 150 | 151 | #ifndef R123_USE_WMMINTRIN_H 152 | #define R123_USE_WMMINTRIN_H 1 153 | #endif 154 | 155 | #ifndef R123_USE_INTRIN_H 156 | #define R123_USE_INTRIN_H 1 157 | #endif 158 | 159 | #ifndef R123_USE_MULHILO16_ASM 160 | #define R123_USE_MULHILO16_ASM 0 161 | #endif 162 | 163 | #ifndef R123_USE_MULHILO32_ASM 164 | #define R123_USE_MULHILO32_ASM 0 165 | #endif 166 | 167 | #ifndef R123_USE_MULHILO64_ASM 168 | #define R123_USE_MULHILO64_ASM 0 169 | #endif 170 | 171 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 172 | #if defined(_M_X64) 173 | #define R123_USE_MULHILO64_MSVC_INTRIN 1 174 | #else 175 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 176 | #endif 177 | #endif 178 | 179 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 180 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 181 | #endif 182 | 183 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 184 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 185 | #endif 186 | 187 | #ifndef __STDC_CONSTANT_MACROS 188 | #define __STDC_CONSTANT_MACROS 189 | #endif 190 | #include 191 | #ifndef UINT64_C 192 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 193 | #endif 194 | 195 | #pragma warning(disable:4244) 196 | #pragma warning(disable:4996) 197 | 198 | // If you add something, it must go in all the other XXfeatures.hpp 199 | // and in ../ut_features.cpp 200 | #endif 201 | -------------------------------------------------------------------------------- /src/library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # *********************************************************************** 3 | # Copyright (c) 2015 Advanced Micro Devices, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions 8 | # are met: 9 | # 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | # *********************************************************************** 30 | 31 | # ######################################################################## 32 | 33 | 34 | # List the names of common files to compile across all platforms 35 | set( clRNG.Source clRNG.c 36 | private.c 37 | mrg32k3a.c 38 | mrg31k3p.c 39 | lfsr113.c 40 | philox432.c 41 | ) 42 | 43 | if( MSVC ) 44 | if( MSVC_VERSION LESS 1800 ) 45 | # Use C++ with Microsoft compiler 46 | SET_SOURCE_FILES_PROPERTIES( ${clRNG.Source} PROPERTIES LANGUAGE CXX) 47 | endif () 48 | endif( ) 49 | 50 | # Windows only uses dllmain 51 | #if( MSVC ) 52 | # set( clRNG.Source ${clRNG.Source} dllmain.cpp ) 53 | #endif( ) 54 | 55 | set( clRNG.Headers private.h 56 | ../include/clRNG/clRNG.h 57 | ../include/clRNG/mrg32k3a.h 58 | ../include/clRNG/mrg31k3p.h 59 | ../include/clRNG/lfsr113.h 60 | ../include/clRNG/philox432.h 61 | ) 62 | 63 | set( clRNG.Files ${clRNG.Source} ${clRNG.Headers} ) 64 | 65 | # Include standard OpenCL headers 66 | include_directories( ${OPENCL_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include ../include ) 67 | 68 | if(BUILD_SHARED_LIBRARY) 69 | add_library( clRNG SHARED ${clRNG.Files} ) 70 | else() 71 | add_library( clRNG STATIC ${clRNG.Files} ) 72 | endif() 73 | target_link_libraries( clRNG ${OPENCL_LIBRARIES} ) 74 | 75 | set_target_properties( clRNG PROPERTIES VERSION ${CLRNG_VERSION} ) 76 | set_target_properties( clRNG PROPERTIES SOVERSION ${CLRNG_SOVERSION} ) 77 | set_target_properties( clRNG PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 78 | 79 | if( CMAKE_COMPILER_IS_GNUCC ) 80 | configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/clRNG.pc.in 81 | ${CMAKE_CURRENT_BINARY_DIR}/clRNG.pc @ONLY ) 82 | 83 | install( FILES ${CMAKE_CURRENT_BINARY_DIR}/clRNG.pc 84 | DESTINATION lib${SUFFIX_LIB}/pkgconfig ) 85 | endif( ) 86 | 87 | # CPack configuration; include the executable into the package 88 | install( TARGETS clRNG 89 | EXPORT clRNG-Targets 90 | RUNTIME DESTINATION bin${SUFFIX_BIN} 91 | LIBRARY DESTINATION lib${SUFFIX_LIB} 92 | ARCHIVE DESTINATION lib${SUFFIX_LIB}/import 93 | ) 94 | 95 | # CMake config files for clRNG 96 | include( CMakePackageConfigHelpers ) 97 | 98 | set( LIB_INSTALL_DIR lib${SUFFIX_LIB} ) 99 | set( INCLUDE_INSTALL_DIR include ) 100 | set( ConfigPackageLocation ${LIB_INSTALL_DIR}/cmake/clRNG ) 101 | 102 | configure_package_config_file( 103 | clRNGConfig.cmake.in 104 | ${CMAKE_CURRENT_BINARY_DIR}/clRNGConfig.cmake 105 | INSTALL_DESTINATION ${ConfigPackageLocation} 106 | PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR 107 | ) 108 | 109 | write_basic_package_version_file( 110 | ${CMAKE_CURRENT_BINARY_DIR}/clRNGConfigVersion.cmake 111 | VERSION ${CLRNG_VERSION} 112 | COMPATIBILITY SameMajorVersion 113 | ) 114 | 115 | # This generates the files that defines the import targets 116 | install( EXPORT clRNG-Targets 117 | DESTINATION 118 | ${ConfigPackageLocation} 119 | ) 120 | 121 | #Copy the config files generated by configure_package_config_file & write_basic_package_version_file 122 | install(FILES 123 | ${CMAKE_CURRENT_BINARY_DIR}/clRNGConfig.cmake 124 | ${CMAKE_CURRENT_BINARY_DIR}/clRNGConfigVersion.cmake 125 | DESTINATION 126 | ${ConfigPackageLocation} ) 127 | 128 | # For debug builds, include the debug runtimes into the package for testing on non-developer machines 129 | set( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP true ) 130 | set( CMAKE_INSTALL_DEBUG_LIBRARIES true ) 131 | set( CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY true ) 132 | 133 | if( WIN32 ) 134 | set( CLRNG_RUNTIME_DESTINATION bin${SUFFIX_BIN} ) 135 | else( ) 136 | set( CLRNG_RUNTIME_DESTINATION lib${SUFFIX_LIB} ) 137 | endif( ) 138 | 139 | include( InstallRequiredSystemLibraries ) 140 | 141 | # Install necessary runtime files for debug builds 142 | install( PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} 143 | CONFIGURATIONS Debug 144 | DESTINATION ${CLRNG_RUNTIME_DESTINATION} ) 145 | 146 | # Install all *.pdb files for debug builds 147 | install( DIRECTORY ${PROJECT_BINARY_DIR}/staging/ 148 | DESTINATION ${CLRNG_RUNTIME_DESTINATION} 149 | OPTIONAL 150 | CONFIGURATIONS Debug 151 | FILES_MATCHING PATTERN "*.pdb" ) 152 | 153 | # Install a snapshot of the source as it was for this build; useful for the .pdb's 154 | install( DIRECTORY ${PROJECT_SOURCE_DIR} 155 | DESTINATION ${CLRNG_RUNTIME_DESTINATION} 156 | OPTIONAL 157 | CONFIGURATIONS Debug ) 158 | -------------------------------------------------------------------------------- /src/client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # *********************************************************************** 3 | # Copyright (c) 2015 Advanced Micro Devices, Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions 8 | # are met: 9 | # 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | # 29 | # *********************************************************************** 30 | 31 | # ######################################################################## 32 | 33 | 34 | 35 | set( Common.Headers common.h ../include/clRNG/clRNG.h ../include/clRNG/mrg31k3p.h ) 36 | set( Common.Source common.c ) 37 | 38 | # workitem 39 | set( WorkItem.Source WorkItem/workitem.c ${Common.Source} ) 40 | set( WorkItem.Headers ${Common.Headers} ) 41 | set( WorkItem.Files ${WorkItem.Source} ${WorkItem.Headers} WorkItem/workitem_kernel.cl ) 42 | 43 | # multistream 44 | set( MultiStream.Source MultiStream/multistream.c ${Common.Source} ) 45 | set( MultiStream.Headers ${Common.Headers} ) 46 | set( MultiStream.Files ${MultiStream.Source} ${MultiStream.Headers} ) 47 | 48 | # hostonly 49 | set( HostOnly.Source HostOnly/hostonly.c ${Common.Source} ) 50 | set( HostOnly.Headers ${Common.Headers} ) 51 | set( HostOnly.Files ${HostOnly.Source} ${HostOnly.Headers} ) 52 | 53 | # randomarray 54 | set( RandomArray.Source RandomArray/randomarray.c ${Common.Source} ) 55 | set( RandomArray.Headers ${Common.Headers} ) 56 | set( RandomArray.Files ${RandomArray.Source} ${RandomArray.Headers} ) 57 | 58 | set( Inventory.Source 59 | Inventory/inventory.c 60 | Inventory/Policies.c 61 | Inventory/SimulateRuns.c 62 | ${Common.Source} ) 63 | set( Inventory.Headers 64 | Inventory/Policies.h 65 | Inventory/SimulateRuns.h 66 | ${Common.Headers} ) 67 | set( Inventory.Files ${Inventory.Source} ${Inventory.Headers} 68 | Inventory/InventoryKernels.cl ) 69 | 70 | set( Client.Source ${WorkItem.Source} ${MultiStream.Source} ${HostOnly.Source} ${RandomArray.Source} ${Inventory.Source} ) 71 | 72 | if( MSVC ) 73 | if( MSVC_VERSION LESS 1800 ) 74 | # Use C++ with Microsoft compiler 75 | SET_SOURCE_FILES_PROPERTIES( ${Client.Source} PROPERTIES LANGUAGE CXX) 76 | endif () 77 | endif( ) 78 | 79 | set( DL_LIB "" ) 80 | if( WIN32 ) 81 | add_definitions( "/D_CONSOLE" ) 82 | elseif( APPLE ) 83 | set( CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}" ) 84 | else( ) 85 | # To use the dlopen() and dlclose() functions, we should link with libdl 86 | set( DL_LIB "-ldl" ) 87 | endif( ) 88 | 89 | if( CMAKE_COMPILER_IS_GNUCC ) 90 | set( MATH_LIB "-lm" ) 91 | endif() 92 | 93 | # Include standard OpenCL headers 94 | include_directories( ${OPENCL_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include ../include ) 95 | 96 | add_executable( WorkItem ${WorkItem.Files} ) 97 | add_executable( MultiStream ${MultiStream.Files} ) 98 | add_executable( HostOnly ${HostOnly.Files} ) 99 | add_executable( RandomArray ${RandomArray.Files} ) 100 | add_executable( Inventory ${Inventory.Files} ) 101 | 102 | target_link_libraries( WorkItem clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 103 | target_link_libraries( MultiStream clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 104 | target_link_libraries( HostOnly clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 105 | target_link_libraries( RandomArray clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 106 | target_link_libraries( Inventory clRNG ${OPENCL_LIBRARIES} ${DL_LIB} ${MATH_LIB} ) 107 | 108 | set_target_properties( WorkItem PROPERTIES VERSION ${CLRNG_VERSION} ) 109 | set_target_properties( WorkItem PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 110 | 111 | set_target_properties( MultiStream PROPERTIES VERSION ${CLRNG_VERSION} ) 112 | set_target_properties( MultiStream PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 113 | 114 | set_target_properties( HostOnly PROPERTIES VERSION ${CLRNG_VERSION} ) 115 | set_target_properties( HostOnly PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 116 | 117 | set_target_properties( RandomArray PROPERTIES VERSION ${CLRNG_VERSION} ) 118 | set_target_properties( RandomArray PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 119 | 120 | set_target_properties( Inventory PROPERTIES VERSION ${CLRNG_VERSION} ) 121 | set_target_properties( Inventory PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging" ) 122 | 123 | # CPack configuration; include the executable into the package 124 | install( TARGETS WorkItem MultiStream HostOnly RandomArray Inventory 125 | RUNTIME DESTINATION bin${SUFFIX_BIN} 126 | LIBRARY DESTINATION lib${SUFFIX_LIB} 127 | ARCHIVE DESTINATION lib${SUFFIX_LIB}/import 128 | ) 129 | 130 | install( FILES 131 | "WorkItem/workitem_kernel.cl" 132 | DESTINATION 133 | "./client/WorkItem" ) 134 | 135 | install( FILES 136 | "Inventory/InventoryKernels.cl" 137 | DESTINATION 138 | "./client/Inventory" ) 139 | -------------------------------------------------------------------------------- /src/client/Inventory/inventory.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #include 34 | #include 35 | #include "../common.h" 36 | #include "Types.h" 37 | #include "Policies.h" 38 | 39 | 40 | int main() 41 | { 42 | printf("Please type a number followed by ENTER: \n\n"); 43 | 44 | printf(" One Policy : \n"); 45 | printf(" (1) - n runs on CPU, using one stream \n"); 46 | printf(" (2) - n runs with n work items, using two streams and their substreams \n"); 47 | printf(" (3) - n runs with n work items, using two arrays of n stream each \n"); 48 | printf(" (4) - n2 runs with n1 work itmes, using 2*n1 streams their substreams \n"); 49 | printf(" (5) - n2 runs with n1 work items, using 2*n2 distinct streams. \n"); 50 | 51 | printf("\n Several policies : \n"); 52 | printf(" (6) - p policies in series, with n1 work items and n2 runs per work item\n"); /*option1*/ 53 | printf(" (7) - p policies in parallel, with n1p work items and n2 runs per work item \n"); /*option2*/ 54 | 55 | int m = 10; // number of days 56 | int n = 1 << 20; // number of runs 57 | int n1 = 1 << 10; // number of workitems that will simulate n2 runs 58 | 59 | 60 | //Policies values 61 | int s[] = { 80, 80 }; 62 | int S[] = { 200, 198}; 63 | int P = 2; // number of policies 64 | 65 | cl_device_type device_type = CL_DEVICE_TYPE_GPU; 66 | int platform_index = 0; 67 | int device_index = 0; 68 | int ret = 0; 69 | 70 | int funcNbr; 71 | printf("\n Choice (0 to quit) : "); 72 | scanf(" %d", &funcNbr); getchar(); 73 | 74 | //Simulate different options : 75 | while (funcNbr != 0) 76 | { 77 | switch (funcNbr) 78 | { 79 | case 1: { 80 | printf("\n===========================================================================\n ONE POLICY:\n=============\n"); 81 | printf("+++++++++ On CPU (basic case): One policy, one stream \n"); 82 | OnePolicyData data = { n, 0, m, s[0], S[0], basic }; 83 | ret = call_with_opencl(platform_index, device_type, device_index, &one_Policy, &data, true); 84 | 85 | break; 86 | } 87 | case 2: { 88 | printf("\n===========================================================================\n ONE POLICY:\n=============\n"); 89 | printf("+++++++++ On CPU (case a) : One policy, two streams with their substreams \n"); 90 | OnePolicyData data = { n, 0, m, s[0], S[0], Case_a }; 91 | ret = call_with_opencl(platform_index, device_type, device_index, &one_Policy, &data, true); 92 | break; 93 | } 94 | case 3: { 95 | printf("\n===========================================================================\n ONE POLICY:\n=============\n"); 96 | printf("+++++++++ On CPU (case b): One policy, two arrays of n streams each \n"); 97 | OnePolicyData data = { n, 0, m, s[0], S[0], Case_b }; 98 | ret = call_with_opencl(platform_index, device_type, device_index, &one_Policy, &data, true); 99 | break; 100 | } 101 | case 4: { 102 | printf("\n===========================================================================\n ONE POLICY:\n=============\n"); 103 | //no CPU implementation : (case c) 104 | OnePolicyData data = { n, n1, m, s[0], S[0], Case_c }; 105 | ret = call_with_opencl(platform_index, device_type, device_index, &one_Policy, &data, true); 106 | break; 107 | } 108 | case 5: { 109 | printf("\n===========================================================================\n ONE POLICY:\n=============\n"); 110 | //no CPU implementation : (case d) 111 | OnePolicyData data = { n, n1, m, s[0], S[0], Case_d }; 112 | ret = call_with_opencl(platform_index, device_type, device_index, &one_Policy, &data, true); 113 | break; 114 | } 115 | case 6: { 116 | printf("\n===========================================================================\n Several policies Option1:\n=========\n"); 117 | //no CPU implementation : Several policies (option 1) 118 | SeveralPoliciesData data = { n, n1, m, s, S, P, Option1 }; 119 | ret = call_with_opencl(platform_index, device_type, device_index, &several_Policies, &data, true); 120 | break; 121 | } 122 | case 7: { 123 | printf("\n===========================================================================\n Several policies Option2:\n=========\n"); 124 | //no CPU implementation : Several policies (option 2) 125 | SeveralPoliciesData data = { n, n1, m, s, S, P, Option2 }; 126 | ret = call_with_opencl(platform_index, device_type, device_index, &several_Policies, &data, false); 127 | break; 128 | } 129 | 130 | default: 131 | break; 132 | } 133 | 134 | printf("\n Choice (0 to quit) : "); 135 | scanf(" %d", &funcNbr); 136 | } 137 | 138 | return ret; 139 | } 140 | -------------------------------------------------------------------------------- /src/client/anyrng.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file anyrng.h 34 | * @brief Link names of the generic API to a given RNG's API. 35 | * 36 | * The purposose of this file is to facilitate testing the examples against 37 | * different RNG implementations. 38 | * 39 | * Exactly one of the preprocessor symbols \c USE_MRG31K3P, \c USE_MRG32K3A or 40 | * \c USE_LFSR113 must be defined before including this header file. 41 | * 42 | * The following preprocessor symbols are defined: 43 | * - \c RNG_HOST_HEADER expands to the name of the RNG header file for the 44 | * host code, surrounded with angle brackets; 45 | * - \c RNG_DEVICE_HEADER expands to the name of the RNG header file for the 46 | * device code, surrounded with angle brackets; 47 | * - \c RNG_PREFIX expands to the RNG prefix that is normally expanded after 48 | * the common \c clrng prefix, e.g., \c Mrg31k3p for the MRG31k3p RNG; 49 | * host code, surrounded with angle brackets; 50 | * - \c RNG_PREFIX_S and \c RNG_DEVICE_HEADER_S respectively expand to the 51 | * values of \c RNG_PREFIX and \c RNG_DEVICE_HEADER, but surrounded with 52 | * quotes (stringified); 53 | * - \c RNG_DEVICE_HEADER expands to the name of the RNG header file for the 54 | * device code, surrounded with angle brackets; 55 | * - the clRNG API types and functions in a generic form, i.e., without the 56 | * name of the RNG expanded after the \c clrng prefix. 57 | * 58 | * To use the MRG31k3p generator, write: 59 | * 60 | * #define USE_MRG31K3P 61 | * #include 62 | */ 63 | 64 | #if defined(USE_MRG31K3P) && !defined(USE_MRG32K3A) && !defined(USE_LFSR113) 65 | #define RNG_PREFIX Mrg31k3p 66 | #define RNG_HEADER_NAME mrg31k3p 67 | #elif defined(USE_MRG32K3A) && !defined(USE_LFSR113) 68 | #define RNG_PREFIX Mrg32k3a 69 | #define RNG_HEADER_NAME mrg32k3a 70 | #elif defined(USE_LFSR113) 71 | #define RNG_PREFIX Lfsr113 72 | #define RNG_HEADER_NAME lfsr113 73 | #else 74 | #error Exactly one of USE_MRG31K3P, USE_MRG32K3A or USE_LFSR113 must be defined. 75 | #endif 76 | 77 | #define RNG_HOST_HEADER 78 | #define RNG_DEVICE_HEADER 79 | 80 | #define RNG_MEMBER_(rng, ident) RNG_MEMBER__(rng, ident) 81 | #define RNG_MEMBER__(rng, ident) clrng ## rng ## ident 82 | 83 | #define RNG_STR_(x) RNG_STR__(x) 84 | #define RNG_STR__(x) #x 85 | 86 | #define RNG_PREFIX_S RNG_STR_(RNG_PREFIX) 87 | #define RNG_DEVICE_HEADER_S RNG_STR_(RNG_DEVICE_HEADER) 88 | 89 | 90 | #include RNG_HOST_HEADER 91 | 92 | #define clrngStreamState RNG_MEMBER_(RNG_PREFIX, StreamState) 93 | #define clrngStream RNG_MEMBER_(RNG_PREFIX, Stream) 94 | #define clrngStreamCreator RNG_MEMBER_(RNG_PREFIX, StreamCreator) 95 | #define clrngCopyStreamCreator RNG_MEMBER_(RNG_PREFIX, CopyStreamCreator) 96 | #define clrngDestroyStreamCreator RNG_MEMBER_(RNG_PREFIX, DestroyStreamCreator) 97 | #define clrngSetBaseCreatorState RNG_MEMBER_(RNG_PREFIX, SetBaseCreatorState) 98 | #define clrngChangeStreamsSpacing RNG_MEMBER_(RNG_PREFIX, ChangeStreamsSpacing) 99 | #define clrngAllocStreams RNG_MEMBER_(RNG_PREFIX, AllocStreams) 100 | #define clrngDestroyStreams RNG_MEMBER_(RNG_PREFIX, DestroyStreams) 101 | #define clrngCreateStreams RNG_MEMBER_(RNG_PREFIX, CreateStreams) 102 | #define clrngCreateOverStreams RNG_MEMBER_(RNG_PREFIX, CreateOverStreams) 103 | #define clrngCopyStreams RNG_MEMBER_(RNG_PREFIX, CopyStreams) 104 | #define clrngCopyOverStreams RNG_MEMBER_(RNG_PREFIX, CopyOverStreams) 105 | #define clrngRandomU01 RNG_MEMBER_(RNG_PREFIX, RandomU01) 106 | #define clrngRandomInteger RNG_MEMBER_(RNG_PREFIX, RandomInteger) 107 | #define clrngRandomU01Array RNG_MEMBER_(RNG_PREFIX, RandomU01Array) 108 | #define clrngRandomIntegerArray RNG_MEMBER_(RNG_PREFIX, RandomIntegerArray) 109 | #define clrngRewindStreams RNG_MEMBER_(RNG_PREFIX, RewindStreams) 110 | #define clrngRewindSubstreams RNG_MEMBER_(RNG_PREFIX, RewindSubstreams) 111 | #define clrngForwardToNextSubstreams RNG_MEMBER_(RNG_PREFIX, ForwardToNextSubstreams) 112 | #define clrngMakeSubstreams RNG_MEMBER_(RNG_PREFIX, MakeSubstreams) 113 | #define clrngMakeOverSubstreams RNG_MEMBER_(RNG_PREFIX, MakeOverSubstreams) 114 | #define clrngAdvanceSubstreams RNG_MEMBER_(RNG_PREFIX, AdvanceSubstreams) 115 | #define clrngDeviceRandomU01Array RNG_MEMBER_(RNG_PREFIX, DeviceRandomU01Array) 116 | #define clrngWriteStreamInfo RNG_MEMBER_(RNG_PREFIX, WriteStreamInfo) 117 | 118 | #ifdef __CLRNG_DEVICE_API 119 | #define clrngCopyOverStreamsFromGlobal RNG_MEMBER_(RNG_PREFIX, CopyOverStreamsFromGlobal) 120 | #define clrngCopyOverStreamsToGlobal RNG_MEMBER_(RNG_PREFIX, CopyOverStreamsToGlobal) 121 | #endif 122 | 123 | -------------------------------------------------------------------------------- /src/include/clRNG/lfsr113.clh: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file lfsr113.clh 34 | * @brief Specific device interface for the lfsr113 generator 35 | * 36 | * The functions defined in this file are not documented here. Refer to the 37 | * documentation of lfsr113.h. 38 | */ 39 | 40 | #pragma once 41 | #ifndef LFSR113_CLH 42 | #define LFSR113_CLH 43 | 44 | #include 45 | 46 | 47 | /******************************************************************************** 48 | * Functions and types declarations * 49 | ********************************************************************************/ 50 | 51 | typedef struct { 52 | /*! @brief Seed for the lfsr113 generator 53 | */ 54 | cl_uint g[4]; 55 | 56 | } clrngLfsr113StreamState; 57 | 58 | struct clrngLfsr113Stream_ { 59 | clrngLfsr113StreamState current; 60 | #if __OPENCL_C_VERSION__ >= 200 61 | // use generic address space 62 | const clrngLfsr113StreamState* initial; 63 | #else 64 | // force global address space 65 | __global const clrngLfsr113StreamState* initial; 66 | #endif 67 | #ifdef CLRNG_ENABLE_SUBSTREAMS 68 | clrngLfsr113StreamState substream; 69 | #endif 70 | }; 71 | typedef struct clrngLfsr113Stream_ clrngLfsr113Stream; 72 | 73 | struct clrngLfsr113HostStream_ { 74 | clrngLfsr113StreamState current; 75 | clrngLfsr113StreamState initial; 76 | clrngLfsr113StreamState substream; 77 | }; 78 | typedef struct clrngLfsr113HostStream_ clrngLfsr113HostStream; 79 | 80 | clrngStatus clrngLfsr113CopyOverStreamsFromGlobal(size_t count, clrngLfsr113Stream* destStreams, __global const clrngLfsr113HostStream* srcStreams); 81 | clrngStatus clrngLfsr113CopyOverStreamsToGlobal(size_t count, __global clrngLfsr113HostStream* destStreams, const clrngLfsr113Stream* srcStreams); 82 | clrngStatus clrngLfsr113CopyOverStreams(size_t count, clrngLfsr113Stream* destStreams, const clrngLfsr113Stream* srcStreams); 83 | 84 | #define clrngLfsr113RandomU01 _CLRNG_TAG_FPTYPE(clrngLfsr113RandomU01) 85 | #define clrngLfsr113RandomInteger _CLRNG_TAG_FPTYPE(clrngLfsr113RandomInteger) 86 | #define clrngLfsr113RandomU01Array _CLRNG_TAG_FPTYPE(clrngLfsr113RandomU01Array) 87 | #define clrngLfsr113RandomIntegerArray _CLRNG_TAG_FPTYPE(clrngLfsr113RandomIntegerArray) 88 | 89 | _CLRNG_FPTYPE clrngLfsr113RandomU01(clrngLfsr113Stream* stream); 90 | clrngStatus clrngLfsr113RandomU01Array(clrngLfsr113Stream* stream, size_t count, _CLRNG_FPTYPE* buffer); 91 | cl_int clrngLfsr113RandomInteger(clrngLfsr113Stream* stream, cl_int i, cl_int j); 92 | clrngStatus clrngLfsr113RandomIntegerArray(clrngLfsr113Stream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer); 93 | 94 | clrngStatus clrngLfsr113RewindStreams(size_t count, clrngLfsr113Stream* streams); 95 | 96 | #ifdef CLRNG_ENABLE_SUBSTREAMS 97 | clrngStatus clrngLfsr113RewindSubstreams(size_t count, clrngLfsr113Stream* streams); 98 | clrngStatus clrngLfsr113ForwardToNextSubstreams(size_t count, clrngLfsr113Stream* streams); 99 | clrngStatus clrngLfsr113MakeOverSubstreams(clrngLfsr113Stream* stream, size_t count, clrngLfsr113Stream* substreams); 100 | #endif 101 | 102 | 103 | 104 | /******************************************************************************** 105 | * Implementation * 106 | ********************************************************************************/ 107 | 108 | clrngStatus clrngLfsr113CopyOverStreamsFromGlobal(size_t count, clrngLfsr113Stream* destStreams, __global const clrngLfsr113HostStream* srcStreams) 109 | { 110 | //Check params 111 | if (!destStreams) 112 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngLfsr113CopyOverStreamsFromGlobal(): destStreams cannot be NULL"); 113 | if (!srcStreams) 114 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngLfsr113CopyOverStreamsFromGlobal(): srcStreams cannot be NULL"); 115 | 116 | for (size_t i = 0; i < count; i++) { 117 | destStreams[i].current = srcStreams[i].current; 118 | destStreams[i].initial = &srcStreams[i].initial; 119 | #ifdef CLRNG_ENABLE_SUBSTREAMS 120 | destStreams[i].substream = srcStreams[i].substream; 121 | #endif 122 | } 123 | 124 | return CLRNG_SUCCESS; 125 | } 126 | 127 | clrngStatus clrngLfsr113CopyOverStreamsToGlobal(size_t count, __global clrngLfsr113HostStream* destStreams, const clrngLfsr113Stream* srcStreams) 128 | { 129 | //Check params 130 | if (!destStreams) 131 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngLfsr113CopyOverStreamsToGlobal(): destStreams cannot be NULL"); 132 | if (!srcStreams) 133 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngLfsr113CopyOverStreamsToGlobal(): srcStreams cannot be NULL"); 134 | 135 | for (size_t i = 0; i < count; i++) { 136 | destStreams[i].current = srcStreams[i].current; 137 | destStreams[i].initial = *srcStreams[i].initial; 138 | #ifdef CLRNG_ENABLE_SUBSTREAMS 139 | destStreams[i].substream = srcStreams[i].substream; 140 | #endif 141 | } 142 | 143 | return CLRNG_SUCCESS; 144 | } 145 | 146 | // code that is common to host and device 147 | #include 148 | 149 | #endif 150 | 151 | /* 152 | vim: ft=c sw=4 153 | */ 154 | -------------------------------------------------------------------------------- /src/include/clRNG/philox432.clh: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file Philox432.clh 34 | * @brief Specific device interface for the Philox432 generator 35 | * 36 | * The functions defined in this file are not documented here. Refer to the 37 | * documentation of philox432.h. 38 | */ 39 | 40 | #pragma once 41 | #ifndef PHILOX432_CLH 42 | #define PHILOX432_CLH 43 | 44 | #include 45 | 46 | 47 | /******************************************************************************** 48 | * Functions and types declarations * 49 | ********************************************************************************/ 50 | 51 | typedef struct clrngPhilox432SB_ { 52 | cl_uint msb, lsb; //most significant bits, and the least significant bits 53 | }clrngPhilox432SB; 54 | 55 | typedef struct clrngPhilox432Counter_ { 56 | clrngPhilox432SB H, L; 57 | } clrngPhilox432Counter; 58 | 59 | 60 | typedef struct { 61 | clrngPhilox432Counter ctr; // 128 bits counter 62 | cl_uint deck[4]; // this table hold the 4x32 generated uint from philox4x32(ctr,kry) function 63 | cl_uint deckIndex; //the index of actual pregenerated integer to give to the user 64 | } clrngPhilox432StreamState; 65 | 66 | 67 | struct clrngPhilox432Stream_ { 68 | clrngPhilox432StreamState current; 69 | #if __OPENCL_C_VERSION__ >= 200 70 | // use generic address space 71 | const clrngPhilox432StreamState* initial; 72 | #else 73 | // force global address space 74 | __global const clrngPhilox432StreamState* initial; 75 | #endif 76 | #ifdef CLRNG_ENABLE_SUBSTREAMS 77 | clrngPhilox432StreamState substream; 78 | #endif 79 | }; 80 | typedef struct clrngPhilox432Stream_ clrngPhilox432Stream; 81 | 82 | struct clrngPhilox432HostStream_ { 83 | clrngPhilox432StreamState current; 84 | clrngPhilox432StreamState initial; 85 | clrngPhilox432StreamState substream; 86 | }; 87 | typedef struct clrngPhilox432HostStream_ clrngPhilox432HostStream; 88 | 89 | clrngStatus clrngPhilox432CopyOverStreamsFromGlobal(size_t count, clrngPhilox432Stream* destStreams, __global const clrngPhilox432HostStream* srcStreams); 90 | clrngStatus clrngPhilox432CopyOverStreamsToGlobal(size_t count, __global clrngPhilox432HostStream* destStreams, const clrngPhilox432Stream* srcStreams); 91 | clrngStatus clrngPhilox432CopyOverStreams(size_t count, clrngPhilox432Stream* destStreams, const clrngPhilox432Stream* srcStreams); 92 | 93 | #define clrngPhilox432RandomU01 _CLRNG_TAG_FPTYPE(clrngPhilox432RandomU01) 94 | #define clrngPhilox432RandomInteger _CLRNG_TAG_FPTYPE(clrngPhilox432RandomInteger) 95 | #define clrngPhilox432RandomU01Array _CLRNG_TAG_FPTYPE(clrngPhilox432RandomU01Array) 96 | #define clrngPhilox432RandomIntegerArray _CLRNG_TAG_FPTYPE(clrngPhilox432RandomIntegerArray) 97 | 98 | clrngStatus clrngPhilox432RewindStreams(size_t count, clrngPhilox432Stream* streams); 99 | 100 | #ifdef CLRNG_ENABLE_SUBSTREAMS 101 | clrngStatus clrngPhilox432RewindSubstreams(size_t count, clrngPhilox432Stream* streams); 102 | clrngStatus clrngPhilox432ForwardToNextSubstreams(size_t count, clrngPhilox432Stream* streams); 103 | clrngStatus clrngPhilox432MakeOverSubstreams(clrngPhilox432Stream* stream, size_t count, clrngPhilox432Stream* substreams); 104 | #endif 105 | 106 | 107 | 108 | /******************************************************************************** 109 | * Implementation * 110 | ********************************************************************************/ 111 | 112 | clrngStatus clrngPhilox432CopyOverStreamsFromGlobal(size_t count, clrngPhilox432Stream* destStreams, __global const clrngPhilox432HostStream* srcStreams) 113 | { 114 | //Check params 115 | if (!destStreams) 116 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngPhilox432CopyOverStreamsFromGlobal(): destStreams cannot be NULL"); 117 | if (!srcStreams) 118 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngPhilox432CopyOverStreamsFromGlobal(): srcStreams cannot be NULL"); 119 | 120 | for (size_t i = 0; i < count; i++) { 121 | destStreams[i].current = srcStreams[i].current; 122 | destStreams[i].initial = &srcStreams[i].initial; 123 | #ifdef CLRNG_ENABLE_SUBSTREAMS 124 | destStreams[i].substream = srcStreams[i].substream; 125 | #endif 126 | } 127 | 128 | return CLRNG_SUCCESS; 129 | } 130 | 131 | clrngStatus clrngPhilox432CopyOverStreamsToGlobal(size_t count, __global clrngPhilox432HostStream* destStreams, const clrngPhilox432Stream* srcStreams) 132 | { 133 | //Check params 134 | if (!destStreams) 135 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngPhilox432CopyOverStreamsToGlobal(): destStreams cannot be NULL"); 136 | if (!srcStreams) 137 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngPhilox432CopyOverStreamsToGlobal(): srcStreams cannot be NULL"); 138 | 139 | for (size_t i = 0; i < count; i++) { 140 | destStreams[i].current = srcStreams[i].current; 141 | destStreams[i].initial = *srcStreams[i].initial; 142 | #ifdef CLRNG_ENABLE_SUBSTREAMS 143 | destStreams[i].substream = srcStreams[i].substream; 144 | #endif 145 | } 146 | 147 | return CLRNG_SUCCESS; 148 | } 149 | 150 | // code that is common to host and device 151 | #include 152 | 153 | #endif 154 | 155 | /* 156 | vim: ft=c sw=4 157 | */ -------------------------------------------------------------------------------- /src/include/clRNG/mrg32k3a.clh: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file Mrg32k3a.clh 34 | * @brief Specific device interface for the Mrg32k3a generator 35 | * 36 | * The functions defined in this file are not documented here. Refer to the 37 | * documentation of Mrg32k3a.h. 38 | */ 39 | 40 | #pragma once 41 | #ifndef MRG32K3A_CLH 42 | #define MRG32K3A_CLH 43 | 44 | #include 45 | 46 | 47 | /******************************************************************************** 48 | * Functions and types declarations * 49 | ********************************************************************************/ 50 | 51 | typedef struct { 52 | /*! @brief Seed for the first MRG component 53 | */ 54 | cl_ulong g1[3]; 55 | /*! @brief Seed for the second MRG component 56 | */ 57 | cl_ulong g2[3]; 58 | } clrngMrg32k3aStreamState; 59 | 60 | struct clrngMrg32k3aStream_ { 61 | clrngMrg32k3aStreamState current; 62 | #if __OPENCL_C_VERSION__ >= 200 63 | // use generic address space 64 | const clrngMrg32k3aStreamState* initial; 65 | #else 66 | // force global address space 67 | __global const clrngMrg32k3aStreamState* initial; 68 | #endif 69 | #ifdef CLRNG_ENABLE_SUBSTREAMS 70 | clrngMrg32k3aStreamState substream; 71 | #endif 72 | }; 73 | typedef struct clrngMrg32k3aStream_ clrngMrg32k3aStream; 74 | 75 | struct clrngMrg32k3aHostStream_ { 76 | clrngMrg32k3aStreamState current; 77 | clrngMrg32k3aStreamState initial; 78 | clrngMrg32k3aStreamState substream; 79 | }; 80 | typedef struct clrngMrg32k3aHostStream_ clrngMrg32k3aHostStream; 81 | 82 | clrngStatus clrngMrg32k3aCopyOverStreamsFromGlobal(size_t count, clrngMrg32k3aStream* destStreams, __global const clrngMrg32k3aHostStream* srcStreams); 83 | clrngStatus clrngMrg32k3aCopyOverStreamsToGlobal(size_t count, __global clrngMrg32k3aHostStream* destStreams, const clrngMrg32k3aStream* srcStreams); 84 | clrngStatus clrngMrg32k3aCopyOverStreams(size_t count, clrngMrg32k3aStream* destStreams, const clrngMrg32k3aStream* srcStreams); 85 | 86 | #define clrngMrg32k3aRandomU01 _CLRNG_TAG_FPTYPE(clrngMrg32k3aRandomU01) 87 | #define clrngMrg32k3aRandomInteger _CLRNG_TAG_FPTYPE(clrngMrg32k3aRandomInteger) 88 | #define clrngMrg32k3aRandomU01Array _CLRNG_TAG_FPTYPE(clrngMrg32k3aRandomU01Array) 89 | #define clrngMrg32k3aRandomIntegerArray _CLRNG_TAG_FPTYPE(clrngMrg32k3aRandomIntegerArray) 90 | 91 | _CLRNG_FPTYPE clrngMrg32k3aRandomU01(clrngMrg32k3aStream* stream); 92 | clrngStatus clrngMrg32k3aRandomU01Array(clrngMrg32k3aStream* stream, size_t count, _CLRNG_FPTYPE* buffer); 93 | 94 | cl_int clrngMrg32k3aRandomInteger(clrngMrg32k3aStream* stream, cl_int i, cl_int j); 95 | clrngStatus clrngMrg32k3aRandomIntegerArray(clrngMrg32k3aStream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer); 96 | 97 | clrngStatus clrngMrg32k3aRewindStreams(size_t count, clrngMrg32k3aStream* streams); 98 | 99 | #ifdef CLRNG_ENABLE_SUBSTREAMS 100 | clrngStatus clrngMrg32k3aRewindSubstreams(size_t count, clrngMrg32k3aStream* streams); 101 | clrngStatus clrngMrg32k3aForwardToNextSubstreams(size_t count, clrngMrg32k3aStream* streams); 102 | clrngStatus clrngMrg32k3aMakeOverSubstreams(clrngMrg32k3aStream* stream, size_t count, clrngMrg32k3aStream* substreams); 103 | #endif 104 | 105 | 106 | 107 | /******************************************************************************** 108 | * Implementation * 109 | ********************************************************************************/ 110 | 111 | clrngStatus clrngMrg32k3aCopyOverStreamsFromGlobal(size_t count, clrngMrg32k3aStream* destStreams, __global const clrngMrg32k3aHostStream* srcStreams) 112 | { 113 | //Check params 114 | if (!destStreams) 115 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg32k3aCopyOverStreamsFromGlobal(): destStreams cannot be NULL"); 116 | if (!srcStreams) 117 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg32k3aCopyOverStreamsFromGlobal(): srcStreams cannot be NULL"); 118 | 119 | for (size_t i = 0; i < count; i++) { 120 | destStreams[i].current = srcStreams[i].current; 121 | destStreams[i].initial = &srcStreams[i].initial; 122 | #ifdef CLRNG_ENABLE_SUBSTREAMS 123 | destStreams[i].substream = srcStreams[i].substream; 124 | #endif 125 | } 126 | 127 | return CLRNG_SUCCESS; 128 | } 129 | 130 | clrngStatus clrngMrg32k3aCopyOverStreamsToGlobal(size_t count, __global clrngMrg32k3aHostStream* destStreams, const clrngMrg32k3aStream* srcStreams) 131 | { 132 | //Check params 133 | if (!destStreams) 134 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg32k3aCopyOverStreamsToGlobal(): destStreams cannot be NULL"); 135 | if (!srcStreams) 136 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg32k3aCopyOverStreamsToGlobal(): srcStreams cannot be NULL"); 137 | 138 | for (size_t i = 0; i < count; i++) { 139 | destStreams[i].current = srcStreams[i].current; 140 | destStreams[i].initial = *srcStreams[i].initial; 141 | #ifdef CLRNG_ENABLE_SUBSTREAMS 142 | destStreams[i].substream = srcStreams[i].substream; 143 | #endif 144 | } 145 | 146 | return CLRNG_SUCCESS; 147 | } 148 | 149 | #ifdef CLRNG_ENABLE_SUBSTREAMS 150 | #define MODULAR_NUMBER_TYPE cl_ulong 151 | #define MODULAR_FIXED_SIZE 3 152 | #include "./private/modular.c.h" 153 | #endif 154 | 155 | // code that is common to host and device 156 | #include 157 | 158 | #endif 159 | 160 | /* 161 | vim: ft=c sw=4 162 | */ 163 | -------------------------------------------------------------------------------- /src/client/common.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #ifndef COMMON_H 34 | #define COMMON_H 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #include 43 | 44 | #if defined ( WIN32 ) 45 | #define __func__ __FUNCTION__ 46 | #endif 47 | 48 | #ifndef __cplusplus 49 | typedef enum b_ 50 | { 51 | false = 0, 52 | true =1 53 | } bool; 54 | #endif 55 | 56 | typedef enum simType_ { 57 | CPU_Exec = 1, 58 | GPU_Exec = 2 59 | } simType; 60 | 61 | typedef struct simResult_ { 62 | int ExecOption; // menu option executed = 1..7 63 | simType SimType; // CPU or GPU 64 | //Results 65 | float CPU_time; 66 | float average; 67 | float variance; 68 | float CI_low; 69 | float CI_high; 70 | 71 | } simResult; 72 | 73 | typedef struct policyPoint_{ 74 | int s, S; 75 | } policyPoint; 76 | 77 | //Confidence Interval calculation 78 | void computeCI(int n, double* statTally, simResult * results); 79 | 80 | /*! @brief Interrupt the program if an error has occurred. 81 | * 82 | * Print the error message \c msg to standard error and exists the program if 83 | * \c errcode < 0. 84 | * If \c msg is NULL, clrngGetErrorString() is invoked to obtain the message 85 | * string. 86 | */ 87 | void check_error(cl_int errcode, const char* msg, ...); 88 | 89 | /*! @brief Reads a whole file in a buffer. 90 | * 91 | * Necessary memory is allocated and must be released manually with free(). 92 | */ 93 | int read_file(const char* filename, char** pbuf); 94 | 95 | /*! @brief Retrieve the specified OpenCL device name. 96 | * 97 | * A pointer to a static memory location is returned. 98 | * It is overwritten at each call go get_device_name(). 99 | */ 100 | const char* get_device_name(cl_device_id device); 101 | 102 | /*! @brief Retrieve the specified OpenCL device version. 103 | * 104 | * A pointer to a static memory location is returned. 105 | * It is overwritten at each call go get_device_version(). 106 | */ 107 | const char* get_device_version(cl_device_id device); 108 | 109 | /*! @brief Retrieve the specified OpenCL platform name. 110 | * 111 | * A pointer to a static memory location is returned. 112 | * It is overwritten at each call go get_platform_name(). 113 | */ 114 | const char* get_platform_name(cl_platform_id platform); 115 | 116 | /*! @brief Retrieve the specified OpenCL platform version. 117 | * 118 | * A pointer to a static memory location is returned. 119 | * It is overwritten at each call go get_platform_version(). 120 | */ 121 | const char* get_platform_version(cl_platform_id platform); 122 | 123 | /*! @brief Return the maximum workgroup size on the given device. 124 | * 125 | * @note The program displays an error message and is interrupted upon error. 126 | */ 127 | size_t get_max_workgroup_size(cl_device_id device); 128 | 129 | /*! @brief Write the build log to \c file. 130 | * 131 | * @note The program displays an error message and is interrupted upon error. 132 | */ 133 | void write_build_log(FILE* file, cl_program program, cl_device_id device); 134 | 135 | /*! @brief Type of path for use with load_kernel_from_file() 136 | * 137 | */ 138 | typedef enum PathType_ { PATH_ABSOLUTE, PATH_RELATIVE_TO_LIB } PathType; 139 | 140 | /*! @brief Create and build an OpenCL probram from a source file. 141 | * @param[in] context OpenCL context. 142 | * @param[in] device OpenCL device ID. 143 | * @param[in] source_file Path to the source file, relative to the 144 | * library root specified by the environment 145 | * variable CLRNG_ROOT if \c 146 | * relative_to_lib_root is 147 | * \c PATH_RELATIVE_TO_LIB. 148 | * @param[in] path_type If PATH_RELATIVE_TO_LIB, \c source_file is 149 | * considered to be a path relative to the 150 | * library root. 151 | * @param[in] extra_options Additional options to pass to the OpenCL C 152 | * compiler. 153 | * @return Created and built OpenCL kernel. 154 | * 155 | * @note The program displays an error message and is interrupted upon error. 156 | */ 157 | cl_program build_program_from_file( 158 | cl_context context, 159 | cl_device_id device, 160 | const char* source_file, 161 | PathType path_type, 162 | const char* extra_options); 163 | 164 | /*! Prepare the OpenCL environment and run a given task. 165 | * 166 | * The task is specified as a callback function. 167 | * The OpenCL resources for the context, device and command queue are managed 168 | * by this function. The task callback is responsible for managing its 169 | * buffers and kernels. 170 | * The context, device and command queue that are passed to the task function 171 | * must not be released by the user; they are managed by call_with_opencl(). 172 | * 173 | * @param[in] platform_index The OpenCL platform with corresponding index is selected. 174 | * @param[in] task Callback function. 175 | * @param[in] device_type CL_DEVICE_TYPE_CPU or CL_DEVICE_TYPE_GPU. 176 | * @param[in] device_index If < 0, the task is run for all devices, otherwise, the 177 | * device with corresponding index is selected. 178 | * @param[in] data Extra data to pass as the last argument to the 179 | * callback (can be NULL). 180 | * @param[in] echoVersion Used to activate the display of information about Platform/Device versions. 181 | */ 182 | int call_with_opencl( 183 | int platform_index, 184 | cl_device_type device_type, 185 | int device_index, 186 | int (*task)(cl_context,cl_device_id,cl_command_queue,void*), 187 | void* data, 188 | bool echoVersion); 189 | #endif 190 | -------------------------------------------------------------------------------- /src/include/clRNG/mrg31k3p.clh: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | /*! @file mrg31k3p.clh 34 | * @brief Specific device interface for the MRG31k3p generator 35 | * 36 | * The functions defined in this file are not documented here. Refer to the 37 | * documentation of mrg31k3p.h. 38 | */ 39 | 40 | #pragma once 41 | #ifndef MRG31K3P_CLH 42 | #define MRG31K3P_CLH 43 | 44 | #include 45 | 46 | 47 | /******************************************************************************** 48 | * Functions and types declarations * 49 | ********************************************************************************/ 50 | 51 | typedef struct { 52 | /*! @brief Seed for the first MRG component 53 | */ 54 | cl_uint g1[3]; 55 | /*! @brief Seed for the second MRG component 56 | */ 57 | cl_uint g2[3]; 58 | } clrngMrg31k3pStreamState; 59 | 60 | struct clrngMrg31k3pStream_ { 61 | clrngMrg31k3pStreamState current; 62 | #if __OPENCL_C_VERSION__ >= 200 63 | // use generic address space 64 | const clrngMrg31k3pStreamState* initial; 65 | #else 66 | // force global address space 67 | __global const clrngMrg31k3pStreamState* initial; 68 | #endif 69 | #ifdef CLRNG_ENABLE_SUBSTREAMS 70 | clrngMrg31k3pStreamState substream; 71 | #endif 72 | }; 73 | typedef struct clrngMrg31k3pStream_ clrngMrg31k3pStream; 74 | 75 | struct clrngMrg31k3pHostStream_ { 76 | clrngMrg31k3pStreamState current; 77 | clrngMrg31k3pStreamState initial; 78 | clrngMrg31k3pStreamState substream; 79 | }; 80 | typedef struct clrngMrg31k3pHostStream_ clrngMrg31k3pHostStream; 81 | 82 | clrngStatus clrngMrg31k3pCopyOverStreamsFromGlobal(size_t count, clrngMrg31k3pStream* destStreams, __global const clrngMrg31k3pHostStream* srcStreams); 83 | clrngStatus clrngMrg31k3pCopyOverStreamsToGlobal(size_t count, __global clrngMrg31k3pHostStream* destStreams, const clrngMrg31k3pStream* srcStreams); 84 | clrngStatus clrngMrg31k3pCopyOverStreams(size_t count, clrngMrg31k3pStream* destStreams, const clrngMrg31k3pStream* srcStreams); 85 | 86 | #define clrngMrg31k3pRandomU01 _CLRNG_TAG_FPTYPE(clrngMrg31k3pRandomU01) 87 | #define clrngMrg31k3pRandomInteger _CLRNG_TAG_FPTYPE(clrngMrg31k3pRandomInteger) 88 | #define clrngMrg31k3pRandomU01Array _CLRNG_TAG_FPTYPE(clrngMrg31k3pRandomU01Array) 89 | #define clrngMrg31k3pRandomIntegerArray _CLRNG_TAG_FPTYPE(clrngMrg31k3pRandomIntegerArray) 90 | 91 | _CLRNG_FPTYPE clrngMrg31k3pRandomU01(clrngMrg31k3pStream* stream); 92 | clrngStatus clrngMrg31k3pRandomU01Array(clrngMrg31k3pStream* stream, size_t count, _CLRNG_FPTYPE* buffer); 93 | cl_int clrngMrg31k3pRandomInteger(clrngMrg31k3pStream* stream, cl_int i, cl_int j); 94 | clrngStatus clrngMrg31k3pRandomIntegerArray(clrngMrg31k3pStream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer); 95 | 96 | clrngStatus clrngMrg31k3pRewindStreams(size_t count, clrngMrg31k3pStream* streams); 97 | 98 | #ifdef CLRNG_ENABLE_SUBSTREAMS 99 | clrngStatus clrngMrg31k3pRewindSubstreams(size_t count, clrngMrg31k3pStream* streams); 100 | clrngStatus clrngMrg31k3pForwardToNextSubstreams(size_t count, clrngMrg31k3pStream* streams); 101 | clrngStatus clrngMrg31k3pMakeOverSubstreams(clrngMrg31k3pStream* stream, size_t count, clrngMrg31k3pStream* substreams); 102 | #endif 103 | 104 | 105 | 106 | /******************************************************************************** 107 | * Implementation * 108 | ********************************************************************************/ 109 | 110 | clrngStatus clrngMrg31k3pCopyOverStreamsFromGlobal(size_t count, clrngMrg31k3pStream* destStreams, __global const clrngMrg31k3pHostStream* srcStreams) 111 | { 112 | //Check params 113 | if (!destStreams) 114 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg31k3pCopyOverStreamsFromGlobal(): destStreams cannot be NULL"); 115 | if (!srcStreams) 116 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg31k3pCopyOverStreamsFromGlobal(): srcStreams cannot be NULL"); 117 | 118 | for (size_t i = 0; i < count; i++) { 119 | destStreams[i].current = srcStreams[i].current; 120 | destStreams[i].initial = &srcStreams[i].initial; 121 | #ifdef CLRNG_ENABLE_SUBSTREAMS 122 | destStreams[i].substream = srcStreams[i].substream; 123 | #endif 124 | } 125 | 126 | return CLRNG_SUCCESS; 127 | } 128 | 129 | clrngStatus clrngMrg31k3pCopyOverStreamsToGlobal(size_t count, __global clrngMrg31k3pHostStream* destStreams, const clrngMrg31k3pStream* srcStreams) 130 | { 131 | //Check params 132 | if (!destStreams) 133 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg31k3pCopyOverStreamsToGlobal(): destStreams cannot be NULL"); 134 | if (!srcStreams) 135 | return clrngSetErrorString(CLRNG_INVALID_VALUE, "clrngMrg31k3pCopyOverStreamsToGlobal(): srcStreams cannot be NULL"); 136 | 137 | for (size_t i = 0; i < count; i++) { 138 | destStreams[i].current = srcStreams[i].current; 139 | destStreams[i].initial = *srcStreams[i].initial; 140 | #ifdef CLRNG_ENABLE_SUBSTREAMS 141 | destStreams[i].substream = srcStreams[i].substream; 142 | #endif 143 | } 144 | 145 | return CLRNG_SUCCESS; 146 | } 147 | 148 | #ifdef CLRNG_ENABLE_SUBSTREAMS 149 | #define MODULAR_NUMBER_TYPE cl_uint 150 | #define MODULAR_FIXED_SIZE 3 151 | #include "./private/modular.c.h" 152 | #endif 153 | 154 | // code that is common to host and device 155 | #include 156 | 157 | #endif 158 | 159 | /* 160 | vim: ft=c sw=4 161 | */ 162 | -------------------------------------------------------------------------------- /src/client/RandomArray/randomarray.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #if defined(__APPLE__) || defined(__MACOSX) 34 | #include 35 | #else 36 | #include 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | /* uncomment to use single precision floating point numbers */ 44 | //#define CLRNG_SINGLE_PRECISION 45 | 46 | #ifdef CLRNG_SINGLE_PRECISION 47 | typedef cl_float fp_type; 48 | #else 49 | typedef cl_double fp_type; 50 | #endif 51 | 52 | /* Define only one of the following: */ 53 | #define USE_MRG31K3P 54 | //#define USE_MRG32K3A 55 | //#define USE_LFSR113 56 | 57 | #include "../common.h" 58 | #include "../anyrng.h" 59 | 60 | void write_fp_array(FILE* file, size_t num_cols, const char* format, size_t array_size, const fp_type* array) 61 | { 62 | size_t num_rows = (array_size + num_cols - 1) / num_cols; 63 | for (size_t row = 0; row < num_rows; row++) { 64 | for (size_t col = 0; col < num_cols; col++) { 65 | size_t i = col * num_rows + row; 66 | if (i < array_size) 67 | fprintf(file, format, array[i]); 68 | } 69 | fprintf(file, "\n"); 70 | } 71 | } 72 | 73 | 74 | typedef struct TaskData_ { 75 | size_t number_count; 76 | size_t stream_count; 77 | int display; 78 | } TaskData; 79 | 80 | void multistream_fill_array(size_t stream_count, clrngStream* streams, size_t number_count, fp_type* numbers) 81 | { 82 | for (size_t i = 0; i < number_count; i++) 83 | numbers[i] = clrngRandomU01(&streams[i % stream_count]); 84 | } 85 | 86 | int task(cl_context context, cl_device_id device, cl_command_queue queue, void* data_) 87 | { 88 | cl_int err; 89 | const TaskData* data = (const TaskData*) data_; 90 | size_t stream_count = data->stream_count; 91 | size_t number_count = data->number_count; 92 | 93 | // prepare input and output buffers 94 | /*! [streams allocation] */ 95 | size_t streams_buf_size; 96 | clrngStream* streams = clrngCreateStreams(NULL, stream_count, &streams_buf_size, (clrngStatus *)&err); 97 | /*! [streams allocation] */ 98 | check_error(err, "cannot create random streams"); 99 | 100 | fp_type* numbers_host = (fp_type*) malloc(number_count * sizeof(fp_type)); 101 | 102 | // fill array on the host, using the same ordering as on the device 103 | clock_t host_start_time = clock(); 104 | multistream_fill_array(stream_count, streams, number_count, numbers_host); 105 | clock_t host_end_time = clock(); 106 | 107 | if (data->display) { 108 | // output generated values 109 | printf("\nArray generated on the host:\n\n"); 110 | write_fp_array(stdout, 4, "%12.6f", number_count, numbers_host); 111 | } 112 | 113 | // output computing time 114 | printf("\nComputing time on the host: %1.5f s\n", (float)(host_end_time - host_start_time) / CLOCKS_PER_SEC); 115 | 116 | // reset streams for usage on device 117 | clrngRewindStreams(stream_count, streams); 118 | 119 | // create OpenCL buffers 120 | /*! [streams buffer] */ 121 | cl_mem streams_buf = clCreateBuffer(context, CL_MEM_HOST_WRITE_ONLY | CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, streams_buf_size, streams, &err); 122 | /*! [streams buffer] */ 123 | check_error(err, "cannot create streams buffer"); 124 | /*! [numbers buffer] */ 125 | cl_mem numbers_buf = clCreateBuffer(context, CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY, number_count * sizeof(fp_type), NULL, &err); 126 | /*! [numbers buffer] */ 127 | check_error(err, "cannot create numbers buffer"); 128 | 129 | // fill array on the device 130 | /*! [random array call] */ 131 | cl_event event; 132 | err = clrngDeviceRandomU01Array(stream_count, streams_buf, number_count, numbers_buf, 1, &queue, 0, NULL, &event); 133 | /*! [random array call] */ 134 | check_error(err, NULL); 135 | /*! [random array wait] */ 136 | err = clWaitForEvents(1, &event); 137 | /*! [random array wait] */ 138 | check_error(err, "error waiting for events"); 139 | 140 | // retrieve output values 141 | /*! [random array read] */ 142 | fp_type* numbers = (fp_type*) malloc(number_count * sizeof(fp_type)); 143 | err = clEnqueueReadBuffer(queue, numbers_buf, CL_TRUE, 0, number_count * sizeof(fp_type), numbers, 0, NULL, NULL); 144 | /*! [random array read] */ 145 | check_error(err, "cannot read output buffer"); 146 | 147 | if (data->display) { 148 | // output generated values 149 | printf("\nArray generated on the device:\n\n"); 150 | write_fp_array(stdout, 4, "%12.6f", number_count, numbers); 151 | } 152 | 153 | // output computing time 154 | cl_ulong device_time_start, device_time_end; 155 | clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(device_time_start), &device_time_start, NULL); 156 | clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(device_time_end), &device_time_end, NULL); 157 | printf("\nComputing time on the device: %1.5f s\n", (device_time_end - device_time_start) / 1.0e9); 158 | 159 | // compare outputs from host and device 160 | size_t diff_count = 0; 161 | fp_type diff_tot = 0.0; 162 | for (size_t j = 0; j < number_count; j++) { 163 | fp_type n1 = numbers_host[j]; 164 | fp_type n2 = numbers[j]; 165 | if (n1 != n2) { 166 | diff_tot += n1 > n2 ? n1 - n2 : n2 - n1; 167 | diff_count++; 168 | } 169 | } 170 | printf("\ncount of different values: %lu\n", diff_count); 171 | if (diff_count > 0) 172 | printf("average difference: %g\n", diff_tot / diff_count); 173 | 174 | // release resources 175 | free(numbers_host); 176 | free(numbers); 177 | clrngDestroyStreams(streams); 178 | clReleaseEvent(event); 179 | 180 | return EXIT_SUCCESS; 181 | } 182 | 183 | 184 | int main() 185 | { 186 | // IMPORTANT: number_count must be a multiple of stream_count 187 | // Set display to a nonzero value to output the numbers 188 | size_t stream_count = 1 << 10; 189 | size_t numbers_ratio = 1 << 10; 190 | TaskData data = { 191 | data.number_count = stream_count * numbers_ratio, 192 | data.stream_count = stream_count, 193 | data.display = 0 194 | }; 195 | 196 | return call_with_opencl(0, CL_DEVICE_TYPE_GPU, 0, &task, &data, true); 197 | } 198 | 199 | 200 | -------------------------------------------------------------------------------- /src/client/Inventory/InventoryKernels.cl: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *********************************************************************** 4 | Copyright (c) 2015 Advanced Micro Devices, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | *********************************************************************** 31 | */ 32 | 33 | #define CLRNG_ENABLE_SUBSTREAMS 34 | /*! [clRNG header] */ 35 | #include 36 | /*! [clRNG header] */ 37 | 38 | __constant int L = 100; 39 | __constant int c = 2; 40 | __constant double h = 0.1; 41 | __constant int K = 10; 42 | __constant int k = 1; 43 | __constant double p = 0.95; 44 | 45 | 46 | #pragma OPENCL EXTENSION cl_amd_printf : enable 47 | #pragma OPENCL EXTENSION cl_amd_fp64 : enable 48 | 49 | //Important : all the variables that start with the prefix 'param_' are passed to the Open CL C compiler as inline parameter (see.: BuildOptions) 50 | 51 | //---------------------------------------------------------------------------- 52 | 53 | double inventorySimulateOneRun(int m, int s, int S, clrngMrg31k3pStream* stream_demand, clrngMrg31k3pStream* stream_order) 54 | { 55 | int Xj = S, Yj; // Stock in the morning and in the evening. 56 | double profit = 0.0; // Cumulated profit. 57 | for (int j = 0; j < m; j++) { 58 | // Generate and subtract the demand for the day. 59 | Yj = Xj - clrngMrg31k3pRandomInteger(stream_demand, 0, L); 60 | if (Yj < 0) 61 | Yj = 0; // Lost demand. 62 | profit += c * (Xj - Yj) - h * Yj; 63 | if ((Yj < s) && (clrngMrg31k3pRandomU01(stream_order) < p)) { 64 | // We have a successful order. 65 | profit -= K + k * (S - Yj); 66 | Xj = S; 67 | } 68 | else 69 | Xj = Yj; 70 | } 71 | 72 | return profit / m; 73 | 74 | 75 | } 76 | 77 | //************************************************************************ 78 | // One policy 79 | //************************************************************************ 80 | 81 | //Case (a) and (b) : Simulate n runs on n work items using two streams and their substreams or 2*n streams 82 | __kernel void inventorySimulateGPU(__global clrngMrg31k3pHostStream* streams_demand,__global clrngMrg31k3pHostStream* streams_order,__global double* stat_profit) 83 | { 84 | // Each of the n work items executes the following code. 85 | int gid = get_global_id(0); // Id of this work item. 86 | 87 | // Make local copies of the stream states in private memory. 88 | clrngMrg31k3pStream stream_demand_d, stream_order_d; 89 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_demand_d, &streams_demand[gid]); 90 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_order_d, &streams_order[gid]); 91 | 92 | stat_profit[gid] = inventorySimulateOneRun(param_m, param_s, param_S, &stream_demand_d, &stream_order_d); 93 | } 94 | 95 | //Case (c) : use distinct streams across the work items and n2 substreams within each work item. 96 | __kernel void inventorySimulSubstreamsGPU(__global clrngMrg31k3pHostStream *streams_demand, __global clrngMrg31k3pHostStream *streams_order,__global double *stat_profit) 97 | { 98 | // Each of the n1 work items executes the following to simulate n2 runs. 99 | int gid = get_global_id(0); // Id of this work item 100 | int n1 = get_global_size(0); //Total number of work items 101 | 102 | // Make local copies of the stream states in private memory 103 | clrngMrg31k3pStream stream_demand_d, stream_order_d; 104 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_demand_d, &streams_demand[gid]); 105 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_order_d, &streams_order[gid]); 106 | 107 | for (int i = 0; i < param_n2; i++) { 108 | stat_profit[i * n1 + gid] = inventorySimulateOneRun(param_m, param_s, param_S, &stream_demand_d, &stream_order_d); 109 | clrngMrg31k3pForwardToNextSubstreams(1, &stream_demand_d); 110 | clrngMrg31k3pForwardToNextSubstreams(1, &stream_order_d); 111 | } 112 | } 113 | 114 | //Case (d) : each work item uses 2*n2 distinct streams instead of using substreams. 115 | __kernel void inventorySimul_DistinctStreams_GPU(__global clrngMrg31k3pHostStream *streams_demand, __global clrngMrg31k3pHostStream *streams_order,__global double *stat_profit) 116 | { 117 | // Each of the n1 work items executes the following to simulate n2 runs. 118 | int gid = get_global_id(0); // Id of this work item. 119 | int n1 = get_global_size(0); //Total number of work items 120 | 121 | clrngMrg31k3pStream stream_demand_d, stream_order_d; 122 | 123 | for (int i = 0; i < param_n2; i++) { 124 | // Make local copies of the stream states, in private memory. 125 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_demand_d, &streams_demand[i * n1 + gid]); 126 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_order_d, &streams_order[i * n1 + gid]); 127 | 128 | stat_profit[i * n1 + gid] = inventorySimulateOneRun(param_m, param_s, param_S, &stream_demand_d, &stream_order_d); 129 | } 130 | } 131 | 132 | //************************************************************************ 133 | // Several policies 134 | //************************************************************************ 135 | 136 | //Simulate n2 runs on n1p workitmes using n1 streams and their substreams 137 | __kernel void inventorySimulPoliciesGPU(__global clrngMrg31k3pHostStream *streams_demand, __global clrngMrg31k3pHostStream *streams_order, __global double *stat_profit 138 | ,__global cl_int *s, __global cl_int *S) 139 | { 140 | // Each of the n1*P work items executes the following to simulate n2 runs. 141 | int gid = get_global_id(0); // Id of this work item. 142 | int n1p = get_global_size(0); // n1*P = Total number of work items 143 | int n1 = n1p / param_P; // Number of streams. 144 | int k = gid / n1; // Index that identify which policy the work item will use. in case p = 2 : k = 0 or k = 1 145 | int j = gid % n1; // Index that identify the index of the work item modulo n1, in case n1=100 : j=0..99 146 | 147 | // Make local copies of the stream states, in private memory. 148 | clrngMrg31k3pStream stream_demand_d, stream_order_d; 149 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_demand_d, &streams_demand[j]); 150 | clrngMrg31k3pCopyOverStreamsFromGlobal(1, &stream_order_d, &streams_order[j]); 151 | 152 | for (int i = 0; i < param_n2; i++) 153 | { 154 | stat_profit[i * n1p + gid] = inventorySimulateOneRun(param_m, s[k], S[k], &stream_demand_d, &stream_order_d); 155 | clrngMrg31k3pForwardToNextSubstreams(1, &stream_demand_d); 156 | clrngMrg31k3pForwardToNextSubstreams(1, &stream_order_d); 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /src/include/clRNG/private/Random123/features/gccfeatures.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010-2011, D. E. Shaw Research. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions, and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions, and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of D. E. Shaw Research nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | #ifndef __gccfeatures_dot_hpp 33 | #define __gccfeatures_dot_hpp 34 | 35 | #define R123_GNUC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) 36 | 37 | #if !defined(__x86_64__) && !defined(__i386__) && !defined(__powerpc__) 38 | # error "This code has only been tested on x86 and powerpc platforms." 39 | #include 40 | { /* maybe an unbalanced brace will terminate the compilation */ 41 | /* Feel free to try the Random123 library on other architectures by changing 42 | the conditions that reach this error, but you should consider it a 43 | porting exercise and expect to encounter bugs and deficiencies. 44 | Please let the authors know of any successes (or failures). */ 45 | #endif 46 | 47 | #ifdef __powerpc__ 48 | #include 49 | #endif 50 | 51 | #ifndef R123_STATIC_INLINE 52 | #define R123_STATIC_INLINE static __inline__ 53 | #endif 54 | 55 | #ifndef R123_FORCE_INLINE 56 | #if R123_GNUC_VERSION >= 40000 57 | #define R123_FORCE_INLINE(decl) decl __attribute__((always_inline)) 58 | #else 59 | #define R123_FORCE_INLINE(decl) decl 60 | #endif 61 | #endif 62 | 63 | #ifndef R123_CUDA_DEVICE 64 | #define R123_CUDA_DEVICE 65 | #endif 66 | 67 | #ifndef R123_ASSERT 68 | #include 69 | #define R123_ASSERT(x) assert(x) 70 | #endif 71 | 72 | #ifndef R123_BUILTIN_EXPECT 73 | #define R123_BUILTIN_EXPECT(expr,likely) __builtin_expect(expr,likely) 74 | #endif 75 | 76 | /* According to the C++0x standard, we should be able to test the numeric 77 | value of __cplusplus == 199701L for C++98, __cplusplus == 201103L for C++0x 78 | But gcc has had an open bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773 79 | since early 2001, which was finally fixed in 4.7 (early 2012). For 80 | earlier versions, the only way to detect whether --std=c++0x was requested 81 | on the command line is to look at the __GCC_EXPERIMENTAL_CXX0X__ pp-symbol. 82 | */ 83 | #define GNU_CXX11 (__cplusplus>=201103L || (R123_GNUC_VERSION<40700 && defined(__GCC_EXPERIMENTAL_CXX0X__) )) 84 | 85 | #ifndef R123_USE_CXX11_UNRESTRICTED_UNIONS 86 | #define R123_USE_CXX11_UNRESTRICTED_UNIONS ((R123_GNUC_VERSION >= 40600) && GNU_CXX11) 87 | #endif 88 | 89 | #ifndef R123_USE_CXX11_STATIC_ASSERT 90 | #define R123_USE_CXX11_STATIC_ASSERT ((R123_GNUC_VERSION >= 40300) && GNU_CXX11) 91 | #endif 92 | 93 | #ifndef R123_USE_CXX11_CONSTEXPR 94 | #define R123_USE_CXX11_CONSTEXPR ((R123_GNUC_VERSION >= 40600) && GNU_CXX11) 95 | #endif 96 | 97 | #ifndef R123_USE_CXX11_EXPLICIT_CONVERSIONS 98 | #define R123_USE_CXX11_EXPLICIT_CONVERSIONS ((R123_GNUC_VERSION >= 40500) && GNU_CXX11) 99 | #endif 100 | 101 | #ifndef R123_USE_CXX11_RANDOM 102 | #define R123_USE_CXX11_RANDOM ((R123_GNUC_VERSION>=40500) && GNU_CXX11) 103 | #endif 104 | 105 | #ifndef R123_USE_CXX11_TYPE_TRAITS 106 | #define R123_USE_CXX11_TYPE_TRAITS ((R123_GNUC_VERSION>=40400) && GNU_CXX11) 107 | #endif 108 | 109 | #ifndef R123_USE_AES_NI 110 | #ifdef __AES__ 111 | #define R123_USE_AES_NI 1 112 | #else 113 | #define R123_USE_AES_NI 0 114 | #endif 115 | #endif 116 | 117 | #ifndef R123_USE_SSE4_2 118 | #ifdef __SSE4_2__ 119 | #define R123_USE_SSE4_2 1 120 | #else 121 | #define R123_USE_SSE4_2 0 122 | #endif 123 | #endif 124 | 125 | #ifndef R123_USE_SSE4_1 126 | #ifdef __SSE4_1__ 127 | #define R123_USE_SSE4_1 1 128 | #else 129 | #define R123_USE_SSE4_1 0 130 | #endif 131 | #endif 132 | 133 | #ifndef R123_USE_SSE 134 | /* There's no point in trying to compile SSE code in Random123 135 | unless SSE2 is available. */ 136 | #ifdef __SSE2__ 137 | #define R123_USE_SSE 1 138 | #else 139 | #define R123_USE_SSE 0 140 | #endif 141 | #endif 142 | 143 | #ifndef R123_USE_AES_OPENSSL 144 | /* There isn't really a good way to tell at compile time whether 145 | openssl is available. Without a pre-compilation configure-like 146 | tool, it's less error-prone to guess that it isn't available. Add 147 | -DR123_USE_AES_OPENSSL=1 and any necessary LDFLAGS or LDLIBS to 148 | play with openssl */ 149 | #define R123_USE_AES_OPENSSL 0 150 | #endif 151 | 152 | #ifndef R123_USE_GNU_UINT128 153 | #ifdef __x86_64__ 154 | #define R123_USE_GNU_UINT128 1 155 | #else 156 | #define R123_USE_GNU_UINT128 0 157 | #endif 158 | #endif 159 | 160 | #ifndef R123_USE_ASM_GNU 161 | #define R123_USE_ASM_GNU (defined(__x86_64__)||defined(__i386__)) 162 | #endif 163 | 164 | #ifndef R123_USE_CPUID_MSVC 165 | #define R123_USE_CPUID_MSVC 0 166 | #endif 167 | 168 | #ifndef R123_USE_X86INTRIN_H 169 | #define R123_USE_X86INTRIN_H ((defined(__x86_64__)||defined(__i386__)) && R123_GNUC_VERSION >= 40402) 170 | #endif 171 | 172 | #ifndef R123_USE_IA32INTRIN_H 173 | #define R123_USE_IA32INTRIN_H 0 174 | #endif 175 | 176 | #ifndef R123_USE_XMMINTRIN_H 177 | #define R123_USE_XMMINTRIN_H 0 178 | #endif 179 | 180 | #ifndef R123_USE_EMMINTRIN_H 181 | /* gcc -m64 on Solaris 10 defines __SSE2__ but doesn't have 182 | emmintrin.h in the include search path. This is 183 | so broken that I refuse to try to work around it. If this 184 | affects you, figure out where your emmintrin.h lives and 185 | add an appropriate -I to your CPPFLAGS. Or add -DR123_USE_SSE=0. */ 186 | #define R123_USE_EMMINTRIN_H (R123_USE_SSE && (R123_GNUC_VERSION < 40402)) 187 | #endif 188 | 189 | #ifndef R123_USE_SMMINTRIN_H 190 | #define R123_USE_SMMINTRIN_H ((R123_USE_SSE4_1 || R123_USE_SSE4_2) && (R123_GNUC_VERSION < 40402)) 191 | #endif 192 | 193 | #ifndef R123_USE_WMMINTRIN_H 194 | #define R123_USE_WMMINTRIN_H 0 195 | #endif 196 | 197 | #ifndef R123_USE_INTRIN_H 198 | #define R123_USE_INTRIN_H 0 199 | #endif 200 | 201 | #ifndef R123_USE_MULHILO32_ASM 202 | #define R123_USE_MULHILO32_ASM 0 203 | #endif 204 | 205 | #ifndef R123_USE_MULHILO64_ASM 206 | #define R123_USE_MULHILO64_ASM 0 207 | #endif 208 | 209 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 210 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 211 | #endif 212 | 213 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 214 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 215 | #endif 216 | 217 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 218 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 219 | #endif 220 | 221 | #ifndef R123_USE_MULHILO64_MULHI_INTRIN 222 | #define R123_USE_MULHILO64_MULHI_INTRIN (defined(__powerpc64__)) 223 | #endif 224 | 225 | #ifndef R123_MULHILO64_MULHI_INTRIN 226 | #define R123_MULHILO64_MULHI_INTRIN __mulhdu 227 | #endif 228 | 229 | #ifndef R123_USE_MULHILO32_MULHI_INTRIN 230 | #define R123_USE_MULHILO32_MULHI_INTRIN 0 231 | #endif 232 | 233 | #ifndef R123_MULHILO32_MULHI_INTRIN 234 | #define R123_MULHILO32_MULHI_INTRIN __mulhwu 235 | #endif 236 | 237 | #ifndef __STDC_CONSTANT_MACROS 238 | #define __STDC_CONSTANT_MACROS 239 | #endif 240 | #include 241 | #ifndef UINT64_C 242 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 243 | #endif 244 | 245 | /* If you add something, it must go in all the other XXfeatures.hpp 246 | and in ../ut_features.cpp */ 247 | #endif 248 | --------------------------------------------------------------------------------