├── .codecov.yml ├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── appveyor.yml ├── benchmarks ├── CMakeLists.txt ├── kuramoto.cl ├── kuramoto_benchmark.py ├── oculomotor.cl └── oculomotor_benchmark.py ├── ci └── intelOpenCLSilent.cfg ├── cmake ├── CompilerWarnings.cmake ├── ProjectDependences.cmake └── StandardProjectSettings.cmake ├── examples ├── CMakeLists.txt ├── kuramoto.cl ├── kuramoto_euler.py ├── kuramoto_euler_stochastic.py ├── oculomotor.cl ├── oculomotor_euler.py ├── oculomotor_euler_stochastic.py ├── oculomotor_ie.py ├── oculomotor_im.py └── oculomotor_rk.py ├── external └── include │ ├── Random123 │ ├── LICENSE │ ├── MicroURNG.hpp │ ├── ReinterpretCtr.hpp │ ├── aes.h │ ├── array.h │ ├── ars.h │ ├── conventional │ │ ├── Engine.hpp │ │ └── gsl_cbrng.h │ ├── features │ │ ├── clangfeatures.h │ │ ├── compilerfeatures.h │ │ ├── gccfeatures.h │ │ ├── iccfeatures.h │ │ ├── llvmfeatures.h │ │ ├── msvcfeatures.h │ │ ├── nvccfeatures.h │ │ ├── open64features.h │ │ ├── openclfeatures.h │ │ ├── pgccfeatures.h │ │ ├── sse.h │ │ ├── sunprofeatures.h │ │ └── xlcfeatures.h │ ├── gsl_microrng.h │ ├── philox.h │ ├── threefry.h │ └── u01.h │ └── catch.hpp ├── get_code_cov.sh ├── include ├── build_Option.hpp ├── clog.hpp ├── device.hpp ├── device_Type.hpp ├── output_Type.hpp ├── platform.hpp ├── sodecl.hpp ├── sodeclmgr.hpp ├── solver_Type.hpp └── timer.hpp ├── interfaces ├── CMakeLists.txt └── python │ ├── CMakeLists.txt │ ├── sodecl.cpp │ └── sodecl.py ├── scripts ├── slurm_submit.peta4-knl ├── slurm_submit.peta4-skylake └── slurm_submit.wilkes2 ├── src ├── CMakeLists.txt ├── clog.cpp ├── device.cpp ├── kernels │ ├── euler.cl │ ├── ie.cl │ ├── im.cl │ ├── rk4.cl │ ├── solver_caller.cl │ ├── stochastic_euler.cl │ └── stochastic_solver_caller.cl ├── platform.cpp ├── sodeclmgr.cpp └── timer.cpp └── tests ├── CMakeLists.txt ├── approval └── CMakeLists.txt ├── data ├── CMakeLists.txt ├── oculomotor_euler.pkl ├── oculomotor_ie.pkl ├── oculomotor_im.pkl └── oculomotor_rk.pkl ├── kuramoto.cl ├── oculomotor.cl ├── sodecl_python_tests.py └── unit ├── CMakeLists.txt └── sodecl_tests.cpp /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: no 4 | 5 | coverage: 6 | precision: 2 7 | round: down 8 | range: "50...100" 9 | 10 | status: 11 | project: yes 12 | patch: yes 13 | changes: no 14 | 15 | parsers: 16 | gcov: 17 | branch_detection: 18 | conditional: yes 19 | loop: yes 20 | method: no 21 | macro: no 22 | 23 | comment: 24 | layout: "header, diff" 25 | behavior: default 26 | require_changes: no 27 | 28 | ignore: 29 | - "src/include/.*" 30 | - "src/matlabscripts/.*" 31 | - "src/pythonscripts/.*" 32 | - "src/tests/.*" 33 | - "pybind11/.*" 34 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. iOS] 25 | - Browser [e.g. chrome, safari] 26 | - Version [e.g. 22] 27 | 28 | **Smartphone (please complete the following information):** 29 | - Device: [e.g. iPhone6] 30 | - OS: [e.g. iOS8.1] 31 | - Browser [e.g. stock browser, safari] 32 | - Version [e.g. 22] 33 | 34 | **Additional context** 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | \.idea/ 3 | cmake-*/ 4 | venv/ 5 | matlabstuff/ 6 | slurm/ 7 | poster* -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build 3 | - test 4 | 5 | build:ubuntu: 6 | image: elavram/ubuntu:latest 7 | stage: build 8 | tags: 9 | - docker 10 | script: 11 | - apt-get update && apt-get install -y build-essential cmake git python3-dev python3-numpy 12 | - apt-get install -y lsb-core ocl-icd-opencl-dev pocl-opencl-icd 13 | - ldconfig 14 | - cd /builds/$CI_PROJECT_PATH 15 | - git submodule update --init 16 | - mkdir build 17 | - cd build 18 | - cmake .. 19 | - make 20 | artifacts: 21 | paths: 22 | - build 23 | 24 | test:ubuntu: 25 | image: elavram/ubuntu:latest 26 | stage: test 27 | tags: 28 | - docker 29 | script: 30 | - apt-get update && apt-get install -y build-essential cmake git python3-dev python3-numpy 31 | - apt-get install -y lsb-core ocl-icd-opencl-dev pocl-opencl-icd 32 | - ldconfig 33 | - cd /builds/$CI_PROJECT_PATH/build/tests 34 | - ctest -V 35 | 36 | build:fedora: 37 | image: fedora:latest 38 | stage: build 39 | tags: 40 | - docker 41 | script: 42 | - dnf install -y redhat-lsb-core dnf-plugins-core git cmake gcc g++ python3-devel.x86_64 python3-numpy 43 | - dnf -y copr enable jdanecki/intel-opencl 44 | - dnf install -y intel-opencl 45 | - dnf install -y ocl-icd ocl-icd-devel 46 | - cd /builds/$CI_PROJECT_PATH 47 | - git submodule update --init 48 | - mkdir build 49 | - cd build 50 | - cmake .. 51 | - make 52 | artifacts: 53 | paths: 54 | - build 55 | 56 | test:fedora: 57 | image: fedora:latest 58 | stage: test 59 | tags: 60 | - docker 61 | script: 62 | - dnf install -y redhat-lsb-core dnf-plugins-core git cmake gcc g++ python3-devel.x86_64 python3-numpy 63 | - dnf -y copr enable jdanecki/intel-opencl 64 | - dnf install -y intel-opencl 65 | - dnf install -y ocl-icd ocl-icd-devel 66 | - cd /builds/$CI_PROJECT_PATH/build/tests 67 | - ctest -V -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "interfaces/python/pybind11"] 2 | path = interfaces/python/pybind11 3 | url = https://github.com/pybind/pybind11.git 4 | branch = stable 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------------------// 2 | # Copyright (c) 2015 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | #---------------------------------------------------------------------------// 7 | 8 | cmake_minimum_required (VERSION 3.15) 9 | 10 | project(sodecl CXX) 11 | 12 | # Project dependences 13 | include(cmake/ProjectDependences.cmake) 14 | 15 | # Project settings 16 | include(cmake/StandardProjectSettings.cmake) 17 | add_library(project_options INTERFACE) 18 | target_compile_features(project_options INTERFACE cxx_std_17) 19 | 20 | # Standard compiler warnings 21 | add_library(project_warnings INTERFACE) 22 | include(cmake/CompilerWarnings.cmake) 23 | set_project_warnings(project_warnings) 24 | 25 | add_subdirectory(src) 26 | include(GenerateExportHeader) 27 | generate_export_header(sodecl) 28 | 29 | add_subdirectory(interfaces) 30 | add_subdirectory(benchmarks) 31 | enable_testing() 32 | add_subdirectory(tests) 33 | add_subdirectory(examples) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Eleftherios Avramidis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | *********************************************************************** 24 | SODECL uses the following software with their 25 | corresponding licenses printed below: 26 | *********************************************************************** 27 | 28 | Random123 software 29 | https://www.deshawresearch.com/resources_random123.html 30 | 31 | Copyright 2010-2012, D. E. Shaw Research. 32 | All rights reserved. 33 | 34 | Redistribution and use in source and binary forms, with or without 35 | modification, are permitted provided that the following conditions are 36 | met: 37 | 38 | * Redistributions of source code must retain the above copyright 39 | notice, this list of conditions, and the following disclaimer. 40 | 41 | * Redistributions in binary form must reproduce the above copyright 42 | notice, this list of conditions, and the following disclaimer in the 43 | documentation and/or other materials provided with the distribution. 44 | 45 | * Neither the name of D. E. Shaw Research nor the names of its 46 | contributors may be used to endorse or promote products derived from 47 | this software without specific prior written permission. 48 | 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | 62 | Catch2 library 63 | https://github.com/catchorg/Catch2 64 | 65 | Boost Software License - Version 1.0 - August 17th, 2003 66 | 67 | Permission is hereby granted, free of charge, to any person or organization 68 | obtaining a copy of the software and accompanying documentation covered by 69 | this license (the "Software") to use, reproduce, display, distribute, 70 | execute, and transmit the Software, and to prepare derivative works of the 71 | Software, and to permit third-parties to whom the Software is furnished to 72 | do so, all subject to the following: 73 | 74 | The copyright notices in the Software and this entire statement, including 75 | the above license grant, this restriction and the following disclaimer, 76 | must be included in all copies of the Software, in whole or in part, and 77 | all derivative works of the Software, unless such copies or derivative 78 | works are solely in the form of machine-executable object code generated by 79 | a source language processor. 80 | 81 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 82 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 83 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 84 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 85 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 86 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 87 | DEALINGS IN THE SOFTWARE. 88 | 89 | pybind11 90 | https://github.com/pybind/pybind11 91 | 92 | Copyright (c) 2016 Wenzel Jakob , All rights reserved. 93 | 94 | Redistribution and use in source and binary forms, with or without 95 | modification, are permitted provided that the following conditions are met: 96 | 97 | 1. Redistributions of source code must retain the above copyright notice, this 98 | list of conditions and the following disclaimer. 99 | 100 | 2. Redistributions in binary form must reproduce the above copyright notice, 101 | this list of conditions and the following disclaimer in the documentation 102 | and/or other materials provided with the distribution. 103 | 104 | 3. Neither the name of the copyright holder nor the names of its contributors 105 | may be used to endorse or promote products derived from this software 106 | without specific prior written permission. 107 | 108 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 109 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 110 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 111 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 112 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 113 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 114 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 115 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 116 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 117 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 118 | 119 | Please also refer to the file CONTRIBUTING.md, which clarifies licensing of 120 | external contributions to this project including patches, pull requests, etc. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SODECL 2 | 3 | [![license: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/avramidis/sodecl/blob/master/LICENSE) 4 | ![stability-wip](https://img.shields.io/badge/stability-work_in_progress-lightgrey.svg) 5 | [![pipeline status](https://gitlab.com/avramidis/sodecl/badges/master/pipeline.svg)](https://gitlab.com/avramidis/sodecl/-/commits/master) 6 | [![Build status](https://ci.appveyor.com/api/projects/status/l232dxa64k60onls?svg=true)](https://ci.appveyor.com/project/avramidis/sodecl) 7 | [![codecov](https://codecov.io/gh/avramidis/sodecl/branch/master/graph/badge.svg)](https://codecov.io/gh/avramidis/sodecl) 8 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/avramidis/sodecl/issues) 9 | [![DOI](https://zenodo.org/badge/49196982.svg)](https://zenodo.org/badge/latestdoi/49196982) 10 | 11 | 12 | SODECL is a library of ordinary differential equation (ODE) and stochastic differential equation (SDE) solvers in OpenCL. 13 | Using SODECL the user can calculate the integration orbits of a ODE or SDE system for a large number of different parameter values. 14 | 15 | One example of the usefullness of SODECL is the fitting an ODE system representing a biological model to experimental data. When optimising an ODE biological model using for example genetic algorithms the ODE model has to be calculated for a large number of different parameter values combinations. SODECL accelerates the calculation of these ODE model orbit integrations by taking advantage of all the cores of a CPU or the parallel capabilities of a GPU. 16 | 17 | ## Getting Started 18 | 19 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. 20 | 21 | ### Prerequisites 22 | 23 | To get the code you will need git. To install git on Ubuntu use the following commands in a terminal 24 | 25 | ``` 26 | sudo apt update 27 | sudo apt install git 28 | ``` 29 | 30 | To clone the repository from github use the following command in a terminal 31 | 32 | ``` 33 | git clone https://github.com/avramidis/sodecl.git 34 | ``` 35 | You will need pybind11, to clone the repository in the sodecl folder use the following commands in a terminal 36 | 37 | ``` 38 | cd sodecl 39 | git submodule update --init 40 | ``` 41 | 42 | You will need lsb-core, to install it you the following command in a terminal 43 | 44 | ``` 45 | sudo apt install lsb-core 46 | ``` 47 | 48 | You will need the OpenCL Runtime for Intel Core and Intel Xeon Processors to run SODECL on an Intel CPU. The runtime can be downloaded from https://software.intel.com/en-us/articles/opencl-drivers#latest_CPU_runtime. In the folder with the downloaded tgz file use the following commands in a terminal 49 | 50 | ``` 51 | tar -zxvf l_opencl_p_18.1.0.014.tgz 52 | cd l_opencl_p_18.1.0.014 53 | sudo ./install_GUI.sh 54 | ``` 55 | 56 | You will need to install the OpenCL library. To do that use the following commands in a terminal 57 | 58 | ``` 59 | sudo apt install ocl-icd-opencl-dev 60 | ``` 61 | 62 | To generate the makefile for compiling SODECL you will need cmake. To install cmake on Ubuntu use the following command in a terminal 63 | 64 | ``` 65 | sudo apt install cmake 66 | ``` 67 | 68 | To use the Python wrapper a number of module must be installed. To install these modules use the following commands in a terminal 69 | 70 | ``` 71 | sudo apt install python3-numpy 72 | sudo pip3 install numpy 73 | sudo pip3 install matplotlib 74 | ``` 75 | 76 | ### Installing 77 | 78 | A step by step series of examples that tell you have to get a development env running 79 | 80 | To generate the makefiles use the following commands in a terminal in the sodecl folders 81 | 82 | ``` 83 | mkdir build 84 | cd build 85 | cmake .. 86 | ``` 87 | 88 | To build SODECL use the following command 89 | 90 | ``` 91 | make 92 | ``` 93 | 94 | To run an example using the Python wrapper use the following commands in a terminal the build directory 95 | 96 | 97 | ``` 98 | cd examples 99 | python3 kuramoto_euler_stochastic.py 100 | ``` 101 | 102 | If the run was successful the output will be similar to the following 103 | 104 | ``` 105 | Compute results runtime: 0.0690873 sec. 106 | Simulation execution time: 0.5892870426177979 seconds. 107 | ``` 108 | 109 | Using the following command in a terminal in the pythonwrapper directory the log generated by the SODECL run can be viewed 110 | 111 | ``` 112 | more sodecllog.txt 113 | ``` 114 | 115 | The output for a successful run should be similar too the following. The log file includes the OpenCL platforms and devices available in the system. Also, it includes the build options for the OpenCL kernel and the runtime. 116 | 117 | ``` 118 | The platform name is Intel(R) OpenCL 119 | The platform version is OpenCL 1.2 LINUX 120 | The device name is Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz 121 | Selected platform name: Intel(R) OpenCL 122 | Selected device name: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz 123 | Selected device OpenCL version: OpenCL 1.2 (Build 37) 124 | kernels/stochasticeuler.cl 125 | Build options string: -I. -cl-fast-relaxed-math -cl-std=CL2.0 126 | The local group size is: 8 127 | Compute results runtime: 0.0690873sec. 128 | ``` 129 | 130 | ## Current fixed step solvers 131 | 132 | 1. Euler 133 | 2. Runge-Kutta 134 | 3. Implicit Euler 135 | 4. Implicit midpoint 136 | 5. Euler-Maruyama 137 | 138 | ## Simple wrappers for 139 | 140 | 1. Python 141 | 142 | ## Future work 143 | 144 | 1. More ODE and SDE solvers 145 | 2. Variable step ODE solvers 146 | 3. Benchmarks 147 | 4. Support for using multiple devices (e.g. CPUs+GPUs) 148 | 5. Optimisation for AMD and NVIDIA GPUs 149 | 6. Tutorials 150 | 7. Doxygen documentation 151 | 152 | ## License 153 | 154 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 155 | 156 | ## How to cite SODECL 157 | To cite SODECL please cite the URL and the DOI of the release version you used. The DOI of the latest release is at the badge at the top of this README.md file. 158 | 159 | ## Acknowledgements 160 | 161 | * The Random123 library found at https://www.deshawresearch.com/resources_random123.html is used 162 | * The Catch2 unit testing library found at https://github.com/catchorg/Catch2 is used 163 | * The pybind11 library found at https://github.com/pybind/pybind11 is used 164 | * This readme file is based on the template found at https://gist.github.com/PurpleBooth/109311bb0361f32d87a2 165 | * The initial work on this library was done as part of a PhD work presented in the publication Avramidis, Eleftherios, and Ozgur E. Akman. "Optimisation of an exemplar oculomotor model using multi-objective genetic algorithms executed on a GPU-CPU combination." BMC systems Biology 11.1 (2017): 40. DOI: 10.1186/s12918-017-0416-2 166 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | 2 | image: Ubuntu1804 3 | 4 | install: 5 | - git submodule update --init 6 | - sudo apt update -qq 7 | - sudo apt install python3-dev -y -qq 8 | - sudo apt install cmake -y -qq 9 | - mkdir temp 10 | - cd temp 11 | - wget https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-Linux-x86_64.sh 12 | - sudo sh cmake-3.16.4-Linux-x86_64.sh --skip-license --prefix=/usr/local 13 | - sudo apt install lsb-core -y -qq 14 | - sudo apt install ocl-icd-opencl-dev -y -qq 15 | - wget http://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/15532/l_opencl_p_18.1.0.015.tgz 16 | - tar -xvzf l_opencl_p_18.1.0.015.tgz 17 | - cd l_opencl_p_18.1.0.015 18 | - sudo ./install.sh -s $APPVEYOR_BUILD_FOLDER/ci/intelOpenCLSilent.cfg 19 | - sudo ldconfig 20 | - sudo apt install python3-pip -y 21 | - pip3 install numpy 22 | 23 | build: off 24 | 25 | build_script: 26 | - cd $APPVEYOR_BUILD_FOLDER 27 | - mkdir build 28 | - cd build 29 | - cmake .. && make 30 | 31 | test_script: 32 | - ctest 33 | 34 | -------------------------------------------------------------------------------- /benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(benchmarks) 4 | 5 | set(BENCHMARK_PYTHON_SOURCE_FILES 6 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto_benchmark.py 7 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto.cl 8 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_benchmark.py 9 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor.cl 10 | ) 11 | 12 | set(BENCHMARK_PYTHON_FILES 13 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto_benchmark.py 14 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto.cl 15 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_benchmark.py 16 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor.cl 17 | ) 18 | 19 | add_custom_command(OUTPUT ${BENCHMARK_PYTHON_FILES} 20 | COMMAND ${CMAKE_COMMAND} -E copy ${BENCHMARK_PYTHON_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/ 21 | COMMENT "Copy benchmark files" 22 | VERBATIM 23 | ) 24 | 25 | add_custom_target(benchmarks_copy ALL 26 | DEPENDS ${BENCHMARK_PYTHON_FILES} 27 | VERBATIM) 28 | -------------------------------------------------------------------------------- /benchmarks/kuramoto.cl: -------------------------------------------------------------------------------- 1 | #define NOSC _numeq_ 2 | 3 | void sode_system(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 4 | { 5 | for (int i = 0; i 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import random 9 | import time 10 | import numpy 11 | import sodecl 12 | 13 | if __name__ == '__main__': 14 | orbit_set = [512, 5120, 25600, 40960, 81920, 163840] 15 | nequat_set = [5, 10, 15] 16 | repetitions = 8 17 | 18 | # orbit_set = [512] 19 | # nequat_set = [15] 20 | # repetitions = 8 21 | 22 | openclplatform = 0 23 | opencldevice = 0 24 | openclkernel = 'kuramoto.cl' 25 | solver = 0 26 | dt = 0.05 27 | tspan = 50 28 | ksteps = 40 29 | localgroupsize = 0 30 | 31 | runtimes = numpy.zeros((len(nequat_set), len(orbit_set), repetitions+1)) 32 | 33 | nequat_count = 0 34 | for nequat in nequat_set: 35 | orbits_count = 0 36 | for orbits in orbit_set: 37 | reps_count = 0 38 | for reps in range(repetitions): 39 | print("nequat: ", nequat_set[nequat_count]) 40 | print("norbits: ", orbit_set[orbits_count]) 41 | print("rep: ", reps) 42 | 43 | time.sleep(3) 44 | start_time = time.time() 45 | 46 | nparams = nequat+1 47 | nnoi = nequat 48 | 49 | # Initialise initial state of the system 50 | initx = numpy.ndarray((orbits, nequat)) 51 | for o in range(orbits): 52 | for p in range(nequat): 53 | initx[o][p] = random.uniform(-3.1416, 3.1416) 54 | 55 | # Initialise parameters values of the system 56 | params = numpy.ndarray((orbits, nparams)) 57 | for o in range(orbits): 58 | params[o][0] = 0.2 59 | for p in range(1,nequat+1): 60 | params[o][p] = random.uniform(0.2, 0.4) 61 | 62 | # Initialise noise values of the system 63 | noise = numpy.ndarray((orbits, nequat)) 64 | for o in range(orbits): 65 | for p in range(nequat): 66 | noise[o][p] = random.uniform(0.01, 0.03) 67 | 68 | params = numpy.concatenate((params, noise), axis=1) 69 | 70 | results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 71 | initx, params, solver, 72 | orbits, nequat, nnoi, 73 | dt, tspan, ksteps, localgroupsize) 74 | 75 | end_time = time.time() 76 | 77 | # import matplotlib.pyplot as plt 78 | # plt.plot(results[0, :]) 79 | # plt.xlabel('Time') 80 | # plt.ylabel('Value') 81 | # plt.show() 82 | 83 | #print("Simulation execution time:l ", end_time - start_time, " seconds.") 84 | if numpy.isnan(numpy.sum(numpy.sum(results))): 85 | raise RuntimeError("NaN present!") 86 | 87 | runtimes[nequat_count][orbits_count][reps_count] = end_time - start_time 88 | reps_count = reps_count + 1 89 | print("") 90 | 91 | runtimes[nequat_count][orbits_count][reps_count] = numpy.mean(runtimes[nequat_count][orbits_count][0:repetitions-1]) 92 | 93 | orbits_count = orbits_count + 1 94 | nequat_count = nequat_count + 1 95 | 96 | print(runtimes) 97 | 98 | ##################################################### 99 | ## Write the results to files 100 | numpy.savetxt('nequat_5.txt', runtimes[0][:][:], fmt='%.4f') 101 | numpy.savetxt('nequat_10.txt', runtimes[1][:][:], fmt='%.4f') 102 | numpy.savetxt('nequat_15.txt', runtimes[2][:][:], fmt='%.4f') -------------------------------------------------------------------------------- /benchmarks/oculomotor.cl: -------------------------------------------------------------------------------- 1 | #define T1 0.15 2 | #define T2 0.012 3 | #define Tn 25.00 4 | 5 | inline static double sburstf(double x, double aval, double bval, double atval, double btval) 6 | { 7 | double y; 8 | y = 0; 9 | 10 | if (x > 0) 11 | { 12 | y = (atval * (1.00 - exp(-x / btval))); 13 | } 14 | else 15 | { 16 | y = (-(aval / bval) * x * exp(x / bval)); 17 | } 18 | 19 | return y; 20 | } 21 | 22 | inline static double dsburstf(double x, double aval, double bval, double atval, double btval) 23 | { 24 | double y; 25 | y = 0; 26 | 27 | if (x > 0) 28 | { 29 | y = (atval*exp(-x / btval)) / btval; 30 | } 31 | else 32 | { 33 | y = -((aval*exp(x / bval)) / bval + (aval*x*exp(x / bval)) / (bval*bval)); 34 | } 35 | return y; 36 | } 37 | 38 | inline static void calc_jacobian(double y[_numeq_], double jac[_numeq_][_numeq_], double p[_numpar_]) 39 | { 40 | jac[0][0] = 0; 41 | jac[0][1] = 1; 42 | jac[0][2] = 0; 43 | jac[0][3] = 0; 44 | jac[0][4] = 0; 45 | jac[0][5] = 0; 46 | 47 | jac[1][0] = -1 / (T1*T2); 48 | jac[1][1] = -(1 / T1) - (1 / T2); 49 | jac[1][2] = 1 / (T1*T2); 50 | jac[1][3] = (1 / T1) + (1 / T2); 51 | jac[1][4] = -(1 / T1) - (1 / T2); 52 | jac[1][5] = 0; 53 | 54 | jac[2][0] = 0; 55 | jac[2][1] = 0; 56 | jac[2][2] = -1 / Tn; 57 | jac[2][3] = 1; 58 | jac[2][4] = -1; 59 | jac[2][5] = 0; 60 | 61 | jac[3][0] = 0; 62 | jac[3][1] = 0; 63 | jac[3][2] = 0; 64 | jac[3][3] = -(p[3] * (y[4] * y[4]) + 1) / p[2]; 65 | jac[3][4] = -(2 * p[3] * y[4] * y[3]) / p[2]; 66 | jac[3][5] = dsburstf(y[5], p[0], p[1], p[4], p[5]) / p[2]; 67 | 68 | jac[4][0] = 0; 69 | jac[4][1] = 0; 70 | jac[4][2] = 0; 71 | jac[4][3] = -(2 * p[3] * y[4] * y[3]) / p[2]; 72 | jac[4][4] = -(p[3] * (y[3] * y[3]) + 1) / p[2]; 73 | jac[4][5] = dsburstf(-y[5], p[0], p[1], p[4], p[5]) / p[2]; 74 | 75 | jac[5][0] = 0; 76 | jac[5][1] = 0; 77 | jac[5][2] = 0; 78 | jac[5][3] = -1; 79 | jac[5][4] = 1; 80 | jac[5][5] = 0; 81 | } 82 | 83 | inline static void sode_system(double t, __global double y[_numeq_], __global double yout[_numeq_], __global double p[_numpar_]) 84 | { 85 | int ig = get_global_id(0); 86 | int paramstep = ig * _numpar_; 87 | 88 | // g 89 | yout[ig * _numeq_ + 0] = y[ig * _numeq_ + 1]; 90 | // u 91 | yout[ig * _numeq_ + 1] = -(((1.00 / T1) + (1.00 / T2)) * y[ig * _numeq_ + 1]) - (1.00 / (T1 * T2) * y[ig * _numeq_ + 0]) + (1.00 / (T1 * T2) * y[ig * _numeq_ + 2]) + ((1.00 / T1) + (1.00 / T2)) * (y[ig * _numeq_ + 3] - y[ig * _numeq_ + 4]); 92 | // n 93 | yout[ig * _numeq_ + 2] = -(y[ig * _numeq_ + 2] / Tn) + (y[ig * _numeq_ + 3] - y[ig * _numeq_ + 4]); 94 | //r 95 | yout[ig * _numeq_ + 3] = (1.00 / p[paramstep + 2])*(-y[ig * _numeq_ + 3] - (p[paramstep + 3] * y[ig * _numeq_ + 3] * y[ig * _numeq_ + 4] * y[ig * _numeq_ + 4]) + sburstf(y[5], p[paramstep + 0], p[paramstep + 1], p[paramstep + 4], p[paramstep + 5])); 96 | // l 97 | yout[ig * _numeq_ + 4] = (1.00 / p[paramstep + 2])*(-y[ig * _numeq_ + 4] - (p[paramstep + 3] * y[ig * _numeq_ + 4] * y[ig * _numeq_ + 3] * y[ig * _numeq_ + 3]) + sburstf(-y[5], p[paramstep + 0], p[paramstep + 1], p[paramstep + 4], p[paramstep + 5])); 98 | // m 99 | yout[ig * _numeq_ + 5] = -(y[ig * _numeq_ + 3] - y[ig * _numeq_ + 4]); 100 | } 101 | 102 | inline static void sode_system_stoch(double t, __global double y[_numeq_], __global double stoch[_numeq_], __global double p[_numpar_], __global double noise[_numnoi_]) 103 | { 104 | int ig = get_global_id(0); 105 | int paramstep = ig * _numpar_; 106 | 107 | // g 108 | stoch[ig * _numeq_ + 0] = 0; 109 | // u 110 | stoch[ig * _numeq_ + 1] = ((1.00 / T1) + (1.00 / T2)) * (y[ig * _numeq_ + 3] - y[ig * _numeq_ + 4])*p[_numpar_ - _numnoi_ + 0] * noise[ig * _numnoi_ + 0] + p[_numpar_ - _numnoi_ + 1] * noise[ig * _numnoi_ + 1]; 111 | // n 112 | stoch[ig * _numeq_ + 2] = 0; 113 | // r 114 | stoch[ig * _numeq_ + 3] = 0; 115 | // l 116 | stoch[ig * _numeq_ + 4] = 0; 117 | // m 118 | stoch[ig * _numeq_ + 5] = 0; 119 | } -------------------------------------------------------------------------------- /benchmarks/oculomotor_benchmark.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------// 2 | # Copyright (c) 2017 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import numpy 9 | import numpy.matlib 10 | import random 11 | import sodecl 12 | import time 13 | 14 | if __name__ == '__main__': 15 | #def runbench(orbits): 16 | 17 | start = time.time() 18 | 19 | orbits = 8 20 | #orbits = 256 21 | #orbits = 512 22 | #orbits = 1024 23 | #orbits = 2048 24 | #orbits = 4096 25 | #orbits = 8192 26 | #orbits = 16384 27 | # orbits = 32768 28 | 29 | openclplatform = 0 30 | opencldevice = 0 31 | openclkernel = 'oculomotor.cl' 32 | solver = 0 33 | nequat = 6 34 | nparams = 8 35 | nnoi = 2 36 | dt = 1e-8 37 | tspan = 1 38 | ksteps = 40000 39 | localgroupsize = 0 40 | 41 | initx = numpy.array([0, 0, 0, 0, 0, 0.7]) 42 | initx = numpy.matlib.repmat(initx, orbits, 1) 43 | 44 | # low_bounds = [1, 0.1, 0.1, 0, 1, 0.1, 0, 0, 0] 45 | # upper_bounds = [1000, 60, 0.0001, 12, 1000, 60, 0.5, 0.1, 100] 46 | 47 | # low_bounds = [1, 0.1, 0.1, 0, 1, 0.1, 0, 0, 0] 48 | # upper_bounds = [1000, 60, 0.0001, 12, 1000, 60, 0, 0, 0] 49 | 50 | # low_bounds = [120, 1.5, 0.0045, 0.05, 600, 9, 0, 0, 0] 51 | # upper_bounds = [120, 1.5, 0.0045, 0.05, 600, 9, 0.5, 0.1, 100] 52 | 53 | low_bounds = [120, 1.5, 0.0045, 0.05, 600, 9, 0, 0] 54 | upper_bounds = [120, 1.5, 0.0045, 0.05, 600, 9, 0, 0.2] 55 | 56 | params = numpy.ndarray((orbits, nparams)) 57 | for o in range(orbits): 58 | for p in range(nparams): 59 | params[o][p] = random.uniform(low_bounds[p], upper_bounds[p]) 60 | 61 | # params = numpy.array([120, 1.5, 0.0045, 0.05, 600, 9, 0, 0, 0]) 62 | # params = numpy.matlib.repmat(params, orbits, 1) 63 | 64 | results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 65 | initx, params, solver, 66 | orbits, nequat, nnoi, 67 | dt, tspan, ksteps, localgroupsize) 68 | 69 | end = time.time() 70 | print("Simulation execution time: ", end - start, " seconds.") 71 | 72 | import matplotlib.pyplot as plt 73 | plt.plot(results[0, :]) 74 | plt.xlabel('Time') 75 | plt.ylabel('Value') 76 | plt.show() 77 | -------------------------------------------------------------------------------- /ci/intelOpenCLSilent.cfg: -------------------------------------------------------------------------------- 1 | # Patterns used to check silent configuration file 2 | # 3 | # anythingpat - any string 4 | # filepat - the file location pattern (/file/location/to/license.lic) 5 | # lspat - the license server address pattern (0123@hostname) 6 | # snpat - the serial number pattern (ABCD-01234567) 7 | # comppat - the component abbreviation (intel-component-0123.4-567__arch), use installer command line option to get it 8 | 9 | # Accept EULA, valid values are: {accept, decline} 10 | ACCEPT_EULA=accept 11 | 12 | # Optional error behavior, valid values are: {yes, no} 13 | CONTINUE_WITH_OPTIONAL_ERROR=yes 14 | 15 | # Install location, valid values are: {/opt/intel, filepat} 16 | PSET_INSTALL_DIR=/opt/intel 17 | 18 | # Continue with overwrite of existing installation directory, valid values are: {yes, no} 19 | CONTINUE_WITH_INSTALLDIR_OVERWRITE=yes 20 | 21 | # List of components to install (use semicolon to separate the components), valid values are: {ALL, DEFAULTS, comppat} 22 | COMPONENTS=DEFAULTS 23 | 24 | # Installation mode, valid values are: {install, repair, uninstall} 25 | PSET_MODE=install 26 | 27 | # Intel(R) Software Improvement Program 28 | # 29 | # To improve our software and customer experience, Intel would like to collect technical 30 | # information about your software installation and runtime status (such as installation metrics, 31 | # license/support types, software SKU/serial, counters, flags, and timestamps) 32 | # and development environment (such as operating system, CPU architecture, 33 | # last 4-digits of the MAC address and other Intel products installed). ("Information"). 34 | # 35 | # Intel may collect this Information directly or optionally through the use of Google Analytics. 36 | # If Google Analytics is used to collect the Information, Google will aggregate the 37 | # Information with that of other users and present the aggregated results to Intel without any personal identifiers. 38 | # Information collected by Google will be retained by Google under its own data collection policies 39 | # (https://www.google.com/policies/privacy/partners/). 40 | # 41 | # The Information collected under this notice directly by Intel through its Intel® Software Improvement Program 42 | # may be retained indefinitely but it will not be shared outside of Intel or its wholly-owned subsidiaries. 43 | # 44 | # The aggregated Information provided to Intel by Google through its Software Improvement Program 45 | # may be retained by Intel indefinitely but it will not be shared outside of Intel or its wholly-owned subsidiaries 46 | # 47 | # You can revoke your consent at any time by removing the "~/intel/isip" file. 48 | # To remove the file, please open a macOS or Linux terminal, go to the folder "~/intel" and delete the "isip" file. 49 | # For more details, please refer to this article: (https://software.intel.com/en-us/articles/software-improvement-program) 50 | # 51 | # Yes - I consent to the collection of my Information 52 | # No - I do NOT consent to the collection of my Information 53 | #, valid values are: {yes, no} 54 | INTEL_SW_IMPROVEMENT_PROGRAM_CONSENT=yes 55 | 56 | # Perform validation of digital signatures of RPM files, valid values are: {yes, no} 57 | SIGNING_ENABLED=yes 58 | -------------------------------------------------------------------------------- /cmake/CompilerWarnings.cmake: -------------------------------------------------------------------------------- 1 | # from here: 2 | # 3 | # https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md 4 | 5 | function(set_project_warnings project_name) 6 | option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE) 7 | 8 | set(MSVC_WARNINGS 9 | /W4 # Baseline reasonable warnings 10 | /w14242 # 'identfier': conversion from 'type1' to 'type1', possible loss 11 | # of data 12 | /w14254 # 'operator': conversion from 'type1:field_bits' to 13 | # 'type2:field_bits', possible loss of data 14 | /w14263 # 'function': member function does not override any base class 15 | # virtual member function 16 | /w14265 # 'classname': class has virtual functions, but destructor is not 17 | # virtual instances of this class may not be destructed correctly 18 | /w14287 # 'operator': unsigned/negative constant mismatch 19 | /we4289 # nonstandard extension used: 'variable': loop control variable 20 | # declared in the for-loop is used outside the for-loop scope 21 | /w14296 # 'operator': expression is always 'boolean_value' 22 | /w14311 # 'variable': pointer truncation from 'type1' to 'type2' 23 | /w14545 # expression before comma evaluates to a function which is missing 24 | # an argument list 25 | /w14546 # function call before comma missing argument list 26 | /w14547 # 'operator': operator before comma has no effect; expected 27 | # operator with side-effect 28 | /w14549 # 'operator': operator before comma has no effect; did you intend 29 | # 'operator'? 30 | /w14555 # expression has no effect; expected expression with side- effect 31 | /w14619 # pragma warning: there is no warning number 'number' 32 | /w14640 # Enable warning on thread un-safe static member initialization 33 | /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may 34 | # cause unexpected runtime behavior. 35 | /w14905 # wide string literal cast to 'LPSTR' 36 | /w14906 # string literal cast to 'LPWSTR' 37 | /w14928 # illegal copy-initialization; more than one user-defined 38 | # conversion has been implicitly applied 39 | ) 40 | 41 | set(CLANG_WARNINGS 42 | -Wall 43 | -Wextra # reasonable and standard 44 | -Wshadow # warn the user if a variable declaration shadows one from a 45 | # parent context 46 | -Wnon-virtual-dtor # warn the user if a class with virtual functions has a 47 | # non-virtual destructor. This helps catch hard to 48 | # track down memory errors 49 | -Wold-style-cast # warn for c-style casts 50 | -Wcast-align # warn for potential performance problem casts 51 | -Wunused # warn on anything being unused 52 | -Woverloaded-virtual # warn if you overload (not override) a virtual 53 | # function 54 | -Wpedantic # warn if non-standard C++ is used 55 | -Wconversion # warn on type conversions that may lose data 56 | -Wsign-conversion # warn on sign conversions 57 | -Wnull-dereference # warn if a null dereference is detected 58 | -Wdouble-promotion # warn if float is implicit promoted to double 59 | -Wformat=2 # warn on security issues around functions that format output 60 | # (ie printf) 61 | ) 62 | 63 | if (WARNINGS_AS_ERRORS) 64 | set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) 65 | set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) 66 | endif() 67 | 68 | set(GCC_WARNINGS 69 | ${CLANG_WARNINGS} 70 | -Wmisleading-indentation # warn if identation implies blocks where blocks 71 | # do not exist 72 | -Wduplicated-cond # warn if if / else chain has duplicated conditions 73 | -Wduplicated-branches # warn if if / else branches have duplicated code 74 | -Wlogical-op # warn about logical operations being used where bitwise were 75 | # probably wanted 76 | -Wuseless-cast # warn if you perform a cast to the same type 77 | ) 78 | 79 | if(MSVC) 80 | set(PROJECT_WARNINGS ${MSVC_WARNINGS}) 81 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 82 | set(PROJECT_WARNINGS ${CLANG_WARNINGS}) 83 | else() 84 | set(PROJECT_WARNINGS ${GCC_WARNINGS}) 85 | endif() 86 | 87 | target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) 88 | 89 | endfunction() -------------------------------------------------------------------------------- /cmake/ProjectDependences.cmake: -------------------------------------------------------------------------------- 1 | find_package(OpenCL REQUIRED) -------------------------------------------------------------------------------- /cmake/StandardProjectSettings.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 3 | message( 4 | STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") 5 | set(CMAKE_BUILD_TYPE 6 | RelWithDebInfo 7 | CACHE STRING "Choose the type of build." FORCE) 8 | # Set the possible values of build type for cmake-gui, ccmake 9 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" 10 | "MinSizeRel" "RelWithDebInfo") 11 | endif() -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(examples) 4 | 5 | set(EXAMPLE_SOURCE_FILES 6 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_euler.py 7 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_euler_stochastic.py 8 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_rk.py 9 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_ie.py 10 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_im.py 11 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor.cl 12 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto_euler.py 13 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto_euler_stochastic.py 14 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto.cl) 15 | 16 | set(EXAMPLE_FILES 17 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_euler.py 18 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_euler_stochastic.py 19 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_rk.py 20 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_ie.py 21 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_im.py 22 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor.cl 23 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto_euler.py 24 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto_euler_stochastic.py 25 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto.cl) 26 | 27 | add_custom_command(OUTPUT ${EXAMPLE_FILES} 28 | COMMAND ${CMAKE_COMMAND} -E copy ${EXAMPLE_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/ 29 | COMMENT "Copy example files" 30 | VERBATIM) 31 | 32 | add_custom_target(examples_copy ALL 33 | DEPENDS ${EXAMPLE_FILES} 34 | VERBATIM) -------------------------------------------------------------------------------- /examples/kuramoto.cl: -------------------------------------------------------------------------------- 1 | #define NOSC _numeq_ 2 | 3 | void sode_system(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 4 | { 5 | // Kuramoto model 6 | for (int i = 0; i 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import random 9 | import numpy 10 | import sodecl 11 | import matplotlib.pyplot as plt 12 | 13 | if __name__ == '__main__': 14 | 15 | openclplatform = 0 16 | opencldevice = 0 17 | openclkernel = 'kuramoto.cl' 18 | solver = 1 19 | dt = 0.05 20 | tspan = 50 21 | ksteps = 40 22 | localgroupsize = 0 23 | 24 | orbits = 2 25 | nequat = 3 26 | nparams = 4 27 | nnoi = 0 28 | 29 | # Initial conditions 30 | initx = numpy.ndarray((orbits, nequat)) 31 | for o in range(orbits): 32 | for p in range(nequat): 33 | initx[o][p] = random.uniform(-3.1416, 3.1416) 34 | 35 | # Parameters values 36 | params = numpy.ndarray((orbits, nparams)) 37 | for o in range(orbits): 38 | params[o][0] = 0.2 39 | for p in range(1,nequat+1): 40 | params[o][p] = random.uniform(0.2, 0.4) 41 | 42 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 43 | initx, params, solver, 44 | orbits, nequat, nnoi, 45 | dt, tspan, ksteps, localgroupsize) 46 | 47 | plt.plot(t, results[0, :]) 48 | plt.xlabel('Time') 49 | plt.ylabel('Value') 50 | plt.show() -------------------------------------------------------------------------------- /examples/kuramoto_euler_stochastic.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------// 2 | # Copyright (c) 2018 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import random 9 | import numpy 10 | import sodecl 11 | import matplotlib.pyplot as plt 12 | 13 | if __name__ == '__main__': 14 | 15 | openclplatform = 0 16 | opencldevice = 0 17 | openclkernel = 'kuramoto.cl' 18 | solver = 0 19 | dt = 0.05 20 | tspan = 50 21 | ksteps = 40 22 | localgroupsize = 0 23 | 24 | orbits = 2 25 | nequat = 3 26 | nparams = 4 27 | nnoi = 3 28 | 29 | # Initial conditions 30 | initx = numpy.ndarray((orbits, nequat)) 31 | for o in range(orbits): 32 | for p in range(nequat): 33 | initx[o][p] = random.uniform(-3.1416, 3.1416) 34 | 35 | # Parameters values 36 | params = numpy.ndarray((orbits, nparams)) 37 | for o in range(orbits): 38 | params[o][0] = 0.2 39 | for p in range(1,nequat+1): 40 | params[o][p] = random.uniform(0.2, 0.4) 41 | 42 | # Noise parameters values 43 | noise = numpy.ndarray((orbits, nequat)) 44 | for o in range(orbits): 45 | for p in range(nequat): 46 | noise[o][p] = random.uniform(0.01, 0.03) 47 | 48 | params = numpy.concatenate((params, noise), axis=1) 49 | 50 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 51 | initx, params, solver, 52 | orbits, nequat, nnoi, 53 | dt, tspan, ksteps, localgroupsize) 54 | 55 | plt.plot(t, results[0, :]) 56 | plt.xlabel('Time') 57 | plt.ylabel('Value') 58 | plt.show() -------------------------------------------------------------------------------- /examples/oculomotor.cl: -------------------------------------------------------------------------------- 1 | #define T1 0.15 2 | #define T2 0.012 3 | #define Tn 25.00 4 | 5 | double sburstf(double x, double aval, double bval, double atval, double btval) 6 | { 7 | double y; 8 | y = 0; 9 | 10 | if (x > 0) 11 | { 12 | y = (atval * (1.00 - exp(-x / btval))); 13 | } 14 | else 15 | { 16 | y = (-(aval / bval) * x * exp(x / bval)); 17 | } 18 | 19 | return y; 20 | } 21 | 22 | double dsburstf(double x, double aval, double bval, double atval, double btval) 23 | { 24 | double y; 25 | y = 0; 26 | 27 | if (x > 0) 28 | { 29 | y = (atval*exp(-x / btval)) / btval; 30 | } 31 | else 32 | { 33 | y = -((aval*exp(x / bval)) / bval + (aval*x*exp(x / bval)) / (bval*bval)); 34 | } 35 | return y; 36 | } 37 | 38 | void calc_jacobian(double y[_numeq_], double jac[_numeq_][_numeq_], double p[_numpar_]) 39 | { 40 | jac[0][0] = 0; 41 | jac[0][1] = 1; 42 | jac[0][2] = 0; 43 | jac[0][3] = 0; 44 | jac[0][4] = 0; 45 | jac[0][5] = 0; 46 | 47 | jac[1][0] = -1 / (T1*T2); 48 | jac[1][1] = -(1 / T1) - (1 / T2); 49 | jac[1][2] = 1 / (T1*T2); 50 | jac[1][3] = (1 / T1) + (1 / T2); 51 | jac[1][4] = -(1 / T1) - (1 / T2); 52 | jac[1][5] = 0; 53 | 54 | jac[2][0] = 0; 55 | jac[2][1] = 0; 56 | jac[2][2] = -1 / Tn; 57 | jac[2][3] = 1; 58 | jac[2][4] = -1; 59 | jac[2][5] = 0; 60 | 61 | jac[3][0] = 0; 62 | jac[3][1] = 0; 63 | jac[3][2] = 0; 64 | jac[3][3] = -(p[3] * (y[4] * y[4]) + 1) / p[2]; 65 | jac[3][4] = -(2 * p[3] * y[4] * y[3]) / p[2]; 66 | jac[3][5] = dsburstf(y[5], p[0], p[1], p[4], p[5]) / p[2]; 67 | 68 | jac[4][0] = 0; 69 | jac[4][1] = 0; 70 | jac[4][2] = 0; 71 | jac[4][3] = -(2 * p[3] * y[4] * y[3]) / p[2]; 72 | jac[4][4] = -(p[3] * (y[3] * y[3]) + 1) / p[2]; 73 | jac[4][5] = dsburstf(-y[5], p[0], p[1], p[4], p[5]) / p[2]; 74 | 75 | jac[5][0] = 0; 76 | jac[5][1] = 0; 77 | jac[5][2] = 0; 78 | jac[5][3] = -1; 79 | jac[5][4] = 1; 80 | jac[5][5] = 0; 81 | } 82 | 83 | void sode_system(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 84 | { 85 | // g 86 | yout[0] = y[1]; 87 | // u 88 | yout[1] = -(((1.00 / T1) + (1.00 / T2)) * y[1]) - (1.00 / (T1 * T2) * y[0]) + (1.00 / (T1 * T2) * y[2]) + ((1.00 / T1) + (1.00 / T2)) * (y[3] - y[4]); 89 | // n 90 | yout[2] = -(y[2] / Tn) + (y[3] - y[4]); 91 | //r 92 | yout[3] = (1.00 / p[2])*(-y[3] - (p[3] * y[3] * y[4] * y[4]) + sburstf(y[5], p[0], p[1], p[4], p[5])); 93 | // l 94 | yout[4] = (1.00 / p[2])*(-y[4] - (p[3] * y[4] * y[3] * y[3]) + sburstf(-y[5], p[0], p[1], p[4], p[5])); 95 | // m 96 | yout[5] = -(y[3] - y[4]); 97 | } 98 | 99 | void sode_system_stoch(double t, double y[_numeq_], double stoch[_numeq_], double p[_numpar_], double noise[_numnoi_]) 100 | { 101 | // g 102 | stoch[0] = 0; 103 | // u 104 | stoch[1] = ((1.00 / T1) + (1.00 / T2)) * (y[3] - y[4])*p[_numpar_ - _numnoi_ + 0] * noise[0] + p[_numpar_ - _numnoi_ + 1] * noise[1]; 105 | // n 106 | stoch[2] = 0; 107 | // r 108 | stoch[3] = 0; 109 | // l 110 | stoch[4] = 0; 111 | // m 112 | stoch[5] = 0; 113 | } -------------------------------------------------------------------------------- /examples/oculomotor_euler.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import sodecl 3 | import pickle 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__ == '__main__': 7 | 8 | openclplatform = 0 9 | opencldevice = 0 10 | openclkernel = 'oculomotor.cl' 11 | solver = 1 12 | dt = 1e-8 13 | tspan = 0.1 14 | ksteps = 40000 15 | localgroupsize = 0 16 | 17 | orbits = 2 18 | nequat = 6 19 | nparams = 6 20 | nnoi = 0 21 | 22 | # Initial conditions 23 | initx = numpy.ndarray((orbits, nequat)) 24 | for o in range(orbits): 25 | initx[o][0] = 0.0 26 | initx[o][1] = 0.0 27 | initx[o][2] = 0.0 28 | initx[o][3] = 0.0 29 | initx[o][4] = 0.0 30 | initx[o][5] = 2.0 31 | 32 | # Parameters values 33 | params = numpy.ndarray((orbits, nparams)) 34 | for o in range(orbits): 35 | params[o][0] = 120 36 | params[o][1] = 1.5 37 | params[o][2] = 0.0045 38 | params[o][3] = 0.05 39 | params[o][4] = 600 40 | params[o][5] = 9 41 | 42 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 43 | initx, params, solver, 44 | orbits, nequat, nnoi, 45 | dt, tspan, ksteps, localgroupsize) 46 | 47 | pickle.dump(results, open("oculomotor_euler.pkl", "wb")) 48 | 49 | plt.plot(t, results[0, :]) 50 | plt.xlabel('Time') 51 | plt.ylabel('Value') 52 | plt.show() 53 | -------------------------------------------------------------------------------- /examples/oculomotor_euler_stochastic.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------// 2 | # Copyright (c) 2017 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import numpy 9 | import sodecl 10 | import matplotlib.pyplot as plt 11 | 12 | if __name__ == '__main__': 13 | 14 | openclplatform = 0 15 | opencldevice = 0 16 | openclkernel = 'oculomotor.cl' 17 | solver = 0 18 | dt = 1e-8 19 | tspan = 1 20 | ksteps = 40000 21 | localgroupsize = 0 22 | 23 | orbits = 2 24 | nequat = 6 25 | nparams = 6 26 | nnoi = 2 27 | 28 | # Initial conditions 29 | initx = numpy.ndarray((orbits, nequat)) 30 | for o in range(orbits): 31 | initx[o][0] = 0.0 32 | initx[o][1] = 0.0 33 | initx[o][2] = 0.0 34 | initx[o][3] = 0.0 35 | initx[o][4] = 0.0 36 | initx[o][5] = 2.0 37 | 38 | # Parameters values 39 | params = numpy.ndarray((orbits, nparams)) 40 | for o in range(orbits): 41 | params[o][0] = 120 42 | params[o][1] = 1.5 43 | params[o][2] = 0.0045 44 | params[o][3] = 0.05 45 | params[o][4] = 600 46 | params[o][5] = 9 47 | 48 | # Noise parameters values 49 | noise = numpy.ndarray((orbits, nnoi)) 50 | for o in range(orbits): 51 | noise[o][0] = 0.05 52 | noise[o][1] = 50 53 | 54 | params = numpy.concatenate((params, noise), axis=1) 55 | 56 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 57 | initx, params, solver, 58 | orbits, nequat, nnoi, 59 | dt, tspan, ksteps, localgroupsize) 60 | 61 | plt.plot(t, results[0, :]) 62 | plt.xlabel('Time') 63 | plt.ylabel('Value') 64 | plt.show() 65 | -------------------------------------------------------------------------------- /examples/oculomotor_ie.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import sodecl 3 | import pickle 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__ == '__main__': 7 | 8 | openclplatform = 0 9 | opencldevice = 0 10 | openclkernel = 'oculomotor.cl' 11 | solver = 3 12 | dt = 1e-6 13 | tspan = 0.1 14 | ksteps = 400 15 | localgroupsize = 0 16 | 17 | orbits = 2 18 | nequat = 6 19 | nparams = 6 20 | nnoi = 0 21 | 22 | # Initial conditions 23 | initx = numpy.ndarray((orbits, nequat)) 24 | for o in range(orbits): 25 | initx[o][0] = 0.0 26 | initx[o][1] = 0.0 27 | initx[o][2] = 0.0 28 | initx[o][3] = 0.0 29 | initx[o][4] = 0.0 30 | initx[o][5] = 2.0 31 | 32 | # Parameters values 33 | params = numpy.ndarray((orbits, nparams)) 34 | for o in range(orbits): 35 | params[o][0] = 120 36 | params[o][1] = 1.5 37 | params[o][2] = 0.0045 38 | params[o][3] = 0.05 39 | params[o][4] = 600 40 | params[o][5] = 9 41 | 42 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 43 | initx, params, solver, 44 | orbits, nequat, nnoi, 45 | dt, tspan, ksteps, localgroupsize) 46 | 47 | pickle.dump(results, open("oculomotor_ie.pkl", "wb")) 48 | 49 | plt.plot(t, results[0, :]) 50 | plt.xlabel('Time') 51 | plt.ylabel('Value') 52 | plt.show() 53 | -------------------------------------------------------------------------------- /examples/oculomotor_im.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import sodecl 3 | import pickle 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__ == '__main__': 7 | 8 | openclplatform = 0 9 | opencldevice = 0 10 | openclkernel = 'oculomotor.cl' 11 | solver = 4 12 | dt = 1e-6 13 | tspan = 0.1 14 | ksteps = 400 15 | localgroupsize = 0 16 | 17 | orbits = 2 18 | nequat = 6 19 | nparams = 6 20 | nnoi = 0 21 | 22 | # Initial conditions 23 | initx = numpy.ndarray((orbits, nequat)) 24 | for o in range(orbits): 25 | initx[o][0] = 0.0 26 | initx[o][1] = 0.0 27 | initx[o][2] = 0.0 28 | initx[o][3] = 0.0 29 | initx[o][4] = 0.0 30 | initx[o][5] = 2.0 31 | 32 | # Parameters values 33 | params = numpy.ndarray((orbits, nparams)) 34 | for o in range(orbits): 35 | params[o][0] = 120 36 | params[o][1] = 1.5 37 | params[o][2] = 0.0045 38 | params[o][3] = 0.05 39 | params[o][4] = 600 40 | params[o][5] = 9 41 | 42 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 43 | initx, params, solver, 44 | orbits, nequat, nnoi, 45 | dt, tspan, ksteps, localgroupsize) 46 | 47 | pickle.dump(results, open("oculomotor_im.pkl", "wb")) 48 | 49 | plt.plot(t, results[0, :]) 50 | plt.xlabel('Time') 51 | plt.ylabel('Value') 52 | plt.show() 53 | -------------------------------------------------------------------------------- /examples/oculomotor_rk.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import sodecl 3 | import pickle 4 | import matplotlib.pyplot as plt 5 | 6 | if __name__ == '__main__': 7 | 8 | openclplatform = 0 9 | opencldevice = 0 10 | openclkernel = 'oculomotor.cl' 11 | solver = 2 12 | dt = 1e-6 13 | tspan = 0.1 14 | ksteps = 400 15 | localgroupsize = 0 16 | 17 | orbits = 2 18 | nequat = 6 19 | nparams = 6 20 | nnoi = 0 21 | 22 | # Initial conditions 23 | initx = numpy.ndarray((orbits, nequat)) 24 | for o in range(orbits): 25 | initx[o][0] = 0.0 26 | initx[o][1] = 0.0 27 | initx[o][2] = 0.0 28 | initx[o][3] = 0.0 29 | initx[o][4] = 0.0 30 | initx[o][5] = 2.0 31 | 32 | # Parameters values 33 | params = numpy.ndarray((orbits, nparams)) 34 | for o in range(orbits): 35 | params[o][0] = 120 36 | params[o][1] = 1.5 37 | params[o][2] = 0.0045 38 | params[o][3] = 0.05 39 | params[o][4] = 600 40 | params[o][5] = 9 41 | 42 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 43 | initx, params, solver, 44 | orbits, nequat, nnoi, 45 | dt, tspan, ksteps, localgroupsize) 46 | 47 | pickle.dump(results, open("oculomotor_rk.pkl", "wb")) 48 | 49 | plt.plot(t, results[0, :]) 50 | plt.xlabel('Time') 51 | plt.ylabel('Value') 52 | plt.show() 53 | -------------------------------------------------------------------------------- /external/include/Random123/LICENSE: -------------------------------------------------------------------------------- 1 | /** @page LICENSE 2 | Copyright 2010-2012, 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 | -------------------------------------------------------------------------------- /external/include/Random123/MicroURNG.hpp: -------------------------------------------------------------------------------- 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 __MicroURNG_dot_hpp__ 33 | #define __MicroURNG_dot_hpp__ 34 | 35 | #include 36 | #include 37 | 38 | namespace r123{ 39 | /** 40 | Given a CBRNG whose ctr_type has an unsigned integral value_type, 41 | MicroURNG(c, k) is a type that satisfies the 42 | requirements of a C++0x Uniform Random Number Generator. 43 | 44 | The intended purpose is for a MicroURNG to be passed 45 | as an argument to a C++0x Distribution, e.g., 46 | std::normal_distribution. See examples/MicroURNG.cpp. 47 | 48 | The MicroURNG functor has a period of "only" 49 | 50 | ctr_type.size()*2^32, 51 | 52 | after which it will silently repeat. 53 | 54 | The high 32 bits of the highest word in the counter c, passed to 55 | the constructor must be zero. MicroURNG uses these bits to 56 | "count". 57 | 58 | Older versions of the library permitted a second template 59 | parameter by which the caller could control the number of 60 | bits devoted to the URNG's internal counter. This flexibility 61 | has been disabled because URNGs created with different 62 | numbers of counter bits could, conceivably "collide". 63 | 64 | \code 65 | typedef ?someCBRNG? RNG; 66 | RNG::ctr_type c = ...; // under application control 67 | RNG::key_type k = ...; // 68 | std::normal_distribution nd; 69 | MicroURNG urng(c, k); 70 | for(???){ 71 | ... 72 | nd(urng); // may be called several hundred times with BITS=10 73 | ... 74 | } 75 | \endcode 76 | */ 77 | 78 | template 79 | class MicroURNG{ 80 | // According to C++0x, a URNG requires only a result_type, 81 | // operator()(), min() and max() methods. Everything else 82 | // (ctr_type, key_type, reset() method, etc.) is "value added" 83 | // for the benefit of users that "know" that they're dealing with 84 | // a MicroURNG. 85 | public: 86 | typedef CBRNG cbrng_type; 87 | static const int BITS = 32; 88 | typedef typename cbrng_type::ctr_type ctr_type; 89 | typedef typename cbrng_type::key_type key_type; 90 | typedef typename cbrng_type::ukey_type ukey_type; 91 | typedef typename ctr_type::value_type result_type; 92 | 93 | R123_STATIC_ASSERT( std::numeric_limits::digits >= BITS, "The result_type must have at least 32 bits" ); 94 | 95 | result_type operator()(){ 96 | if(last_elem == 0){ 97 | // jam n into the high bits of c 98 | const size_t W = std::numeric_limits::digits; 99 | ctr_type c = c0; 100 | c[c0.size()-1] |= n<<(W-BITS); 101 | rdata = b(c,k); 102 | n++; 103 | last_elem = rdata.size(); 104 | } 105 | return rdata[--last_elem]; 106 | } 107 | MicroURNG(cbrng_type _b, ctr_type _c0, ukey_type _uk) : b(_b), c0(_c0), k(_uk), n(0), last_elem(0) { 108 | chkhighbits(); 109 | } 110 | MicroURNG(ctr_type _c0, ukey_type _uk) : b(), c0(_c0), k(_uk), n(0), last_elem(0) { 111 | chkhighbits(); 112 | } 113 | 114 | // _Min and _Max work around a bug in the library shipped with MacOS Xcode 4.5.2. 115 | // See the commment in conventional/Engine.hpp. 116 | const static result_type _Min = 0; 117 | const static result_type _Max = ~((result_type)0); 118 | 119 | static R123_CONSTEXPR result_type min R123_NO_MACRO_SUBST () { return _Min; } 120 | static R123_CONSTEXPR result_type max R123_NO_MACRO_SUBST () { return _Max; } 121 | // extra methods: 122 | const ctr_type& counter() const{ return c0; } 123 | void reset(ctr_type _c0, ukey_type _uk){ 124 | c0 = _c0; 125 | chkhighbits(); 126 | k = _uk; 127 | n = 0; 128 | last_elem = 0; 129 | } 130 | 131 | private: 132 | cbrng_type b; 133 | ctr_type c0; 134 | key_type k; 135 | R123_ULONG_LONG n; 136 | size_t last_elem; 137 | ctr_type rdata; 138 | void chkhighbits(){ 139 | result_type r = c0[c0.size()-1]; 140 | result_type mask = ((uint64_t)std::numeric_limits::max R123_NO_MACRO_SUBST ())>>BITS; 141 | if((r&mask) != r) 142 | throw std::runtime_error("MicroURNG: c0, does not have high bits clear"); 143 | } 144 | }; 145 | } // namespace r123 146 | #endif 147 | -------------------------------------------------------------------------------- /external/include/Random123/ReinterpretCtr.hpp: -------------------------------------------------------------------------------- 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 __ReinterpretCtr_dot_hpp__ 33 | #define __ReinterpretCtr_dot_hpp__ 34 | 35 | #include "features/compilerfeatures.h" 36 | #include 37 | 38 | namespace r123{ 39 | /*! 40 | ReinterpretCtr uses memcpy to map back and forth 41 | between a CBRNG's ctr_type and the specified ToType. For example, 42 | after: 43 | 44 | typedef ReinterpretCtr G; 45 | 46 | G is a bona fide CBRNG with ctr_type r123array4x32. 47 | 48 | WARNING: ReinterpretCtr is endian dependent. The 49 | values returned by G, declared as above, 50 | will depend on the endianness of the machine on which it runs. 51 | */ 52 | 53 | template 54 | struct ReinterpretCtr{ 55 | typedef ToType ctr_type; 56 | typedef typename CBRNG::key_type key_type; 57 | typedef typename CBRNG::ctr_type bctype; 58 | typedef typename CBRNG::ukey_type ukey_type; 59 | R123_STATIC_ASSERT(sizeof(ToType) == sizeof(bctype) && sizeof(typename bctype::value_type) != 16, 60 | "ReinterpretCtr: sizeof(ToType) is not the same as sizeof(CBRNG::ctr_type) or CBRNG::ctr_type::value_type looks like it might be __m128i"); 61 | // It's amazingly difficult to safely do conversions with __m128i. 62 | // If we use the operator() implementation below with a CBRNG 63 | // whose ctr_type is r123array1xm128i, gcc4.6 optimizes away the 64 | // memcpys, inlines the operator()(c,k), and produces assembly 65 | // language that ends with an aesenclast instruction with a 66 | // destination operand pointing to an unaligned memory address ... 67 | // Segfault! See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50444 68 | // MSVC also produces code that crashes. We suspect a 69 | // similar mechanism but haven't done the debugging necessary to 70 | // be sure. We were able to 'fix' gcc4.6 by making bc a mutable 71 | // data member rather than declaring it in the scope of 72 | // operator(). That didn't fix the MSVC problems, though. 73 | // 74 | // Conclusion - don't touch __m128i, at least for now. The 75 | // easiest (but highly imprecise) way to do that is the static 76 | // assertion above that rejects bctype::value_types of size 16. - 77 | // Sep 2011. 78 | ctr_type operator()(ctr_type c, key_type k){ 79 | bctype bc; 80 | std::memcpy(&bc, &c, sizeof(c)); 81 | CBRNG b; 82 | bc = b(bc, k); 83 | std::memcpy(&c, &bc, sizeof(bc)); 84 | return c; 85 | } 86 | }; 87 | } // namespace r123 88 | #endif 89 | -------------------------------------------------------------------------------- /external/include/Random123/ars.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 __Random123_ars_dot_hpp__ 33 | #define __Random123_ars_dot_hpp__ 34 | 35 | #include "features/compilerfeatures.h" 36 | #include "array.h" 37 | 38 | #if R123_USE_AES_NI 39 | 40 | #ifndef ARS1xm128i_DEFAULT_ROUNDS 41 | #define ARS1xm128i_DEFAULT_ROUNDS 7 42 | #endif 43 | 44 | /** @ingroup AESNI */ 45 | enum r123_enum_ars1xm128i {ars1xm128i_rounds = ARS1xm128i_DEFAULT_ROUNDS}; 46 | 47 | /* ARS1xm128i with Weyl keys. Fast, and Crush-resistant, but NOT CRYPTO. */ 48 | /** @ingroup AESNI */ 49 | typedef struct r123array1xm128i ars1xm128i_ctr_t; 50 | /** @ingroup AESNI */ 51 | typedef struct r123array1xm128i ars1xm128i_key_t; 52 | /** @ingroup AESNI */ 53 | typedef struct r123array1xm128i ars1xm128i_ukey_t; 54 | /** @ingroup AESNI */ 55 | R123_STATIC_INLINE ars1xm128i_key_t ars1xm128ikeyinit(ars1xm128i_ukey_t uk) { return uk; } 56 | /** @ingroup AESNI */ 57 | R123_STATIC_INLINE ars1xm128i_ctr_t ars1xm128i_R(unsigned int Nrounds, ars1xm128i_ctr_t in, ars1xm128i_key_t k){ 58 | __m128i kweyl = _mm_set_epi64x(R123_64BIT(0xBB67AE8584CAA73B), /* sqrt(3) - 1.0 */ 59 | R123_64BIT(0x9E3779B97F4A7C15)); /* golden ratio */ 60 | /* N.B. the aesenc instructions do the xor *after* 61 | // so if we want to follow the AES pattern, we 62 | // have to do the initial xor explicitly */ 63 | __m128i kk = k.v[0].m; 64 | __m128i v = _mm_xor_si128(in.v[0].m, kk); 65 | ars1xm128i_ctr_t ret; 66 | R123_ASSERT(Nrounds<=10); 67 | if( Nrounds>1 ){ 68 | kk = _mm_add_epi64(kk, kweyl); 69 | v = _mm_aesenc_si128(v, kk); 70 | } 71 | if( Nrounds>2 ){ 72 | kk = _mm_add_epi64(kk, kweyl); 73 | v = _mm_aesenc_si128(v, kk); 74 | } 75 | if( Nrounds>3 ){ 76 | kk = _mm_add_epi64(kk, kweyl); 77 | v = _mm_aesenc_si128(v, kk); 78 | } 79 | if( Nrounds>4 ){ 80 | kk = _mm_add_epi64(kk, kweyl); 81 | v = _mm_aesenc_si128(v, kk); 82 | } 83 | if( Nrounds>5 ){ 84 | kk = _mm_add_epi64(kk, kweyl); 85 | v = _mm_aesenc_si128(v, kk); 86 | } 87 | if( Nrounds>6 ){ 88 | kk = _mm_add_epi64(kk, kweyl); 89 | v = _mm_aesenc_si128(v, kk); 90 | } 91 | if( Nrounds>7 ){ 92 | kk = _mm_add_epi64(kk, kweyl); 93 | v = _mm_aesenc_si128(v, kk); 94 | } 95 | if( Nrounds>8 ){ 96 | kk = _mm_add_epi64(kk, kweyl); 97 | v = _mm_aesenc_si128(v, kk); 98 | } 99 | if( Nrounds>9 ){ 100 | kk = _mm_add_epi64(kk, kweyl); 101 | v = _mm_aesenc_si128(v, kk); 102 | } 103 | kk = _mm_add_epi64(kk, kweyl); 104 | v = _mm_aesenclast_si128(v, kk); 105 | ret.v[0].m = v; 106 | return ret; 107 | } 108 | 109 | /** @def ars1xm128i 110 | @ingroup AESNI 111 | The ars1mx128i macro provides a C API interface to the @ref AESNI "ARS" CBRNG with the default number of rounds i.e. \c ars1xm128i_rounds **/ 112 | #define ars1xm128i(c,k) ars1xm128i_R(ars1xm128i_rounds, c, k) 113 | 114 | /** @ingroup AESNI */ 115 | typedef struct r123array4x32 ars4x32_ctr_t; 116 | /** @ingroup AESNI */ 117 | typedef struct r123array4x32 ars4x32_key_t; 118 | /** @ingroup AESNI */ 119 | typedef struct r123array4x32 ars4x32_ukey_t; 120 | /** @ingroup AESNI */ 121 | enum r123_enum_ars4x32 {ars4x32_rounds = ARS1xm128i_DEFAULT_ROUNDS}; 122 | /** @ingroup AESNI */ 123 | R123_STATIC_INLINE ars4x32_key_t ars4x32keyinit(ars4x32_ukey_t uk) { return uk; } 124 | /** @ingroup AESNI */ 125 | R123_STATIC_INLINE ars4x32_ctr_t ars4x32_R(unsigned int Nrounds, ars4x32_ctr_t c, ars4x32_key_t k){ 126 | ars1xm128i_ctr_t c128; 127 | ars1xm128i_key_t k128; 128 | c128.v[0].m = _mm_set_epi32(c.v[3], c.v[2], c.v[1], c.v[0]); 129 | k128.v[0].m = _mm_set_epi32(k.v[3], k.v[2], k.v[1], k.v[0]); 130 | c128 = ars1xm128i_R(Nrounds, c128, k128); 131 | _mm_storeu_si128((__m128i*)&c.v[0], c128.v[0].m); 132 | return c; 133 | } 134 | 135 | /** @def ars4x32 136 | @ingroup AESNI 137 | The ars4x32 macro provides a C API interface to the @ref AESNI "ARS" CBRNG with the default number of rounds i.e. \c ars4x32_rounds **/ 138 | #define ars4x32(c,k) ars4x32_R(ars4x32_rounds, c, k) 139 | 140 | #ifdef __cplusplus 141 | namespace r123{ 142 | /** 143 | @ingroup AESNI 144 | 145 | ARS1xm128i_R exports the member functions, typedefs and operator overloads required by a @ref CBRNG class. 146 | 147 | ARS1xm128i uses the crypotgraphic AES round function, but a @b non-cryptographc key schedule 148 | to save time and space. 149 | 150 | ARS1xm128i is only available when the feature-test macro R123_USE_AES_NI is true, which 151 | should occur only when the compiler is configured to generate AES-NI instructions (or 152 | when defaults are overridden by compile-time, compiler-command-line options). 153 | 154 | The template argument, ROUNDS, is the number of times the ARS round 155 | functions will be applied. 156 | 157 | As of September 2011, the authors know of no statistical flaws with 158 | ROUNDS=5 or more. 159 | 160 | @class ARS1xm128i_R 161 | 162 | */ 163 | template 164 | struct ARS1xm128i_R{ 165 | typedef ars1xm128i_ctr_t ctr_type; 166 | typedef ars1xm128i_key_t key_type; 167 | typedef ars1xm128i_key_t ukey_type; 168 | static const unsigned int rounds=ROUNDS; 169 | R123_FORCE_INLINE(ctr_type operator()(ctr_type ctr, key_type key) const){ 170 | return ars1xm128i_R(ROUNDS, ctr, key); 171 | } 172 | }; 173 | 174 | /** @class ARS4x32_R 175 | @ingroup AESNI 176 | */ 177 | 178 | template 179 | struct ARS4x32_R{ 180 | typedef ars4x32_ctr_t ctr_type; 181 | typedef ars4x32_key_t key_type; 182 | typedef ars4x32_key_t ukey_type; 183 | static const unsigned int rounds=ROUNDS; 184 | R123_FORCE_INLINE(ctr_type operator()(ctr_type ctr, key_type key) const){ 185 | return ars4x32_R(ROUNDS, ctr, key); 186 | } 187 | }; 188 | /** 189 | @ingroup AESNI 190 | 191 | @class ARS1xm128i_R 192 | ARS1xm128i is equivalent to ARS1xm128i_R<7>. With 7 rounds, 193 | the ARS1xm128i CBRNG has a considerable safety margin over the minimum number 194 | of rounds with no known statistical flaws, but still has excellent 195 | performance. */ 196 | typedef ARS1xm128i_R ARS1xm128i; 197 | typedef ARS4x32_R ARS4x32; 198 | } // namespace r123 199 | 200 | #endif /* __cplusplus */ 201 | 202 | #endif /* R123_USE_AES_NI */ 203 | 204 | #endif 205 | -------------------------------------------------------------------------------- /external/include/Random123/conventional/gsl_cbrng.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 __r123_compat_gslrng_dot_h__ 33 | #define __r123_compat_gslrng_dot_h__ 34 | 35 | #include 36 | #include 37 | 38 | /** 39 | The macro: GSL_CBRNG(NAME, CBRNGNAME) 40 | declares the necessary structs and constants that define a 41 | gsl_rng_NAME type based on the counter-based RNG CBRNGNAME. For example: 42 | 43 | Usage: 44 | 45 | @code 46 | #include 47 | #include // this file 48 | GSL_CBRNG(cbrng, threefry4x32); // creates gsl_rng_cbrng 49 | 50 | int main(int argc, char **argv){ 51 | gsl_rng *r = gsl_rng_alloc(gsl_rng_cbrng); 52 | ... use r as you would use any other gsl_rng ... 53 | } 54 | @endcode 55 | 56 | It requires that NAME be the name of a CBRNG that follows the 57 | naming and stylistic conventions of the Random123 library. 58 | 59 | Note that wrapping a \ref CBRNG "counter-based PRNG" with a traditional API in 60 | this way obscures much of the power of the CBRNG API. 61 | Nevertheless, it may be of value to applications that are already 62 | coded to work with GSL random number generators, and that wish 63 | to use the RNGs in the Random123 library. 64 | 65 | */ 66 | 67 | #define GSL_CBRNG(NAME, CBRNGNAME) \ 68 | const gsl_rng_type *gsl_rng_##NAME; \ 69 | \ 70 | typedef struct{ \ 71 | CBRNGNAME##_ctr_t ctr; \ 72 | CBRNGNAME##_ctr_t r; \ 73 | CBRNGNAME##_key_t key; \ 74 | int elem; \ 75 | } NAME##_state; \ 76 | \ 77 | static unsigned long int NAME##_get(void *vstate){ \ 78 | NAME##_state *st = (NAME##_state *)vstate; \ 79 | const int N=sizeof(st->ctr.v)/sizeof(st->ctr.v[0]); \ 80 | if( st->elem == 0 ){ \ 81 | ++st->ctr.v[0]; \ 82 | if( N>1 && st->ctr.v[0] == 0 ) ++st->ctr.v[1]; \ 83 | if( N>2 && st->ctr.v[1] == 0 ) ++st->ctr.v[2]; \ 84 | if( N>3 && st->ctr.v[2] == 0 ) ++st->ctr.v[3]; \ 85 | st->r = CBRNGNAME(st->ctr, st->key); \ 86 | st->elem = N; \ 87 | } \ 88 | return 0xffffffffUL & st->r.v[--st->elem]; \ 89 | } \ 90 | \ 91 | static double \ 92 | NAME##_get_double (void * vstate) \ 93 | { \ 94 | return NAME##_get (vstate)/4294967296.0; \ 95 | } \ 96 | \ 97 | static void NAME##_set(void *vstate, unsigned long int s){ \ 98 | NAME##_state *st = (NAME##_state *)vstate; \ 99 | st->elem = 0; \ 100 | /* Assume that key and ctr have an array member, v, \ 101 | as if they are r123arrayNxW. If not, this will fail \ 102 | to compile. In particular, this macro fails to compile \ 103 | when the underlying CBRNG requires use of keyinit */ \ 104 | memset(&st->ctr.v[0], 0, sizeof(st->ctr.v)); \ 105 | memset(&st->key.v[0], 0, sizeof(st->key.v)); \ 106 | /* GSL 1.15 documentation says this about gsl_rng_set: \ 107 | Note that the most generators only accept 32-bit seeds, with higher \ 108 | values being reduced modulo 2^32. For generators with smaller \ 109 | ranges the maximum seed value will typically be lower. \ 110 | so we won't jump through any hoops here to deal with \ 111 | high bits if sizeof(unsigned long) > sizeof(uint32_t). */ \ 112 | st->key.v[0] = s; \ 113 | } \ 114 | \ 115 | static const gsl_rng_type NAME##_type = { \ 116 | #NAME, \ 117 | 0xffffffffUL, \ 118 | 0, \ 119 | sizeof(NAME##_state), \ 120 | &NAME##_set, \ 121 | &NAME##_get, \ 122 | &NAME##_get_double \ 123 | }; \ 124 | \ 125 | const gsl_rng_type *gsl_rng_##NAME = &NAME##_type 126 | 127 | #endif 128 | 129 | -------------------------------------------------------------------------------- /external/include/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 | -------------------------------------------------------------------------------- /external/include/Random123/features/iccfeatures.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 __icpcfeatures_dot_hpp 33 | #define __icpcfeatures_dot_hpp 34 | 35 | // icc relies on gcc libraries and other toolchain components. 36 | #define R123_GNUC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) 37 | 38 | #if !defined(__x86_64__) && !defined(__i386__) 39 | # error "This code has only been tested on x86 platforms." 40 | { // maybe an unbalanced brace will terminate the compilation 41 | // You are invited to try Easy123 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 | #ifndef R123_STATIC_INLINE 48 | #define R123_STATIC_INLINE static inline 49 | #endif 50 | 51 | #ifndef R123_FORCE_INLINE 52 | #define R123_FORCE_INLINE(decl) decl __attribute__((always_inline)) 53 | #endif 54 | 55 | #ifndef R123_CUDA_DEVICE 56 | #define R123_CUDA_DEVICE 57 | #endif 58 | 59 | #ifndef R123_ASSERT 60 | #include 61 | #define R123_ASSERT(x) assert(x) 62 | #endif 63 | 64 | #ifndef R123_BUILTIN_EXPECT 65 | #define R123_BUILTIN_EXPECT(expr,likely) __builtin_expect(expr,likely) 66 | #endif 67 | 68 | // The basic idiom is: 69 | // #ifndef R123_SOMETHING 70 | // #if some condition 71 | // #define R123_SOMETHING 1 72 | // #else 73 | // #define R123_SOMETHING 0 74 | // #endif 75 | // #endif 76 | // This idiom allows an external user to override any decision 77 | // in this file with a command-line -DR123_SOMETHING=1 or -DR123_SOMETHINE=0 78 | 79 | // An alternative idiom is: 80 | // #ifndef R123_SOMETHING 81 | // #define R123_SOMETHING (some boolean expression) 82 | // #endif 83 | // where the boolean expression might contain previously-defined R123_SOMETHING_ELSE 84 | // pp-symbols. 85 | 86 | #ifndef R123_USE_SSE4_2 87 | #ifdef __SSE4_2__ 88 | #define R123_USE_SSE4_2 1 89 | #else 90 | #define R123_USE_SSE4_2 0 91 | #endif 92 | #endif 93 | 94 | #ifndef R123_USE_SSE4_1 95 | #ifdef __SSE4_1__ 96 | #define R123_USE_SSE4_1 1 97 | #else 98 | #define R123_USE_SSE4_1 0 99 | #endif 100 | #endif 101 | 102 | #ifndef R123_USE_SSE 103 | #ifdef __SSE2__ 104 | #define R123_USE_SSE 1 105 | #else 106 | #define R123_USE_SSE 0 107 | #endif 108 | #endif 109 | 110 | #ifndef R123_USE_AES_NI 111 | // Unlike gcc, icc (version 12) does not pre-define an __AES__ 112 | // pp-symbol when -maes or -xHost is on the command line. This feels 113 | // like a defect in icc (it defines __SSE4_2__ in analogous 114 | // circumstances), but until Intel fixes it, we're better off erring 115 | // on the side of caution and not generating instructions that are 116 | // going to raise SIGILL when executed. To get the AES-NI 117 | // instructions with icc, the caller must puts something like 118 | // -DR123_USE_AES_NI=1 or -D__AES__ on the command line. FWIW, the 119 | // AES-NI Whitepaper by Gueron says that icc has supported AES-NI from 120 | // 11.1 onwards. 121 | // 122 | #define R123_USE_AES_NI ((__ICC>=1101) && defined(__AES__)) 123 | #endif 124 | 125 | #ifndef R123_USE_AES_OPENSSL 126 | /* There isn't really a good way to tell at compile time whether 127 | openssl is available. Without a pre-compilation configure-like 128 | tool, it's less error-prone to guess that it isn't available. Add 129 | -DR123_USE_AES_OPENSSL=1 and any necessary LDFLAGS or LDLIBS to 130 | play with openssl */ 131 | #define R123_USE_AES_OPENSSL 0 132 | #endif 133 | 134 | #ifndef R123_USE_GNU_UINT128 135 | #define R123_USE_GNU_UINT128 0 136 | #endif 137 | 138 | #ifndef R123_USE_ASM_GNU 139 | #define R123_USE_ASM_GNU 1 140 | #endif 141 | 142 | #ifndef R123_USE_CPUID_MSVC 143 | #define R123_USE_CPUID_MSVC 0 144 | #endif 145 | 146 | #ifndef R123_USE_X86INTRIN_H 147 | #define R123_USE_X86INTRIN_H 0 148 | #endif 149 | 150 | #ifndef R123_USE_IA32INTRIN_H 151 | #define R123_USE_IA32INTRIN_H 1 152 | #endif 153 | 154 | #ifndef R123_USE_XMMINTRIN_H 155 | #define R123_USE_XMMINTRIN_H 0 156 | #endif 157 | 158 | #ifndef R123_USE_EMMINTRIN_H 159 | #define R123_USE_EMMINTRIN_H 1 160 | #endif 161 | 162 | #ifndef R123_USE_SMMINTRIN_H 163 | #define R123_USE_SMMINTRIN_H 1 164 | #endif 165 | 166 | #ifndef R123_USE_WMMINTRIN_H 167 | #define R123_USE_WMMINTRIN_H 1 168 | #endif 169 | 170 | #ifndef R123_USE_INTRIN_H 171 | #define R123_USE_INTRIN_H 0 172 | #endif 173 | 174 | #ifndef R123_USE_MULHILO16_ASM 175 | #define R123_USE_MULHILO16_ASM 0 176 | #endif 177 | 178 | #ifndef R123_USE_MULHILO32_ASM 179 | #define R123_USE_MULHILO32_ASM 0 180 | #endif 181 | 182 | #ifndef R123_USE_MULHILO64_ASM 183 | #define R123_USE_MULHILO64_ASM 1 184 | #endif 185 | 186 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 187 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 188 | #endif 189 | 190 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 191 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 192 | #endif 193 | 194 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 195 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 196 | #endif 197 | 198 | #ifndef __STDC_CONSTANT_MACROS 199 | #define __STDC_CONSTANT_MACROS 200 | #endif 201 | #include 202 | #ifndef UINT64_C 203 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 204 | #endif 205 | 206 | // If you add something, it must go in all the other XXfeatures.hpp 207 | // and in ../ut_features.cpp 208 | #endif 209 | -------------------------------------------------------------------------------- /external/include/Random123/features/llvmfeatures.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 __llvmfeatures_dot_hpp 33 | #define __llvmfeatures_dot_hpp 34 | 35 | /* The gcc features seem to work, but this is a placeholder in case they don't. */ 36 | 37 | #include "gccfeatures.h" 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /external/include/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 | -------------------------------------------------------------------------------- /external/include/Random123/features/nvccfeatures.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 __r123_nvcc_features_dot_h__ 33 | #define __r123_nvcc_features_dot_h__ 34 | 35 | #if !defined(CUDART_VERSION) 36 | #error "why are we in nvccfeatures.h if CUDART_VERSION is not defined" 37 | #endif 38 | 39 | #if CUDART_VERSION < 4010 40 | #error "CUDA versions earlier than 4.1 produce incorrect results for some templated functions in namespaces. Random123 isunsupported. See comments in nvccfeatures.h" 41 | // This test was added in Random123-1.08 (August, 2013) because we 42 | // discovered that Ftype(maxTvalue()) with Ftype=double and 43 | // T=uint64_t in examples/uniform.hpp produces -1 for CUDA4.0 and 44 | // earlier. We can't be sure this bug doesn't also affect invocations 45 | // of other templated functions, e.g., essentially all of Random123. 46 | // Thus, we no longer trust CUDA versions earlier than 4.1 even though 47 | // we had previously tested and timed Random123 with CUDA 3.x and 4.0. 48 | // If you feel lucky or desperate, you can change #error to #warning, but 49 | // please take extra care to be sure that you are getting correct 50 | // results. 51 | #endif 52 | 53 | // nvcc falls through to gcc or msvc. So first define 54 | // a couple of things and then include either gccfeatures.h 55 | // or msvcfeatures.h 56 | 57 | #ifndef R123_CUDA_DEVICE 58 | #define R123_CUDA_DEVICE __device__ 59 | #endif 60 | 61 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 62 | #define R123_USE_MULHILO64_CUDA_INTRIN 1 63 | #endif 64 | 65 | #ifndef R123_ASSERT 66 | #define R123_ASSERT(x) if((x)) ; else asm("trap;") 67 | #endif 68 | 69 | #ifndef R123_BUILTIN_EXPECT 70 | #define R123_BUILTIN_EXPECT(expr,likely) expr 71 | #endif 72 | 73 | #ifndef R123_USE_AES_NI 74 | #define R123_USE_AES_NI 0 75 | #endif 76 | 77 | #ifndef R123_USE_SSE4_2 78 | #define R123_USE_SSE4_2 0 79 | #endif 80 | 81 | #ifndef R123_USE_SSE4_1 82 | #define R123_USE_SSE4_1 0 83 | #endif 84 | 85 | #ifndef R123_USE_SSE 86 | #define R123_USE_SSE 0 87 | #endif 88 | 89 | #ifndef R123_USE_GNU_UINT128 90 | #define R123_USE_GNU_UINT128 0 91 | #endif 92 | 93 | #ifndef R123_ULONG_LONG 94 | // uint64_t, which is what we'd get without this, is 95 | // not the same as unsigned long long 96 | #define R123_ULONG_LONG unsigned long long 97 | #endif 98 | 99 | #ifndef R123_THROW 100 | // No exceptions in CUDA, at least upto 4.0 101 | #define R123_THROW(x) R123_ASSERT(0) 102 | #endif 103 | 104 | #if defined(__GNUC__) 105 | #include "gccfeatures.h" 106 | #elif defined(_MSC_FULL_VER) 107 | #include "msvcfeatures.h" 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /external/include/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 | -------------------------------------------------------------------------------- /external/include/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 | -------------------------------------------------------------------------------- /external/include/Random123/features/pgccfeatures.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 | Copyright (c) 2013, Los Alamos National Security, LLC 33 | All rights reserved. 34 | 35 | Copyright 2013. Los Alamos National Security, LLC. This software was produced 36 | under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National 37 | Laboratory (LANL), which is operated by Los Alamos National Security, LLC for 38 | the U.S. Department of Energy. The U.S. Government has rights to use, 39 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS 40 | ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 41 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified 42 | to produce derivative works, such modified software should be clearly marked, 43 | so as not to confuse it with the version available from LANL. 44 | */ 45 | #ifndef __pgccfeatures_dot_hpp 46 | #define __pgccfeatures_dot_hpp 47 | 48 | #if !defined(__x86_64__) && !defined(__i386__) 49 | # error "This code has only been tested on x86 platforms." 50 | #include 51 | { /* maybe an unbalanced brace will terminate the compilation */ 52 | /* Feel free to try the Random123 library on other architectures by changing 53 | the conditions that reach this error, but you should consider it a 54 | porting exercise and expect to encounter bugs and deficiencies. 55 | Please let the authors know of any successes (or failures). */ 56 | #endif 57 | 58 | #ifndef R123_STATIC_INLINE 59 | #define R123_STATIC_INLINE static inline 60 | #endif 61 | 62 | /* Found this example in PGI's emmintrin.h. */ 63 | #ifndef R123_FORCE_INLINE 64 | #define R123_FORCE_INLINE(decl) decl __attribute__((__always_inline__)) 65 | #endif 66 | 67 | #ifndef R123_CUDA_DEVICE 68 | #define R123_CUDA_DEVICE 69 | #endif 70 | 71 | #ifndef R123_ASSERT 72 | #include 73 | #define R123_ASSERT(x) assert(x) 74 | #endif 75 | 76 | #ifndef R123_BUILTIN_EXPECT 77 | #define R123_BUILTIN_EXPECT(expr,likely) (expr) 78 | #endif 79 | 80 | /* PGI through 13.2 doesn't appear to support AES-NI. */ 81 | #ifndef R123_USE_AES_NI 82 | #define R123_USE_AES_NI 0 83 | #endif 84 | 85 | /* PGI through 13.2 appears to support MMX, SSE, SSE3, SSE3, SSSE3, SSE4a, and 86 | ABM, but not SSE4.1 or SSE4.2. */ 87 | #ifndef R123_USE_SSE4_2 88 | #define R123_USE_SSE4_2 0 89 | #endif 90 | 91 | #ifndef R123_USE_SSE4_1 92 | #define R123_USE_SSE4_1 0 93 | #endif 94 | 95 | #ifndef R123_USE_SSE 96 | /* There's no point in trying to compile SSE code in Random123 97 | unless SSE2 is available. */ 98 | #ifdef __SSE2__ 99 | #define R123_USE_SSE 1 100 | #else 101 | #define R123_USE_SSE 0 102 | #endif 103 | #endif 104 | 105 | #ifndef R123_USE_AES_OPENSSL 106 | /* There isn't really a good way to tell at compile time whether 107 | openssl is available. Without a pre-compilation configure-like 108 | tool, it's less error-prone to guess that it isn't available. Add 109 | -DR123_USE_AES_OPENSSL=1 and any necessary LDFLAGS or LDLIBS to 110 | play with openssl */ 111 | #define R123_USE_AES_OPENSSL 0 112 | #endif 113 | 114 | #ifndef R123_USE_GNU_UINT128 115 | #define R123_USE_GNU_UINT128 0 116 | #endif 117 | 118 | #ifndef R123_USE_ASM_GNU 119 | #define R123_USE_ASM_GNU 1 120 | #endif 121 | 122 | #ifndef R123_USE_CPUID_MSVC 123 | #define R123_USE_CPUID_MSVC 0 124 | #endif 125 | 126 | #ifndef R123_USE_X86INTRIN_H 127 | #define R123_USE_X86INTRIN_H 0 128 | #endif 129 | 130 | #ifndef R123_USE_IA32INTRIN_H 131 | #define R123_USE_IA32INTRIN_H 0 132 | #endif 133 | 134 | /* emmintrin.h from PGI #includes xmmintrin.h but then complains at link time 135 | about undefined references to _mm_castsi128_ps(__m128i). Why? */ 136 | #ifndef R123_USE_XMMINTRIN_H 137 | #define R123_USE_XMMINTRIN_H 1 138 | #endif 139 | 140 | #ifndef R123_USE_EMMINTRIN_H 141 | #define R123_USE_EMMINTRIN_H 1 142 | #endif 143 | 144 | #ifndef R123_USE_SMMINTRIN_H 145 | #define R123_USE_SMMINTRIN_H 0 146 | #endif 147 | 148 | #ifndef R123_USE_WMMINTRIN_H 149 | #define R123_USE_WMMINTRIN_H 0 150 | #endif 151 | 152 | #ifndef R123_USE_INTRIN_H 153 | #ifdef __ABM__ 154 | #define R123_USE_INTRIN_H 1 155 | #else 156 | #define R123_USE_INTRIN_H 0 157 | #endif 158 | #endif 159 | 160 | #ifndef R123_USE_MULHILO32_ASM 161 | #define R123_USE_MULHILO32_ASM 0 162 | #endif 163 | 164 | #ifndef R123_USE_MULHILO64_MULHI_INTRIN 165 | #define R123_USE_MULHILO64_MULHI_INTRIN 0 166 | #endif 167 | 168 | #ifndef R123_USE_MULHILO64_ASM 169 | #define R123_USE_MULHILO64_ASM 1 170 | #endif 171 | 172 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 173 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 174 | #endif 175 | 176 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 177 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 178 | #endif 179 | 180 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 181 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 182 | #endif 183 | 184 | #ifndef __STDC_CONSTANT_MACROS 185 | #define __STDC_CONSTANT_MACROS 186 | #endif 187 | #include 188 | #ifndef UINT64_C 189 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 190 | #endif 191 | 192 | /* If you add something, it must go in all the other XXfeatures.hpp 193 | and in ../ut_features.cpp */ 194 | #endif 195 | -------------------------------------------------------------------------------- /external/include/Random123/features/sunprofeatures.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 __sunprofeatures_dot_hpp 33 | #define __sunprofeatures_dot_hpp 34 | 35 | #ifndef R123_STATIC_INLINE 36 | #define R123_STATIC_INLINE static inline 37 | #endif 38 | 39 | #ifndef R123_FORCE_INLINE 40 | #define R123_FORCE_INLINE(decl) decl 41 | #endif 42 | 43 | #ifndef R123_CUDA_DEVICE 44 | #define R123_CUDA_DEVICE 45 | #endif 46 | 47 | #ifndef R123_ASSERT 48 | #include 49 | #define R123_ASSERT(x) assert(x) 50 | #endif 51 | 52 | #ifndef R123_BUILTIN_EXPECT 53 | #define R123_BUILTIN_EXPECT(expr,likely) expr 54 | #endif 55 | 56 | // The basic idiom is: 57 | // #ifndef R123_SOMETHING 58 | // #if some condition 59 | // #define R123_SOMETHING 1 60 | // #else 61 | // #define R123_SOMETHING 0 62 | // #endif 63 | // #endif 64 | // This idiom allows an external user to override any decision 65 | // in this file with a command-line -DR123_SOMETHING=1 or -DR123_SOMETHINE=0 66 | 67 | // An alternative idiom is: 68 | // #ifndef R123_SOMETHING 69 | // #define R123_SOMETHING (some boolean expression) 70 | // #endif 71 | // where the boolean expression might contain previously-defined R123_SOMETHING_ELSE 72 | // pp-symbols. 73 | 74 | #ifndef R123_USE_AES_NI 75 | #define R123_USE_AES_NI 0 76 | #endif 77 | 78 | #ifndef R123_USE_SSE4_2 79 | #define R123_USE_SSE4_2 0 80 | #endif 81 | 82 | #ifndef R123_USE_SSE4_1 83 | #define R123_USE_SSE4_1 0 84 | #endif 85 | 86 | #ifndef R123_USE_SSE 87 | #define R123_USE_SSE 0 88 | #endif 89 | 90 | #ifndef R123_USE_AES_OPENSSL 91 | #define R123_USE_AES_OPENSSL 0 92 | #endif 93 | 94 | #ifndef R123_USE_GNU_UINT128 95 | #define R123_USE_GNU_UINT128 0 96 | #endif 97 | 98 | #ifndef R123_USE_ASM_GNU 99 | #define R123_USE_ASM_GNU 0 100 | #endif 101 | 102 | #ifndef R123_USE_CPUID_MSVC 103 | #define R123_USE_CPUID_MSVC 0 104 | #endif 105 | 106 | #ifndef R123_USE_X86INTRIN_H 107 | #define R123_USE_X86INTRIN_H 0 108 | #endif 109 | 110 | #ifndef R123_USE_IA32INTRIN_H 111 | #define R123_USE_IA32INTRIN_H 0 112 | #endif 113 | 114 | #ifndef R123_USE_XMMINTRIN_H 115 | #define R123_USE_XMMINTRIN_H 0 116 | #endif 117 | 118 | #ifndef R123_USE_EMMINTRIN_H 119 | #define R123_USE_EMMINTRIN_H 0 120 | #endif 121 | 122 | #ifndef R123_USE_SMMINTRIN_H 123 | #define R123_USE_SMMINTRIN_H 0 124 | #endif 125 | 126 | #ifndef R123_USE_WMMINTRIN_H 127 | #define R123_USE_WMMINTRIN_H 0 128 | #endif 129 | 130 | #ifndef R123_USE_INTRIN_H 131 | #define R123_USE_INTRIN_H 0 132 | #endif 133 | 134 | #ifndef R123_USE_MULHILO16_ASM 135 | #define R123_USE_MULHILO16_ASM 0 136 | #endif 137 | 138 | #ifndef R123_USE_MULHILO32_ASM 139 | #define R123_USE_MULHILO32_ASM 0 140 | #endif 141 | 142 | #ifndef R123_USE_MULHILO64_ASM 143 | #define R123_USE_MULHILO64_ASM 0 144 | #endif 145 | 146 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 147 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 148 | #endif 149 | 150 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 151 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 152 | #endif 153 | 154 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 155 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 156 | #endif 157 | 158 | #ifndef R123_USE_PHILOX_64BIT 159 | #define R123_USE_PHILOX_64BIT 0 160 | #endif 161 | 162 | #ifndef __STDC_CONSTANT_MACROS 163 | #define __STDC_CONSTANT_MACROS 164 | #endif 165 | #include 166 | #ifndef UINT64_C 167 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 168 | #endif 169 | 170 | // If you add something, it must go in all the other XXfeatures.hpp 171 | // and in ../ut_features.cpp 172 | #endif 173 | -------------------------------------------------------------------------------- /external/include/Random123/features/xlcfeatures.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 | Copyright (c) 2013, Los Alamos National Security, LLC 33 | All rights reserved. 34 | 35 | Copyright 2013. Los Alamos National Security, LLC. This software was produced 36 | under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National 37 | Laboratory (LANL), which is operated by Los Alamos National Security, LLC for 38 | the U.S. Department of Energy. The U.S. Government has rights to use, 39 | reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS 40 | ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR 41 | ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified 42 | to produce derivative works, such modified software should be clearly marked, 43 | so as not to confuse it with the version available from LANL. 44 | */ 45 | #ifndef __xlcfeatures_dot_hpp 46 | #define __xlcfeatures_dot_hpp 47 | 48 | #if !defined(__x86_64__) && !defined(__i386__) && !defined(__powerpc__) 49 | # error "This code has only been tested on x86 and PowerPC platforms." 50 | #include 51 | { /* maybe an unbalanced brace will terminate the compilation */ 52 | /* Feel free to try the Random123 library on other architectures by changing 53 | the conditions that reach this error, but you should consider it a 54 | porting exercise and expect to encounter bugs and deficiencies. 55 | Please let the authors know of any successes (or failures). */ 56 | #endif 57 | 58 | #ifdef __cplusplus 59 | /* builtins are automatically available to xlc. To use them with xlc++, 60 | one must include builtins.h. c.f 61 | http://publib.boulder.ibm.com/infocenter/cellcomp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.cell.doc/compiler_ref/compiler_builtins.html 62 | */ 63 | #include 64 | #endif 65 | 66 | #ifndef R123_STATIC_INLINE 67 | #define R123_STATIC_INLINE static inline 68 | #endif 69 | 70 | #ifndef R123_FORCE_INLINE 71 | #define R123_FORCE_INLINE(decl) decl __attribute__((__always_inline__)) 72 | #endif 73 | 74 | #ifndef R123_CUDA_DEVICE 75 | #define R123_CUDA_DEVICE 76 | #endif 77 | 78 | #ifndef R123_ASSERT 79 | #include 80 | #define R123_ASSERT(x) assert(x) 81 | #endif 82 | 83 | #ifndef R123_BUILTIN_EXPECT 84 | #define R123_BUILTIN_EXPECT(expr,likely) __builtin_expect(expr,likely) 85 | #endif 86 | 87 | #ifndef R123_USE_AES_NI 88 | #define R123_USE_AES_NI 0 89 | #endif 90 | 91 | #ifndef R123_USE_SSE4_2 92 | #define R123_USE_SSE4_2 0 93 | #endif 94 | 95 | #ifndef R123_USE_SSE4_1 96 | #define R123_USE_SSE4_1 0 97 | #endif 98 | 99 | #ifndef R123_USE_SSE 100 | #define R123_USE_SSE 0 101 | #endif 102 | 103 | #ifndef R123_USE_AES_OPENSSL 104 | /* There isn't really a good way to tell at compile time whether 105 | openssl is available. Without a pre-compilation configure-like 106 | tool, it's less error-prone to guess that it isn't available. Add 107 | -DR123_USE_AES_OPENSSL=1 and any necessary LDFLAGS or LDLIBS to 108 | play with openssl */ 109 | #define R123_USE_AES_OPENSSL 0 110 | #endif 111 | 112 | #ifndef R123_USE_GNU_UINT128 113 | #define R123_USE_GNU_UINT128 0 114 | #endif 115 | 116 | #ifndef R123_USE_ASM_GNU 117 | #define R123_USE_ASM_GNU 1 118 | #endif 119 | 120 | #ifndef R123_USE_CPUID_MSVC 121 | #define R123_USE_CPUID_MSVC 0 122 | #endif 123 | 124 | #ifndef R123_USE_X86INTRIN_H 125 | #define R123_USE_X86INTRIN_H 0 126 | #endif 127 | 128 | #ifndef R123_USE_IA32INTRIN_H 129 | #define R123_USE_IA32INTRIN_H 0 130 | #endif 131 | 132 | #ifndef R123_USE_XMMINTRIN_H 133 | #define R123_USE_XMMINTRIN_H 0 134 | #endif 135 | 136 | #ifndef R123_USE_EMMINTRIN_H 137 | #define R123_USE_EMMINTRIN_H 0 138 | #endif 139 | 140 | #ifndef R123_USE_SMMINTRIN_H 141 | #define R123_USE_SMMINTRIN_H 0 142 | #endif 143 | 144 | #ifndef R123_USE_WMMINTRIN_H 145 | #define R123_USE_WMMINTRIN_H 0 146 | #endif 147 | 148 | #ifndef R123_USE_INTRIN_H 149 | #ifdef __ABM__ 150 | #define R123_USE_INTRIN_H 1 151 | #else 152 | #define R123_USE_INTRIN_H 0 153 | #endif 154 | #endif 155 | 156 | #ifndef R123_USE_MULHILO32_ASM 157 | #define R123_USE_MULHILO32_ASM 0 158 | #endif 159 | 160 | #ifndef R123_USE_MULHILO64_MULHI_INTRIN 161 | #define R123_USE_MULHILO64_MULHI_INTRIN (defined(__powerpc64__)) 162 | #endif 163 | 164 | #ifndef R123_MULHILO64_MULHI_INTRIN 165 | #define R123_MULHILO64_MULHI_INTRIN __mulhdu 166 | #endif 167 | 168 | #ifndef R123_USE_MULHILO32_MULHI_INTRIN 169 | #define R123_USE_MULHILO32_MULHI_INTRIN 0 170 | #endif 171 | 172 | #ifndef R123_MULHILO32_MULHI_INTRIN 173 | #define R123_MULHILO32_MULHI_INTRIN __mulhwu 174 | #endif 175 | 176 | #ifndef R123_USE_MULHILO64_ASM 177 | #define R123_USE_MULHILO64_ASM (defined(__powerpc64__) && !(R123_USE_MULHILO64_MULHI_INTRIN)) 178 | #endif 179 | 180 | #ifndef R123_USE_MULHILO64_MSVC_INTRIN 181 | #define R123_USE_MULHILO64_MSVC_INTRIN 0 182 | #endif 183 | 184 | #ifndef R123_USE_MULHILO64_CUDA_INTRIN 185 | #define R123_USE_MULHILO64_CUDA_INTRIN 0 186 | #endif 187 | 188 | #ifndef R123_USE_MULHILO64_OPENCL_INTRIN 189 | #define R123_USE_MULHILO64_OPENCL_INTRIN 0 190 | #endif 191 | 192 | #ifndef __STDC_CONSTANT_MACROS 193 | #define __STDC_CONSTANT_MACROS 194 | #endif 195 | #include 196 | #ifndef UINT64_C 197 | #error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include 198 | #endif 199 | 200 | /* If you add something, it must go in all the other XXfeatures.hpp 201 | and in ../ut_features.cpp */ 202 | #endif 203 | -------------------------------------------------------------------------------- /external/include/Random123/gsl_microrng.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 __r123_gslmicrorng_dot_h__ 33 | #define __r123_gslmicrorng_dot_h__ 34 | 35 | 36 | #include 37 | #include 38 | 39 | /** The macro: GSL_MICRORNG(NAME, CBRNGNAME) is the GSL 40 | analog analog of the C++ r123::MicroURNG template. It declares a gsl_rng 41 | type named gsl_rng_NAME which uses the underlying CBRNGNAME 42 | and can be invoked a limited number of times between calls to NAME_reset. 43 | 44 | When the underlying CBRNG's \c ctr_t is an \ref arrayNxW "r123arrayNxW", 45 | and the gsl_rng_NAME may called up to \c N*2^32 times 46 | between calls to \c NAME_reset. 47 | 48 | \c NAME_reset takes a gsl_rng_NAME type, a counter and a key as arguments. 49 | It restarts the micro-rng with a new base counter and key. 50 | 51 | Note that you must call NAME_reset before the first use 52 | of a gsl_rng. NAME_reset is not called automatically by 53 | gsl_rng_alloc(). 54 | 55 | @code 56 | #include 57 | #include // this file 58 | GSL_MICRORNG(microcbrng, threefry4x64, 20) // creates gsl_rng_microcbrng 59 | 60 | int main(int argc, char** argv) { 61 | gsl_rng *r = gsl_rng_alloc(gsl_rng_microcbrng); 62 | threefry4x64_ctr_t c = {{}}; 63 | threefry4x64_key_t k = {{}}; 64 | 65 | for (...) { 66 | c.v[0] = ??; // some application variable 67 | microcbrng_reset(r, c, k); 68 | for (...) { 69 | // gaussian calls r several times. It is safe for 70 | // r to be used upto 2^20 times in this loop 71 | something[i] = gsl_ran_gaussian(r, 1.5); 72 | } 73 | } 74 | } 75 | @endcode 76 | 77 | */ 78 | 79 | #define GSL_MICRORNG(NAME, CBRNGNAME) \ 80 | const gsl_rng_type *gsl_rng_##NAME; \ 81 | \ 82 | typedef struct{ \ 83 | CBRNGNAME##_ctr_t ctr; \ 84 | CBRNGNAME##_ctr_t r; \ 85 | CBRNGNAME##_key_t key; \ 86 | R123_ULONG_LONG n; \ 87 | int elem; \ 88 | } NAME##_state; \ 89 | \ 90 | static unsigned long int NAME##_get(void *vstate){ \ 91 | NAME##_state *st = (NAME##_state *)vstate; \ 92 | const int N=sizeof(st->ctr.v)/sizeof(st->ctr.v[0]); \ 93 | if( st->elem == 0 ){ \ 94 | CBRNGNAME##_ctr_t c = st->ctr; \ 95 | c.v[N-1] |= st->n<<(R123_W(CBRNGNAME##_ctr_t)-32); \ 96 | st->n++; \ 97 | st->r = CBRNGNAME(c, st->key); \ 98 | st->elem = N; \ 99 | } \ 100 | return 0xffffffff & st->r.v[--st->elem]; \ 101 | } \ 102 | \ 103 | static double \ 104 | NAME##_get_double (void * vstate) \ 105 | { \ 106 | return NAME##_get (vstate)/4294967296.; \ 107 | } \ 108 | \ 109 | static void NAME##_set(void *vstate, unsigned long int s){ \ 110 | NAME##_state *st = (NAME##_state *)vstate; \ 111 | (void)s; /* ignored */ \ 112 | st->elem = 0; \ 113 | st->n = ~0; /* will abort if _reset is not called */ \ 114 | } \ 115 | \ 116 | static const gsl_rng_type NAME##_type = { \ 117 | #NAME, \ 118 | 0xffffffffUL, \ 119 | 0, \ 120 | sizeof(NAME##_state), \ 121 | &NAME##_set, \ 122 | &NAME##_get, \ 123 | &NAME##_get_double \ 124 | }; \ 125 | \ 126 | R123_STATIC_INLINE void NAME##_reset(const gsl_rng* gr, CBRNGNAME##_ctr_t c, CBRNGNAME##_key_t k) { \ 127 | NAME##_state* state = (NAME##_state *)gr->state; \ 128 | state->ctr = c; \ 129 | state->key = k; \ 130 | state->n = 0; \ 131 | state->elem = 0; \ 132 | } \ 133 | \ 134 | const gsl_rng_type *gsl_rng_##NAME = &NAME##_type 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /external/include/Random123/u01.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 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 _random123_u01_dot_h_ 33 | #define _random123_u01_dot_h_ 34 | 35 | #include "features/compilerfeatures.h" 36 | 37 | /** @defgroup u01_closed_open_W_M The u01 conversion functions 38 | 39 | These functions convert unsigned W-bit integers to real values 40 | (float or double) between 0.0 and 1.0 with mantissas of M bits. 41 | There are 12 functions, corresponding to the following choices: 42 | 43 | - W = 32 or 64 44 | - M = 24 or 53 (float or double) 45 | - open0 or closed0 : whether the output is open or closed at 0.0 46 | - open1 or closed1 : whether the output is open or closed at 1.0 47 | 48 | The W=64 M=24 cases are not implemented. To obtain an M=24 float 49 | from a uint64_t, use a cast (possibly with right-shift and bitwise 50 | and) to convert some of the bits of the uint64_t to a uint32_t and 51 | then use u01_x_y_32_24. Note that the 64-bit random integers 52 | produced by the Random123 library are random in "all the bits", so 53 | with a little extra effort you can obtain two floats this way -- 54 | one from the high bits and one from the low bits of the 64-bit 55 | value. 56 | 57 | If the output is open at one end, then the extreme 58 | value (0.0 or 1.0) will never be returned. Conversely, if the output 59 | is closed at one end, then the extreme value is a possible 60 | return value. 61 | 62 | On x86 hardware, especially on 32bit machines, the use of 63 | internal 80bit x87-style floating point may result in 64 | 'bonus' precision, which may cause closed intervals to not 65 | be really closed, i.e. the conversions below might not 66 | convert UINT{32,64}_MAX to 1.0. This sort of issue is 67 | likely to occur when storing the output of a u01_*_32_24 68 | function in a double, though one can imagine getting extra 69 | precision artifacts when going from 64_53 as well. Other 70 | artifacts may exist on some GPU hardware. The tests in 71 | kat_u01_main.h try to expose such issues, but caveat emptor. 72 | 73 | @{ 74 | @cond HIDDEN_FROM_DOXYGEN 75 | */ 76 | 77 | /* Hex floats were standardized by C in 1999, but weren't standardized 78 | by C++ until 2011. So, we're obliged to write out our constants in 79 | decimal, even though they're most naturally expressed in binary. 80 | We cross our fingers and hope that the compiler does the compile-time 81 | constant arithmetic properly. 82 | */ 83 | #define R123_0x1p_32f (1.f/4294967296.f) 84 | #define R123_0x1p_24f (1.f/16777216.f) 85 | #define R123_0x1fffffep_25f (16777215.f * R123_0x1p_24f * R123_0x1p_24f) 86 | #define R123_0x1p_64 (1./(4294967296.*4294967296.)) 87 | #define R123_0x1p_53 (1./(4294967296.*2097152.)) 88 | #define R123_0x1fffffffffffffp_54 (9007199254740991.*R123_0x1p_53*R123_0x1p_53) 89 | #define R123_0x1p_32 (1./4294967296.) 90 | #define R123_0x100000001p_32 (4294967297.*R123_0x1p_32*R123_0x1p_32) 91 | 92 | /** @endcond */ 93 | 94 | #ifdef __cplusplus 95 | extern "C"{ 96 | #endif 97 | 98 | /* narrowing conversions: uint32_t to float */ 99 | R123_CUDA_DEVICE R123_STATIC_INLINE float u01_closed_closed_32_24(uint32_t i){ 100 | return i*R123_0x1p_32f; /* 0x1.p-32f */ 101 | } 102 | 103 | R123_CUDA_DEVICE R123_STATIC_INLINE float u01_closed_open_32_24(uint32_t i){ 104 | return (i>>8)*R123_0x1p_24f; /* 0x1.0p-24f; */ 105 | } 106 | 107 | R123_CUDA_DEVICE R123_STATIC_INLINE float u01_open_closed_32_24(uint32_t i){ 108 | return (1+(i>>8))*R123_0x1p_24f; /* *0x1.0p-24f; */ 109 | } 110 | 111 | R123_CUDA_DEVICE R123_STATIC_INLINE float u01_open_open_32_24(uint32_t i){ 112 | return (1+(i>>8))*R123_0x1fffffep_25f; /* 0x1.fffffep-25f; */ 113 | } 114 | 115 | #if R123_USE_U01_DOUBLE 116 | /* narrowing conversions: uint64_t to double */ 117 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_closed_closed_64_53(uint64_t i){ 118 | return i*R123_0x1p_64; /* 0x1.p-64; */ 119 | } 120 | 121 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_closed_open_64_53(uint64_t i){ 122 | return (i>>11)*R123_0x1p_53; /* 0x1.0p-53; */ 123 | } 124 | 125 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_open_closed_64_53(uint64_t i){ 126 | return (1+(i>>11))*R123_0x1p_53; /* 0x1.0p-53; */ 127 | } 128 | 129 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_open_open_64_53(uint64_t i){ 130 | return (1+(i>>11))*R123_0x1fffffffffffffp_54; /* 0x1.fffffffffffffp-54; */ 131 | } 132 | 133 | /* widening conversions: u32 to double */ 134 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_closed_closed_32_53(uint32_t i){ 135 | return i*R123_0x100000001p_32; /* 0x1.00000001p-32; */ 136 | } 137 | 138 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_closed_open_32_53(uint32_t i){ 139 | return i*R123_0x1p_32; /* 0x1.p-32; */ 140 | } 141 | 142 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_open_closed_32_53(uint32_t i){ 143 | return (1.+i)*R123_0x1p_32; /* 0x1.p-32; */ 144 | } 145 | 146 | R123_CUDA_DEVICE R123_STATIC_INLINE double u01_open_open_32_53(uint32_t i){ 147 | return (0.5+i)*R123_0x1p_32; /* 0x1.p-32; */ 148 | } 149 | #endif /* R123_USE_U01_DOUBLE */ 150 | 151 | #ifdef __cplusplus 152 | } 153 | #endif 154 | 155 | /** @} */ 156 | #endif 157 | -------------------------------------------------------------------------------- /get_code_cov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for filename in `find . | egrep '\.gcno'`; 3 | do 4 | gcov $filename; 5 | done 6 | -------------------------------------------------------------------------------- /include/build_Option.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_BUILD_OPTION_HPP 9 | #define SODECL_BUILD_OPTION_HPP 10 | 11 | #include "sodecl_export.h" 12 | 13 | namespace sodecl { 14 | enum class SODECL_EXPORT build_Option { 15 | FastRelaxedMath = 1, 16 | stdCL20 = 2, 17 | stdCL21 = 3 18 | }; 19 | } 20 | 21 | 22 | #endif // SODECL_BUILD_OPTION_HPP 23 | -------------------------------------------------------------------------------- /include/clog.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_CLOG_HPP 9 | #define SODECL_CLOG_HPP 10 | 11 | #include "sodecl_export.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | namespace sodecl { 20 | class SODECL_EXPORT clog { 21 | private: 22 | 23 | static bool m_instanceExists; 24 | static clog *m_instance; 25 | 26 | std::ostringstream m_oss; 27 | 28 | /// 29 | /// Default constructor which initialises the clog object. 30 | /// 31 | clog(); 32 | 33 | public: 34 | 35 | static clog *getInstance(); 36 | 37 | ~clog(); 38 | 39 | /// 40 | /// Writes a message to the log. 41 | /// 42 | /// String with the message. 43 | void write(const char* msg); 44 | 45 | /// 46 | /// Writes a message to the log. 47 | /// 48 | /// Double with the message. 49 | void write(double msg); 50 | 51 | /// 52 | /// Writes the log messages in a text file. 53 | /// 54 | void toFile(); 55 | 56 | /// 57 | /// Writes the SODECL exit status file. 58 | /// 59 | void writeExitStatusFile(size_t exittype, string msg); 60 | }; 61 | } 62 | 63 | 64 | #endif // SODECL_CLOG_HPP 65 | -------------------------------------------------------------------------------- /include/device.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_DEVICE_HPP 9 | #define SODECL_DEVICE_HPP 10 | 11 | #include 12 | #include "sodecl_export.h" 13 | 14 | namespace sodecl { 15 | 16 | class SODECL_EXPORT device { 17 | /* 18 | VARIABLES SECTION 19 | */ 20 | public: 21 | 22 | // Platform ID 23 | cl_device_id m_device_id; 24 | 25 | // Device ID 26 | cl_device_id m_device; 27 | 28 | // Device type 29 | cl_device_type m_device_type; 30 | 31 | private: 32 | 33 | /* 34 | FUNCTIONS SECTION 35 | */ 36 | public: 37 | 38 | // Default constructor 39 | device(); 40 | 41 | // Default destructor 42 | ~device(); 43 | 44 | // Costructor with specific platform ID 45 | device(cl_device_id m_device_id); 46 | 47 | // get device name 48 | std::string name(); 49 | 50 | // get device name 51 | std::string version(); 52 | 53 | // get device type 54 | std::string type_str(); 55 | 56 | cl_device_type type(); 57 | 58 | // get platform info based on attribute 59 | std::string get_info(cl_device_info cl_pi); 60 | 61 | private: 62 | 63 | }; 64 | 65 | } 66 | 67 | 68 | #endif // SODECL_DEVICE_HPP 69 | -------------------------------------------------------------------------------- /include/device_Type.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_DEVICE_TYPE_HPP 9 | #define SODECL_DEVICE_TYPE_HPP 10 | 11 | #include "sodecl_export.h" 12 | 13 | namespace sodecl { 14 | enum class SODECL_EXPORT device_Type : uint64_t { 15 | ALL = CL_DEVICE_TYPE_ALL, 16 | CPU = CL_DEVICE_TYPE_CPU, 17 | GPU = CL_DEVICE_TYPE_GPU, 18 | ACCELERATOR = CL_DEVICE_TYPE_ACCELERATOR 19 | }; 20 | } 21 | 22 | 23 | #endif // SODECL_SOLVER_TYPE_HPP 24 | -------------------------------------------------------------------------------- /include/output_Type.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_OUTPUT_TYPE_HPP 9 | #define SODECL_OUTPUT_TYPE_HPP 10 | 11 | #include "sodecl_export.h" 12 | 13 | namespace sodecl { 14 | enum class SODECL_EXPORT output_Type { 15 | None = 0, 16 | Array = 1, 17 | File = 2 18 | }; 19 | } 20 | 21 | 22 | #endif // SODECL_OUTPUT_TYPE_HPP 23 | -------------------------------------------------------------------------------- /include/platform.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_PLATFORM_HPP 9 | #define SODECL_PLATFORM_HPP 10 | 11 | #include 12 | #include "sodecl.hpp" 13 | 14 | #include "sodecl_export.h" 15 | 16 | namespace sodecl { 17 | class SODECL_EXPORT platform { 18 | /* 19 | VARIABLES SECTION 20 | */ 21 | public: 22 | 23 | // Array with pointer to sodecl::platform objects 24 | //sodecl::device *m_devices; 25 | std::vector m_devices; 26 | 27 | // Platform ID 28 | cl_platform_id m_platform_id; 29 | 30 | // Count of devices 31 | cl_uint m_devices_count; 32 | 33 | // The num of the selected device in m_devices vector. 34 | cl_uint m_selected_device; 35 | 36 | private: 37 | 38 | // Log mechanisms 39 | clog *m_log; // Pointer for log. 40 | 41 | /* 42 | FUNCTIONS SECTION 43 | */ 44 | public: 45 | 46 | platform(); 47 | 48 | platform(cl_platform_id m_platform_id); 49 | 50 | ~platform(); 51 | 52 | std::vector get_devices(); 53 | 54 | // get platform name 55 | std::string name(); 56 | 57 | // get platform vendor 58 | std::string vendor(); 59 | 60 | // get platform vendor 61 | std::string version(); 62 | 63 | // get platform profile 64 | std::string profile(); 65 | 66 | // get platform profile 67 | std::string extensions(); 68 | 69 | // get platform info based on attribute 70 | std::string get_info(cl_platform_info cl_pi); 71 | 72 | // get number of devices 73 | int get_device_count(); 74 | 75 | // Create all sodecl::device objects 76 | void create_devices(); 77 | }; 78 | } 79 | 80 | 81 | #endif // SODECL_PLATFORM_HPP 82 | -------------------------------------------------------------------------------- /include/sodecl.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_SODECL_HPP 9 | #define SODECL_SODECL_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #endif -------------------------------------------------------------------------------- /include/solver_Type.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_SOLVER_TYPE_HPP 9 | #define SODECL_SOLVER_TYPE_HPP 10 | 11 | #include "sodecl_export.h" 12 | 13 | namespace sodecl { 14 | enum class SODECL_EXPORT solver_Type { 15 | StochasticEuler = 0, 16 | Euler = 1, 17 | RungeKutta = 2, 18 | ImplicitEuler = 3, 19 | ImplicitMidpoint = 4 20 | }; 21 | } 22 | 23 | #endif // SODECL_SOLVER_TYPE_HPP 24 | -------------------------------------------------------------------------------- /include/timer.hpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #ifndef SODECL_TIMER_HPP 9 | #define SODECL_TIMER_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sodecl_export.h" 16 | 17 | namespace sodecl { 18 | class SODECL_EXPORT timer { 19 | public: 20 | std::chrono::time_point start, end; 21 | 22 | timer() { 23 | start = std::chrono::system_clock::now(); 24 | } 25 | 26 | double stop_timer() { 27 | end = std::chrono::system_clock::now(); 28 | 29 | std::chrono::duration elapsed_seconds = end - start; 30 | 31 | //std::time_t end_time = std::chrono::system_clock::to_time_t(end); 32 | 33 | //std::cout << "Elapsed time: " << elapsed_seconds.count() << " sec.\n"; 34 | 35 | return elapsed_seconds.count(); 36 | } 37 | }; 38 | } 39 | 40 | 41 | #endif // SODECL_TIMER_HPP 42 | -------------------------------------------------------------------------------- /interfaces/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(interfaces) 4 | 5 | add_subdirectory(python) -------------------------------------------------------------------------------- /interfaces/python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | find_package(Python3 COMPONENTS Development) 3 | if (${Python3_FOUND}) 4 | message(STATUS "PYTHON3 FOUND") 5 | message(STATUS ${Python3_INCLUDE_DIRS}) 6 | message(STATUS ${Python3_LIBRARIES}) 7 | else () 8 | message(FATAL_ERROR "PYTHON3 NOT FOUND") 9 | endif () 10 | 11 | add_subdirectory(pybind11) 12 | pybind11_add_module(sodecl_python sodecl.cpp) 13 | set_target_properties(sodecl_python PROPERTIES OUTPUT_NAME sodecl_interface) 14 | 15 | # Add include directories for OpenCL and sodecl 16 | target_include_directories(sodecl_python PUBLIC ${CMAKE_SOURCE_DIR}/external/include 17 | ${CMAKE_SOURCE_DIR}/include 18 | ${CMAKE_BINARY_DIR}) 19 | 20 | target_link_libraries(sodecl_python PUBLIC OpenCL::OpenCL sodecl_lib) 21 | 22 | add_custom_command(TARGET sodecl_python POST_BUILD 23 | 24 | # Copy pybind11 generated library to the benchmarks folder 25 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/benchmarks/ 26 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sodecl.py ${CMAKE_BINARY_DIR}/benchmarks/ 27 | 28 | # Copy OpenCL kernels to the benchmarks folder 29 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/kernels ${CMAKE_BINARY_DIR}/benchmarks//kernels 30 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/external/include/Random123 ${CMAKE_BINARY_DIR}/benchmarks/Random123 31 | 32 | # Copy pybind11 generated library to the tests folder 33 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/tests/ 34 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sodecl.py ${CMAKE_BINARY_DIR}/tests/ 35 | 36 | # Copy OpenCL kernels to the tests folder 37 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/kernels ${CMAKE_BINARY_DIR}/tests/kernels 38 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/external/include/Random123 ${CMAKE_BINARY_DIR}/tests/Random123 39 | 40 | # Copy pybind11 generated library to the examples folder 41 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/examples/ 42 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sodecl.py ${CMAKE_BINARY_DIR}/examples/ 43 | 44 | # Copy OpenCL kernels to the examples folder 45 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/kernels ${CMAKE_BINARY_DIR}/examples/kernels 46 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/external/include/Random123 ${CMAKE_BINARY_DIR}/examples/Random123 47 | 48 | COMMENT "Copying Python interface files") -------------------------------------------------------------------------------- /interfaces/python/sodecl.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #include "iostream" 9 | #include "sodecl.hpp" 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | std::vector sodeclcall( std::vector &a_t0, 17 | std::vector &a_y0, 18 | std::vector &a_params, 19 | int a_platform, 20 | int a_device, 21 | string a_system, 22 | int a_solver_type, 23 | int a_orbits, 24 | int a_equats, 25 | int a_nparams, 26 | int a_nnoi, 27 | double a_dt, 28 | double a_tspan, 29 | int a_ksteps, 30 | int a_local_group_size) 31 | { 32 | sodecl::solver_Type a_solver; 33 | switch (a_solver_type) 34 | { 35 | case 0: 36 | a_solver = sodecl::solver_Type::StochasticEuler; 37 | break; 38 | case 1: 39 | a_solver = sodecl::solver_Type::Euler; 40 | break; 41 | case 2: 42 | a_solver = sodecl::solver_Type::RungeKutta; 43 | break; 44 | case 3: 45 | a_solver = sodecl::solver_Type::ImplicitEuler; 46 | break; 47 | case 4: 48 | a_solver = sodecl::solver_Type::ImplicitMidpoint; 49 | break; 50 | default: 51 | std::cout << "Unknown SODE solver selection." << std::endl; 52 | std::vector myvector(0); 53 | return myvector; 54 | } 55 | 56 | sodecl::sodeclmgr *mysodeclmgr = new sodecl::sodeclmgr("kernels", 57 | &a_system[0], 58 | a_solver, 59 | a_dt, 60 | a_tspan, 61 | a_ksteps, 62 | a_equats, 63 | a_nparams, 64 | a_nnoi, 65 | a_orbits, 66 | sodecl::output_Type::Array); 67 | 68 | int success; 69 | 70 | // Choose device 71 | success = mysodeclmgr->choose_device(a_platform, sodecl::device_Type::ALL, a_device); 72 | if (success == 0) 73 | { 74 | cerr << "Error selecting OpenCL device!" << endl; 75 | } 76 | 77 | mysodeclmgr->set_t0(a_t0.data()); 78 | mysodeclmgr->set_y0(a_y0.data()); 79 | mysodeclmgr->set_params(a_params.data()); 80 | 81 | // Set the local group size. 82 | mysodeclmgr->set_local_group_size(a_local_group_size); 83 | 84 | // Setup and run the SODE solver 85 | int ret = mysodeclmgr->setup_sode_solver(); 86 | if (ret == 0) 87 | { 88 | std::vector myvector(0); 89 | return myvector; 90 | } 91 | 92 | mysodeclmgr->run_sode_solver(); 93 | 94 | return mysodeclmgr->m_output; 95 | } 96 | 97 | PYBIND11_MODULE(sodecl_interface, m) { 98 | m.doc() = "sodecl plugin"; 99 | 100 | m.def("sodeclcall", &sodeclcall, "A function that integrates a SDE/ODE system."); 101 | } -------------------------------------------------------------------------------- /interfaces/python/sodecl.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------// 2 | # Copyright (c) 2017 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | # ---------------------------------------------------------------------------// 7 | 8 | import os 9 | import subprocess 10 | import numpy 11 | import numpy.matlib 12 | import platform 13 | import sodecl_interface 14 | 15 | # Calls the SODECL executable. 16 | # 17 | # Executes the SODECL executable for specific parameters. 18 | # 19 | # @param openclplatform is the number of the OpenCL platform. 20 | # @param opencldevice is the is the number of the OpenCL device for the selected platform. 21 | # @param openclkernel is the path to the OpenCL kernel with the definition of the SODE system. 22 | # @param initx is the array with the initial state of the SODE system. 23 | # @param params is the array with the parameters of the SODE system. 24 | # @param sodesolver is the integration solver for the SODE system. 25 | # @param orbits is the number of orbits to integrate the SODE system. 26 | # @param nequat is the number of equations of the SODE system. 27 | # @param nnoiseprocesses is the number of noise processes needed by the SODE system. 28 | # @param dt is the time step for the SODE solver. 29 | # @param tspan is the time span for the integration of the SODE system. 30 | # @param ksteps is the number of SODE solver step for each call to the OpenCL device. 31 | # @param localgroupsize is the size of the OpenCL local group size. 32 | # 33 | # @return the integration results. 34 | 35 | def sodecl(openclplatform, opencldevice, openclkernel, 36 | initx, params, sodesolver, 37 | orbits, nequat, nnoiseprocesses, 38 | dt, tspan, ksteps, localgroupsize): 39 | 40 | t0 = numpy.array([0]) 41 | t0 = numpy.matlib.repmat(t0, orbits, 1) 42 | nparams = params[0].size 43 | 44 | t0=t0.flatten() 45 | initx=initx.flatten() 46 | params=params.flatten() 47 | 48 | if nnoiseprocesses == 0: 49 | # solvers = {'se': 0, 50 | # 'e': 1, 51 | # 'r': 2, 52 | # 'ie': 3, 53 | # 'im': 4} 54 | 55 | if sodesolver>0 and sodesolver<5: 56 | solver2user = sodesolver 57 | else: 58 | print("Invalid SODE solver selected! Using Euler!") 59 | solver2user = 1 60 | else: 61 | solver2user = 0 62 | 63 | results = sodecl_interface.sodeclcall( t0, 64 | initx, 65 | params, 66 | openclplatform, 67 | opencldevice, 68 | openclkernel, 69 | solver2user, 70 | orbits, 71 | nequat, 72 | nparams, 73 | nnoiseprocesses, 74 | dt, 75 | tspan, 76 | ksteps, 77 | localgroupsize) 78 | 79 | results = numpy.array(results) 80 | results = results.reshape(orbits*nequat, int(results.shape[0] / (orbits*nequat)), order='F') 81 | 82 | t=numpy.arange(0, tspan+dt*ksteps, dt*ksteps) 83 | 84 | return t, results 85 | -------------------------------------------------------------------------------- /scripts/slurm_submit.peta4-knl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #! 3 | #! Example SLURM job script for Peta4-KNL (KNL 7210) 4 | #! Last updated: Mon 13 Nov 12:17:14 GMT 2017 5 | #! 6 | 7 | #!############################################################# 8 | #!#### Modify the options in this section as appropriate ###### 9 | #!############################################################# 10 | 11 | #! sbatch directives begin here ############################### 12 | #! Name of the job: 13 | #SBATCH -J sodeclbench 14 | #! Which project should be charged (NB Peta4-KNL projects end in '-KNL'): 15 | #SBATCH -A SUPPORT-KNL 16 | #! How many whole nodes should be allocated? 17 | #SBATCH --nodes=1 18 | #! Which memory mode do you require (recommended choices are cache or flat): 19 | #SBATCH --constraint=cache 20 | #! How many (MPI) tasks will there be in total? (<=nodes*256) 21 | #SBATCH --ntasks=256 22 | #! How much wallclock time will be required? 23 | #SBATCH --time=02:00:00 24 | #! What types of email messages do you wish to receive? 25 | #SBATCH --mail-type=FAIL 26 | #! Uncomment this to prevent the job from being requeued (e.g. if 27 | #! interrupted by node failure or system downtime): 28 | ##SBATCH --no-requeue 29 | 30 | #! Do not change: 31 | #SBATCH -p knl 32 | 33 | #! sbatch directives end here (put any additional directives above this line) 34 | 35 | #! Notes: 36 | #! Charging is determined by node number*walltime. Allocation is in entire nodes. 37 | 38 | #! Optionally modify the environment seen by the application 39 | #! (note that SLURM reproduces the environment at submission irrespective of ~/.bashrc): 40 | . /etc/profile.d/modules.sh # Leave this line (enables the module command) 41 | module purge # Removes all modules still loaded 42 | module load rhel7/default-peta4 # REQUIRED - loads the basic environment 43 | module load intel/ocl/3.1.1.11385 44 | module load gcc 45 | module load python/3.5.1 46 | 47 | python3 kuramotobenchmarks.py -------------------------------------------------------------------------------- /scripts/slurm_submit.peta4-skylake: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #! 3 | #! Example SLURM job script for Peta4-Skylake (Skylake CPUs, OPA) 4 | #! Last updated: Mon 13 Nov 12:25:17 GMT 2017 5 | #! 6 | 7 | #!############################################################# 8 | #!#### Modify the options in this section as appropriate ###### 9 | #!############################################################# 10 | 11 | #! sbatch directives begin here ############################### 12 | #! Name of the job: 13 | #SBATCH -J sodeclbench 14 | #! Which project should be charged: 15 | #SBATCH -A SUPPORT-CPU 16 | #! How many whole nodes should be allocated? 17 | #SBATCH --nodes=1 18 | #! How many (MPI) tasks will there be in total? (<= nodes*32) 19 | #! The skylake/skylake-himem nodes have 32 CPUs (cores) each. 20 | #SBATCH --ntasks=32 21 | #! How much wallclock time will be required? 22 | #SBATCH --time=02:00:00 23 | #! What types of email messages do you wish to receive? 24 | #SBATCH --mail-type=FAIL 25 | #! Uncomment this to prevent the job from being requeued (e.g. if 26 | #! interrupted by node failure or system downtime): 27 | ##SBATCH --no-requeue 28 | 29 | #! For 6GB per CPU, set "-p skylake"; for 12GB per CPU, set "-p skylake-himem": 30 | #SBATCH -p skylake-himem 31 | 32 | #! sbatch directives end here (put any additional directives above this line) 33 | 34 | #! Notes: 35 | #! Charging is determined by core number*walltime. 36 | #! The --ntasks value refers to the number of tasks to be launched by SLURM only. This 37 | #! usually equates to the number of MPI tasks launched. Reduce this from nodes*32 if 38 | #! demanded by memory requirements, or if OMP_NUM_THREADS>1. 39 | #! Each task is allocated 1 core by default, and each core is allocated 5990MB (skylake) 40 | #! and 12040MB (skylake-himem). If this is insufficient, also specify 41 | #! --cpus-per-task and/or --mem (the latter specifies MB per node). 42 | 43 | #! Number of nodes and tasks per node allocated by SLURM (do not change): 44 | 45 | #! ############################################################ 46 | #! Modify the settings below to specify the application's environment, location 47 | #! and launch method: 48 | 49 | #! Optionally modify the environment seen by the application 50 | #! (note that SLURM reproduces the environment at submission irrespective of ~/.bashrc): 51 | . /etc/profile.d/modules.sh # Leave this line (enables the module command) 52 | module purge # Removes all modules still loaded 53 | module load rhel7/default-peta4 # REQUIRED - loads the basic environment 54 | module load intel/ocl/3.1.1.11385 55 | module load gcc 56 | module load python/3.5.1 57 | 58 | #! Insert additional module load commands after this line if needed: 59 | python3 kuramotobenchmarks.py -------------------------------------------------------------------------------- /scripts/slurm_submit.wilkes2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #! 3 | #! Example SLURM job script for Wilkes2 (Broadwell, ConnectX-4, P100) 4 | #! Last updated: Mon 13 Nov 12:06:57 GMT 2017 5 | #! 6 | 7 | #!############################################################# 8 | #!#### Modify the options in this section as appropriate ###### 9 | #!############################################################# 10 | 11 | #! sbatch directives begin here ############################### 12 | #! Name of the job: 13 | #SBATCH -J sodeclbenchmark 14 | #! Which project should be charged (NB Wilkes2 projects end in '-GPU'): 15 | #SBATCH -A SUPPORT-GPU 16 | #! How many whole nodes should be allocated? 17 | #SBATCH --nodes=1 18 | #! How many (MPI) tasks will there be in total? 19 | #! Note probably this should not exceed the total number of GPUs in use. 20 | #SBATCH --ntasks=1 21 | #! Specify the number of GPUs per node (between 1 and 4; must be 4 if nodes>1). 22 | #! Note that the job submission script will enforce no more than 3 cpus per GPU. 23 | #SBATCH --gres=gpu:1 24 | #! How much wallclock time will be required? 25 | #SBATCH --time=02:00:00 26 | #! What types of email messages do you wish to receive? 27 | #SBATCH --mail-type=FAIL 28 | #! Uncomment this to prevent the job from being requeued (e.g. if 29 | #! interrupted by node failure or system downtime): 30 | ##SBATCH --no-requeue 31 | 32 | #! Do not change: 33 | #SBATCH -p pascal 34 | 35 | #! sbatch directives end here (put any additional directives above this line) 36 | 37 | #! Notes: 38 | #! Charging is determined by GPU number*walltime. 39 | 40 | #! Optionally modify the environment seen by the application 41 | #! (note that SLURM reproduces the environment at submission irrespective of ~/.bashrc): 42 | . /etc/profile.d/modules.sh # Leave this line (enables the module command) 43 | module purge # Removes all modules still loaded 44 | module load rhel7/default-gpu # REQUIRED - loads the basic environment 45 | module load gcc 46 | module load python/3.5.1 47 | module load cuda 48 | module load intel/ocl/3.1.1.11385 49 | 50 | python3 kuramotobenchmarks.py -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------------------// 2 | # Copyright (c) 2015 Eleftherios Avramidis 3 | # 4 | # Distributed under The MIT License (MIT) 5 | # See accompanying file LICENSE 6 | #---------------------------------------------------------------------------// 7 | 8 | include(GNUInstallDirs) 9 | add_library(sodecl SHARED) 10 | add_library(sodecl_lib ALIAS sodecl) 11 | 12 | target_sources(sodecl PRIVATE 13 | ${CMAKE_SOURCE_DIR}/src/clog.cpp 14 | ${CMAKE_SOURCE_DIR}/src/device.cpp 15 | ${CMAKE_SOURCE_DIR}/src/platform.cpp 16 | ${CMAKE_SOURCE_DIR}/src/sodeclmgr.cpp 17 | ${CMAKE_SOURCE_DIR}/src/timer.cpp) 18 | 19 | target_include_directories(sodecl PUBLIC 20 | $ 21 | $ 22 | $) 23 | 24 | target_link_libraries(sodecl PRIVATE project_options OpenCL::OpenCL) 25 | 26 | set_target_properties(sodecl PROPERTIES 27 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 28 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 29 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 30 | 31 | if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 32 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 33 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/examples/sodecl.dll 34 | VERBATIM) 35 | 36 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 37 | COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/tests/sodecl.dll 38 | VERBATIM) 39 | endif () 40 | 41 | install(TARGETS sodecl EXPORT sodeclTargets 42 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT sodecl_RunTime 43 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sodecl_RunTime NAMELINK_COMPONENT cxxplot_Development 44 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sodecl_Development 45 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 46 | 47 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ 48 | TYPE INCLUDE 49 | FILES_MATCHING 50 | PATTERN *.hpp 51 | PERMISSIONS OWNER_READ OWNER_WRITE 52 | GROUP_READ 53 | WORLD_READ) 54 | 55 | install(FILES ${CMAKE_BINARY_DIR}/sodecl_export.h 56 | TYPE INCLUDE 57 | PERMISSIONS OWNER_READ OWNER_WRITE 58 | GROUP_READ 59 | WORLD_READ) 60 | 61 | install(EXPORT sodeclTargets 62 | NAMESPACE sodecl:: 63 | FILE cxxplotConfig.cmake 64 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sodecl) 65 | 66 | include(CMakePackageConfigHelpers) 67 | write_basic_package_version_file( 68 | cxxplotConfigVersion.cmake 69 | VERSION 1.0.0 70 | COMPATIBILITY SameMajorVersion) 71 | 72 | install(FILES ${PROJECT_BINARY_DIR}/source/sodeclConfigVersion.cmake 73 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sodecl) -------------------------------------------------------------------------------- /src/clog.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "clog.hpp" 13 | 14 | using namespace std; 15 | 16 | namespace sodecl { 17 | 18 | // Initialise variables. 19 | bool clog::m_instanceExists = false; 20 | clog* clog::m_instance = NULL; 21 | 22 | clog::clog() 23 | { 24 | ofstream newFileLog("sodecllog.txt", std::ios::binary | std::ios::out); 25 | newFileLog.close(); 26 | 27 | ofstream newFileExitStatus("sodeclexitstatus.txt", std::ios::binary | std::ios::out); 28 | newFileExitStatus.close(); 29 | } 30 | 31 | clog* 32 | clog::getInstance() 33 | { 34 | if (!m_instanceExists) { 35 | m_instance = new clog(); 36 | m_instanceExists = true; 37 | return m_instance; 38 | } 39 | else { 40 | return m_instance; 41 | } 42 | } 43 | 44 | clog::~clog() 45 | { 46 | m_instanceExists = false; 47 | } 48 | 49 | void 50 | clog::write(const char* msg) 51 | { 52 | m_oss << msg; 53 | } 54 | 55 | void 56 | clog::write(double msg) 57 | { 58 | m_oss << msg; 59 | } 60 | 61 | void 62 | clog::toFile() 63 | { 64 | std::ofstream output_stream; 65 | 66 | output_stream.open("sodecllog.txt", std::ios::binary | std::ios::app | std::ios::out); 67 | 68 | output_stream << m_oss.str(); 69 | 70 | output_stream.close(); 71 | 72 | m_oss.clear(); 73 | } 74 | 75 | void 76 | clog::writeExitStatusFile(size_t exittype, string msg) 77 | { 78 | std::ostringstream oss; 79 | if (exittype==0) { 80 | oss << "1 "; 81 | } 82 | else { 83 | oss << "0 "; 84 | } 85 | 86 | oss << msg; 87 | 88 | std::ofstream output_stream; 89 | output_stream.open("sodeclexitstatus.txt", std::ios::binary | std::ios::app | std::ios::out); 90 | output_stream << oss.str(); 91 | output_stream.close(); 92 | 93 | oss.clear(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/device.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #include 9 | 10 | #include 11 | #include "sodecl_export.h" 12 | #include "device.hpp" 13 | 14 | namespace sodecl { 15 | 16 | 17 | // Default constructor 18 | device::device() { 19 | 20 | } 21 | 22 | // Default destructor 23 | device::~device() { 24 | 25 | } 26 | 27 | // Costructor with specific platform ID 28 | device::device(cl_device_id m_device_id) { 29 | this->m_device_id = m_device_id; 30 | 31 | //std::cout << "the name is " << name().c_str() << std::endl; 32 | //std::cout << "the version is " << version().c_str() << std::endl; 33 | } 34 | 35 | // get device name 36 | std::string device::name() { 37 | return get_info(CL_DEVICE_NAME); 38 | } 39 | 40 | // get device name 41 | std::string device::version() { 42 | return get_info(CL_DEVICE_VERSION); 43 | } 44 | 45 | // get device type 46 | std::string device::type_str() { 47 | return get_info(CL_DEVICE_TYPE); 48 | } 49 | 50 | cl_device_type device::type() { 51 | // print device name 52 | cl_device_type info; 53 | 54 | clGetDeviceInfo(m_device_id, CL_DEVICE_TYPE, sizeof(cl_device_type), &info, NULL); 55 | 56 | return info; 57 | } 58 | 59 | // get platform info based on attribute 60 | std::string device::get_info(cl_device_info cl_pi) { 61 | // print device name 62 | char *info; 63 | size_t infoSize; 64 | 65 | clGetDeviceInfo(m_device_id, cl_pi, 0, NULL, &infoSize); 66 | 67 | info = new char[infoSize]; 68 | clGetDeviceInfo(m_device_id, cl_pi, infoSize, info, NULL); 69 | 70 | std::string str(info); 71 | delete[] info; 72 | return str; 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/kernels/euler.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | 9 | // Euler solver 10 | void sode_solver(double dt, double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 11 | { 12 | sode_system(t, y, yout, p); 13 | 14 | for (int ieq = 0; ieq < _numeq_; ieq++) 15 | { 16 | yout[ieq] = y[ieq] + yout[ieq] * dt; 17 | } 18 | } -------------------------------------------------------------------------------- /src/kernels/ie.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | 9 | // The tridiagonal matrix algorithm (Thomas algorithm) 10 | void solvesystem(double jac[_numeq_][_numeq_], double v[_numeq_], double x[_numeq_]) 11 | { 12 | double a[_numeq_]; 13 | for (int i = _numeq_ - 2; i < _numeq_; i++) 14 | { 15 | a[i] = 0; 16 | } 17 | for (int i = 0; i < (_numeq_ - 2); i++) 18 | { 19 | a[i] = jac[i][i + 1]; 20 | } 21 | 22 | double c[_numeq_]; 23 | c[_numeq_ - 1] = 0; 24 | for (int i = 0; i < (_numeq_ - 1); i++) 25 | { 26 | c[i] = jac[i + 1][i]; 27 | } 28 | 29 | double b[_numeq_]; 30 | for (int i = 0; i < _numeq_; i++) 31 | { 32 | b[i] = jac[i][i]; 33 | } 34 | 35 | double m; 36 | for (int i = 1; i < _numeq_; i++) 37 | { 38 | m = a[i] / b[i - 1]; 39 | b[i] = b[i] - m * c[i - 1]; 40 | v[i] = v[i] - m*v[i - 1]; 41 | } 42 | x[_numeq_ - 1] = v[_numeq_ - 1] / b[_numeq_ - 1]; 43 | 44 | for (int i = _numeq_ - 2; i >= 0; i--) 45 | { 46 | x[i] = (v[i] - c[i] * x[i + 1]) / b[i]; 47 | } 48 | } 49 | 50 | void newton_f(double dt, double t, double initial[_numeq_], double guess[_numeq_], double yout[_numeq_], double p[_numpar_]) 51 | { 52 | double detterm[_numeq_]; 53 | sode_system(t, guess, detterm, p); 54 | 55 | for (int i = 0; i < _numeq_; i++) 56 | { 57 | yout[i] = guess[i] - initial[i] - detterm[i] * dt; 58 | } 59 | } 60 | 61 | void newton(double dt, double t, double initial[_numeq_], double guess[_numeq_], double detterm[_numeq_], double p[_numpar_]) 62 | { 63 | double jac[_numeq_][_numeq_]; 64 | double new_out[_numeq_]; 65 | double multi_out[_numeq_]; 66 | 67 | double err1; 68 | 69 | for (int N = 0; N < 1000; N++) 70 | { 71 | newton_f(dt, t, initial, guess, new_out, p); 72 | 73 | err1 = 0; 74 | for (int i = 0; i < _numeq_; i++) 75 | { 76 | err1 = err1 + fabs(new_out[i]); 77 | } 78 | if (err1 < _epsilon1_) 79 | { 80 | break; 81 | } 82 | 83 | calc_jacobian(guess, jac, p); 84 | for (int i = 0; i < _numeq_; i++) 85 | { 86 | for (int j = 0; j < _numeq_; j++) 87 | { 88 | jac[i][j] = jac[i][j] * (-1.00)*dt; 89 | } 90 | 91 | jac[i][i] = jac[i][i] + 1; 92 | } 93 | 94 | solvesystem(jac, new_out, multi_out); 95 | for (int i = 0; i < _numeq_; i++) 96 | { 97 | guess[i] = guess[i] - multi_out[i]; 98 | } 99 | } 100 | 101 | for (int i = 0; i < _numeq_; i++) 102 | { 103 | detterm[i] = guess[i]; 104 | } 105 | } 106 | 107 | void sode_solver(double dt, double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 108 | { 109 | double guess[_numeq_]; 110 | 111 | for (int i = 0; i < _numeq_; i++) 112 | { 113 | guess[i] = y[i]; 114 | } 115 | 116 | newton(dt, t, y, guess, yout, p); 117 | } 118 | -------------------------------------------------------------------------------- /src/kernels/im.cl: -------------------------------------------------------------------------------- 1 | 2 | // The tridiagonal matrix algorithm (Thomas algorithm) 3 | void solvesystem(double jac[_numeq_][_numeq_], double v[_numeq_], double x[_numeq_]) 4 | { 5 | double a[_numeq_]; 6 | for (int i = _numeq_ - 2; i < _numeq_; i++) 7 | { 8 | a[i] = 0; 9 | } 10 | for (int i = 0; i < (_numeq_ - 2); i++) 11 | { 12 | a[i] = jac[i][i + 1]; 13 | } 14 | 15 | double c[_numeq_]; 16 | c[_numeq_ - 1] = 0; 17 | for (int i = 0; i < (_numeq_ - 1); i++) 18 | { 19 | c[i] = jac[i + 1][i]; 20 | } 21 | 22 | double b[_numeq_]; 23 | for (int i = 0; i < _numeq_; i++) 24 | { 25 | b[i] = jac[i][i]; 26 | } 27 | 28 | double m; 29 | for (int i = 1; i < _numeq_; i++) 30 | { 31 | m = a[i] / b[i - 1]; 32 | b[i] = b[i] - m * c[i - 1]; 33 | v[i] = v[i] - m*v[i - 1]; 34 | } 35 | x[_numeq_ - 1] = v[_numeq_ - 1] / b[_numeq_ - 1]; 36 | 37 | for (int i = _numeq_ - 2; i >= 0; i--) 38 | { 39 | x[i] = (v[i] - c[i] * x[i + 1]) / b[i]; 40 | } 41 | } 42 | 43 | void newton_f_mid(double dt, double t, double initial[_numeq_], double guess[_numeq_], double detterm[_numeq_], double yout[_numeq_], double p[6]) 44 | { 45 | for (int i = 0; i < _numeq_; i++) 46 | { 47 | yout[i] = guess[i] - initial[i] - detterm[i] * dt; 48 | } 49 | } 50 | 51 | void newton(double dt, double t, double initial[_numeq_], double detterm[_numeq_], double p[_numpar_]) 52 | { 53 | double jac[_numeq_][_numeq_]; 54 | double new_out[_numeq_]; 55 | double multi_out[_numeq_]; 56 | double err1; 57 | 58 | double guess[_numeq_]; 59 | for (int i = 0; i < _numeq_; i++) 60 | { 61 | guess[i] = initial[i]; 62 | } 63 | double guess2[_numeq_]; 64 | 65 | for (int N = 0; N < 1000; N++) 66 | { 67 | for (int i = 0; i < _numeq_; i++) 68 | { 69 | guess2[i] = (initial[i] + guess[i])*0.5; 70 | } 71 | sode_system(t, guess2, detterm, p); 72 | newton_f_mid(dt, t, initial, guess, detterm, new_out, p); 73 | 74 | err1 = 0; 75 | for (int i = 0; i < _numeq_; i++) 76 | { 77 | err1 = err1 + new_out[i]*new_out[i]; 78 | } 79 | if (sqrt(err1) < _epsilon1_) 80 | { 81 | break; 82 | } 83 | 84 | calc_jacobian(guess2, jac, p); 85 | //calc_jacobian_numerically(t, guess2, jac, p); 86 | for (int i = 0; i < _numeq_; i++) 87 | { 88 | for (int j = 0; j < _numeq_; j++) 89 | { 90 | jac[i][j] = jac[i][j] * (-0.50)*dt; 91 | } 92 | jac[i][i] = jac[i][i] + 1; 93 | } 94 | 95 | solvesystem(jac, new_out, multi_out); 96 | for (int i = 0; i < _numeq_; i++) 97 | { 98 | guess[i] = guess[i] - multi_out[i]; 99 | } 100 | } 101 | 102 | for (int i = 0; i < _numeq_; i++) 103 | { 104 | detterm[i] = guess[i]; 105 | } 106 | } 107 | 108 | void sode_solver(double dt, double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 109 | { 110 | //double guess[_numeq_]; 111 | 112 | //for (int i = 0; i < _numeq_; i++) 113 | //{ 114 | // guess[i] = y[i]; 115 | //} 116 | 117 | newton(dt, t, y, yout, p); 118 | } 119 | -------------------------------------------------------------------------------- /src/kernels/rk4.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | 9 | /// 10 | /// Performs a single step for the fourth-order Runge-kutta method. 11 | /// 12 | /// The dt is the time step. 13 | /// The t is the current time value. 14 | /// The y is the current phase values. 15 | /// The yout is the next phase values. 16 | /// The p is the parameter values. 17 | void sode_solver(double dt, double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 18 | { 19 | sode_system(t, y, yout, p); 20 | 21 | // k1 22 | double k1[_numeq_]; 23 | for (int i = 0; i < _numeq_; ++i) 24 | { 25 | k1[i] = yout[i]; 26 | } 27 | 28 | // k2 29 | double x2[_numeq_]; 30 | for (int i = 0; i < _numeq_; ++i) 31 | { 32 | x2[i] = y[i] + (dt * 0.50)*k1[i]; 33 | } 34 | 35 | sode_system(t + 0.50*dt, x2, k1, p); 36 | for (int i = 0; i < _numeq_; ++i) 37 | { 38 | yout[i] = yout[i] + 2.00 * k1[i]; 39 | } 40 | 41 | // k3 42 | for (int i = 0; i < _numeq_; ++i) 43 | { 44 | x2[i] = y[i] + (dt * 0.50)*k1[i]; 45 | } 46 | sode_system(t + 0.50*dt, x2, k1, p); 47 | 48 | for (int i = 0; i < _numeq_; ++i) 49 | { 50 | yout[i] = yout[i] + 2.00 * k1[i]; 51 | } 52 | 53 | // k4 54 | for (int i = 0; i < _numeq_; ++i) 55 | { 56 | x2[i] = y[i] + dt*k1[i]; 57 | } 58 | sode_system(t+dt, x2, k1, p); 59 | 60 | for (int i = 0; i < _numeq_; ++i) 61 | { 62 | yout[i] = y[i] + (yout[i] + k1[i]) * dt / 6.00; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/kernels/solver_caller.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | __kernel void solver_caller(__global double *t0, 9 | __global double *y0, 10 | __global double *params_g) 11 | { 12 | int i = get_global_id(0); 13 | 14 | double t; 15 | double y[_numeq_]; 16 | double detterm[_numeq_]; 17 | double params[_numpar_]; 18 | 19 | t = t0[i]; 20 | 21 | int k = i * _numeq_; 22 | for (int m = 0; m < _numeq_; ++m) 23 | { 24 | y[m] = y0[k + m]; 25 | } 26 | 27 | k = i * _numpar_; 28 | for (int m = 0; m < _numpar_; ++m) 29 | { 30 | params[m] = params_g[k + m]; 31 | } 32 | 33 | int it; 34 | for (it = 0; it < _numsteps_; ++it) 35 | { 36 | sode_solver(_m_dt_, t, y, detterm, params); 37 | 38 | t = t + _m_dt_; 39 | for (int ieq = 0; ieq < _numeq_; ++ieq) 40 | { 41 | y[ieq] = detterm[ieq]; 42 | } 43 | } 44 | 45 | t0[i] = t; 46 | k = i * _numeq_; 47 | for (int m = 0; m < _numeq_; ++m) 48 | { 49 | y0[k + m] = y[m]; 50 | } 51 | } -------------------------------------------------------------------------------- /src/kernels/stochastic_euler.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | 9 | // StochasticEuler solver 10 | void sode_solver(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_], double noise[_numnoi_]) 11 | { 12 | sode_system(t, y, yout, p); 13 | 14 | double stoch[_numeq_]; 15 | sode_system_stoch(t, y, stoch, p, noise); 16 | 17 | for (int i = 0; i < _numeq_; i++) 18 | { 19 | yout[i] = y[i] + yout[i] * _m_dt_ + stoch[i]; 20 | // yout[i] = fmod(yout[i], 2*M_PI); 21 | } 22 | } -------------------------------------------------------------------------------- /src/kernels/stochastic_solver_caller.cl: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | __kernel void solver_caller(__global double *t0, 9 | __global double *y0, 10 | __global double *params_g, 11 | __global double *counter_g) 12 | { 13 | int i = get_global_id(0); 14 | 15 | double dtsqrt = sqrt(_m_dt_); 16 | 17 | double y[_numeq_]; 18 | double detterm[_numeq_]; 19 | double params[_numpar_]; 20 | double noise[_numnoi_]; 21 | 22 | for (int ieq = 0; ieq < _numeq_; ieq++) 23 | { 24 | y[ieq] = y0[i * _numeq_ + ieq]; 25 | } 26 | for (int ipar = 0; ipar < _numpar_; ipar++) 27 | { 28 | params[ipar] = params_g[i * _numpar_ + ipar]; 29 | } 30 | 31 | threefry2x64_key_t rk = { { i, 0xf00dcafe } }; 32 | threefry2x64_ctr_t rc = { { 0, 0xdecafbad } }; 33 | 34 | threefry2x64_ctr_t rr; 35 | 36 | double u0; 37 | double u1; 38 | rk.v[0] = 0; 39 | 40 | int number_of_noise_calls = ceil((float)((float)(_numnoi_) * 0.5)); 41 | 42 | for (int it = 0; it < _numsteps_; it++) 43 | { 44 | int ncounter = 0; 45 | for (int in = 0; in < number_of_noise_calls; in++) 46 | { 47 | // Generate the noise values 48 | rc.v[0] = i; 49 | rc.v[1] = counter_g[i]; // some iteration number change between kernel calls. 50 | 51 | rr = threefry2x64(rc, rk); 52 | counter_g[i] = counter_g[i] + 1; 53 | 54 | if (ncounter < _numnoi_) 55 | { 56 | u0 = u01_open_open_64_53(rr.v[0]); 57 | u1 = u01_open_open_64_53(rr.v[1]); 58 | noise[ncounter] = (sqrt(-2 * log(u0)) * cos(2 * M_PI * u1))*dtsqrt; 59 | ncounter = ncounter + 1; 60 | } 61 | if (ncounter < _numnoi_) 62 | { 63 | noise[ncounter] = (sqrt(-2 * log(u0)) * sin(2 * M_PI * u1))*dtsqrt; 64 | ncounter = ncounter + 1; 65 | } 66 | } 67 | 68 | // Call the solver 69 | sode_solver(t0[i], y, detterm, params, noise); 70 | 71 | t0[i] = t0[i] + _m_dt_; 72 | for (int ieq = 0; ieq < _numeq_; ieq++) 73 | { 74 | y[ieq] = detterm[ieq]; 75 | } 76 | } 77 | for (int ieq = 0; ieq < _numeq_; ieq++) 78 | { 79 | y0[i * _numeq_ + ieq] = y[ieq]; 80 | } 81 | } -------------------------------------------------------------------------------- /src/platform.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #include 9 | #include "sodecl.hpp" 10 | 11 | #include "sodecl_export.h" 12 | 13 | namespace sodecl { 14 | 15 | platform::platform() 16 | { 17 | 18 | } 19 | 20 | platform::platform(cl_platform_id m_platform_id) 21 | { 22 | 23 | // Initialise the clog object 24 | m_log = clog::getInstance(); 25 | 26 | this->m_platform_id = m_platform_id; 27 | 28 | //std::cout << "The platform name is " << name().c_str() << std::endl; 29 | //std::cout << "The platform version is " << version().c_str() << std::endl; 30 | m_log->write("The platform name is "); 31 | m_log->write(name().c_str()); 32 | m_log->write("\n"); 33 | 34 | m_log->write(" The platform version is "); 35 | m_log->write(version().c_str()); 36 | m_log->write("\n"); 37 | 38 | m_devices_count = get_device_count(); 39 | if (m_devices_count==0) { 40 | throw std::runtime_error("No OpenCL device found.\n"); 41 | } 42 | 43 | if (m_devices_count<=10) { 44 | create_devices(); 45 | } 46 | 47 | } 48 | 49 | platform::~platform() 50 | { 51 | for (auto i : m_devices) { 52 | delete i; 53 | } 54 | 55 | m_devices.clear(); 56 | } 57 | 58 | std::vector 59 | platform::get_devices() 60 | { 61 | return m_devices; 62 | } 63 | 64 | // get platform name 65 | std::string 66 | platform::name() 67 | { 68 | return get_info(CL_PLATFORM_NAME); 69 | } 70 | 71 | // get platform vendor 72 | std::string 73 | platform::vendor() 74 | { 75 | return get_info(CL_PLATFORM_VENDOR); 76 | } 77 | 78 | // get platform vendor 79 | std::string 80 | platform::version() 81 | { 82 | return get_info(CL_PLATFORM_VERSION); 83 | } 84 | 85 | // get platform profile 86 | std::string 87 | platform::profile() 88 | { 89 | return get_info(CL_PLATFORM_PROFILE); 90 | } 91 | 92 | // get platform profile 93 | std::string 94 | platform::extensions() 95 | { 96 | return get_info(CL_PLATFORM_EXTENSIONS); 97 | } 98 | 99 | // get platform info based on attribute 100 | std::string 101 | platform::get_info(cl_platform_info cl_pi) 102 | { 103 | char* info; 104 | size_t infoSize; 105 | 106 | // get platform attribute value size 107 | clGetPlatformInfo(m_platform_id, cl_pi, 0, NULL, &infoSize); 108 | info = new char[infoSize]; 109 | 110 | // get platform attribute value 111 | clGetPlatformInfo(m_platform_id, cl_pi, infoSize, info, NULL); 112 | 113 | std::string str(info); 114 | delete info; 115 | 116 | return str; 117 | } 118 | 119 | // get number of devices 120 | int 121 | platform::get_device_count() 122 | { 123 | cl_uint device_count; 124 | 125 | // get device count 126 | cl_int err = clGetDeviceIDs(m_platform_id, CL_DEVICE_TYPE_ALL, 0, NULL, &device_count); 127 | 128 | return device_count; 129 | } 130 | 131 | // Create all sodecl::device objects 132 | void 133 | platform::create_devices() 134 | { 135 | cl_device_id* cpDevice = new cl_device_id[m_devices_count]; 136 | 137 | clGetDeviceIDs(m_platform_id, CL_DEVICE_TYPE_ALL, m_devices_count, cpDevice, NULL); 138 | 139 | for (cl_uint i = 0; iwrite(" The device name is "); 143 | m_log->write(m_devices.back()->name().c_str()); 144 | m_log->write("\n"); 145 | } 146 | delete[] cpDevice; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/timer.cpp: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------------------// 2 | // Copyright (c) 2015,2016 Eleftherios Avramidis 3 | // 4 | // Distributed under The MIT License (MIT) 5 | // See accompanying file LICENSE 6 | //---------------------------------------------------------------------------// 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "sodecl_export.h" 13 | 14 | namespace sodecl { 15 | class SODECL_EXPORT timer { 16 | public: 17 | std::chrono::time_point start, end; 18 | 19 | timer() { 20 | start = std::chrono::system_clock::now(); 21 | } 22 | 23 | double stop_timer() { 24 | end = std::chrono::system_clock::now(); 25 | 26 | std::chrono::duration elapsed_seconds = end - start; 27 | 28 | //std::time_t end_time = std::chrono::system_clock::to_time_t(end); 29 | 30 | //std::cout << "Elapsed time: " << elapsed_seconds.count() << " sec.\n"; 31 | 32 | return elapsed_seconds.count(); 33 | } 34 | }; 35 | } -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(tests) 4 | 5 | set(TESTS_SOURCE_FILES 6 | ${CMAKE_CURRENT_SOURCE_DIR}/sodecl_python_tests.py 7 | ${CMAKE_CURRENT_SOURCE_DIR}/kuramoto.cl 8 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor.cl 9 | ${CMAKE_CURRENT_SOURCE_DIR}/data/oculomotor_euler.pkl) 10 | 11 | set(TESTS_FILES 12 | ${CMAKE_CURRENT_BINARY_DIR}/sodecl_python_tests.py 13 | ${CMAKE_CURRENT_BINARY_DIR}/kuramoto.cl 14 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor.cl 15 | ${CMAKE_CURRENT_BINARY_DIR}/data/oculomotor_euler.pkl) 16 | 17 | add_custom_command(OUTPUT ${TESTS_FILES} 18 | COMMAND ${CMAKE_COMMAND} -E copy ${TESTS_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/ 19 | COMMENT "Copy test files" 20 | VERBATIM) 21 | 22 | add_custom_target(tests_copy ALL 23 | DEPENDS ${TESTS_FILES} 24 | VERBATIM) 25 | 26 | FIND_PACKAGE(Python3 REQUIRED) 27 | 28 | add_test(NAME tests_python 29 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sodecl_python_tests.py) 30 | 31 | add_subdirectory(data) 32 | #add_subdirectory(unit) 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/approval/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(approval_tests) 4 | 5 | -------------------------------------------------------------------------------- /tests/data/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(tests_data_copy) 4 | 5 | enable_testing() 6 | 7 | set(TESTS_SOURCE_FILES 8 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_euler.pkl 9 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_rk.pkl 10 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_ie.pkl 11 | ${CMAKE_CURRENT_SOURCE_DIR}/oculomotor_im.pkl) 12 | 13 | set(TESTS_FILES 14 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_euler.pkl 15 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_rk.pkl 16 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_ie.pkl 17 | ${CMAKE_CURRENT_BINARY_DIR}/oculomotor_im.pkl) 18 | 19 | add_custom_command(OUTPUT ${TESTS_FILES} 20 | COMMAND ${CMAKE_COMMAND} -E copy ${TESTS_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/ 21 | COMMENT "Copy test files" 22 | VERBATIM) 23 | 24 | add_custom_target(tests_data_copy ALL 25 | DEPENDS ${TESTS_FILES} 26 | VERBATIM) 27 | -------------------------------------------------------------------------------- /tests/data/oculomotor_euler.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avramidis/sodecl/7bc2654293666a3a30766616d347e6347900e222/tests/data/oculomotor_euler.pkl -------------------------------------------------------------------------------- /tests/data/oculomotor_ie.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avramidis/sodecl/7bc2654293666a3a30766616d347e6347900e222/tests/data/oculomotor_ie.pkl -------------------------------------------------------------------------------- /tests/data/oculomotor_im.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avramidis/sodecl/7bc2654293666a3a30766616d347e6347900e222/tests/data/oculomotor_im.pkl -------------------------------------------------------------------------------- /tests/data/oculomotor_rk.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avramidis/sodecl/7bc2654293666a3a30766616d347e6347900e222/tests/data/oculomotor_rk.pkl -------------------------------------------------------------------------------- /tests/kuramoto.cl: -------------------------------------------------------------------------------- 1 | #define NOSC _numeq_ 2 | 3 | void sode_system(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 4 | { 5 | for (int i = 0; i 0) 11 | { 12 | y = (atval * (1.00 - exp(-x / btval))); 13 | } 14 | else 15 | { 16 | y = (-(aval / bval) * x * exp(x / bval)); 17 | } 18 | 19 | return y; 20 | } 21 | 22 | double dsburstf(double x, double aval, double bval, double atval, double btval) 23 | { 24 | double y; 25 | y = 0; 26 | 27 | if (x > 0) 28 | { 29 | y = (atval*exp(-x / btval)) / btval; 30 | } 31 | else 32 | { 33 | y = -((aval*exp(x / bval)) / bval + (aval*x*exp(x / bval)) / (bval*bval)); 34 | } 35 | return y; 36 | } 37 | 38 | void calc_jacobian(double y[_numeq_], double jac[_numeq_][_numeq_], double p[_numpar_]) 39 | { 40 | jac[0][0] = 0; 41 | jac[0][1] = 1; 42 | jac[0][2] = 0; 43 | jac[0][3] = 0; 44 | jac[0][4] = 0; 45 | jac[0][5] = 0; 46 | 47 | jac[1][0] = -1 / (T1*T2); 48 | jac[1][1] = -(1 / T1) - (1 / T2); 49 | jac[1][2] = 1 / (T1*T2); 50 | jac[1][3] = (1 / T1) + (1 / T2); 51 | jac[1][4] = -(1 / T1) - (1 / T2); 52 | jac[1][5] = 0; 53 | 54 | jac[2][0] = 0; 55 | jac[2][1] = 0; 56 | jac[2][2] = -1 / Tn; 57 | jac[2][3] = 1; 58 | jac[2][4] = -1; 59 | jac[2][5] = 0; 60 | 61 | jac[3][0] = 0; 62 | jac[3][1] = 0; 63 | jac[3][2] = 0; 64 | jac[3][3] = -(p[3] * (y[4] * y[4]) + 1) / p[2]; 65 | jac[3][4] = -(2 * p[3] * y[4] * y[3]) / p[2]; 66 | jac[3][5] = dsburstf(y[5], p[0], p[1], p[4], p[5]) / p[2]; 67 | 68 | jac[4][0] = 0; 69 | jac[4][1] = 0; 70 | jac[4][2] = 0; 71 | jac[4][3] = -(2 * p[3] * y[4] * y[3]) / p[2]; 72 | jac[4][4] = -(p[3] * (y[3] * y[3]) + 1) / p[2]; 73 | jac[4][5] = dsburstf(-y[5], p[0], p[1], p[4], p[5]) / p[2]; 74 | 75 | jac[5][0] = 0; 76 | jac[5][1] = 0; 77 | jac[5][2] = 0; 78 | jac[5][3] = -1; 79 | jac[5][4] = 1; 80 | jac[5][5] = 0; 81 | } 82 | 83 | void sode_system(double t, double y[_numeq_], double yout[_numeq_], double p[_numpar_]) 84 | { 85 | // g 86 | yout[0] = y[1]; 87 | // u 88 | yout[1] = -(((1.00 / T1) + (1.00 / T2)) * y[1]) - (1.00 / (T1 * T2) * y[0]) + (1.00 / (T1 * T2) * y[2]) + ((1.00 / T1) + (1.00 / T2)) * (y[3] - y[4]); 89 | // n 90 | yout[2] = -(y[2] / Tn) + (y[3] - y[4]); 91 | //r 92 | yout[3] = (1.00 / p[2])*(-y[3] - (p[3] * y[3] * y[4] * y[4]) + sburstf(y[5], p[0], p[1], p[4], p[5])); 93 | // l 94 | yout[4] = (1.00 / p[2])*(-y[4] - (p[3] * y[4] * y[3] * y[3]) + sburstf(-y[5], p[0], p[1], p[4], p[5])); 95 | // m 96 | yout[5] = -(y[3] - y[4]); 97 | } 98 | 99 | void sode_system_stoch(double t, double y[_numeq_], double stoch[_numeq_], double p[_numpar_], double noise[_numnoi_]) 100 | { 101 | // g 102 | stoch[0] = 0; 103 | // u 104 | stoch[1] = ((1.00 / T1) + (1.00 / T2)) * (y[3] - y[4])*p[_numpar_ - _numnoi_ + 0] * noise[0] + p[_numpar_ - _numnoi_ + 1] * noise[1]; 105 | // n 106 | stoch[2] = 0; 107 | // r 108 | stoch[3] = 0; 109 | // l 110 | stoch[4] = 0; 111 | // m 112 | stoch[5] = 0; 113 | } -------------------------------------------------------------------------------- /tests/sodecl_python_tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import numpy 3 | import random 4 | import pickle 5 | import sodecl 6 | 7 | class TestPythonWrapper(unittest.TestCase): 8 | 9 | def test_oculomotor_euler(self): 10 | openclplatform = 0 11 | opencldevice = 0 12 | openclkernel = 'oculomotor.cl' 13 | solver = 1 14 | dt = 1e-8 15 | tspan = 0.1 16 | ksteps = 40000 17 | localgroupsize = 0 18 | 19 | orbits = 2 20 | nequat = 6 21 | nparams = 6 22 | nnoi = 0 23 | 24 | # Initial conditions 25 | initx = numpy.ndarray((orbits, nequat)) 26 | for o in range(orbits): 27 | initx[o][0] = 0.0 28 | initx[o][1] = 0.0 29 | initx[o][2] = 0.0 30 | initx[o][3] = 0.0 31 | initx[o][4] = 0.0 32 | initx[o][5] = 2.0 33 | 34 | # Parameters values 35 | params = numpy.ndarray((orbits, nparams)) 36 | for o in range(orbits): 37 | params[o][0] = 120 38 | params[o][1] = 1.5 39 | params[o][2] = 0.0045 40 | params[o][3] = 0.05 41 | params[o][4] = 600 42 | params[o][5] = 9 43 | 44 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 45 | initx, params, solver, 46 | orbits, nequat, nnoi, 47 | dt, tspan, ksteps, localgroupsize) 48 | 49 | test_results = pickle.load(open("data/oculomotor_euler.pkl", "rb")) 50 | self.assertTrue(numpy.isclose(results, test_results).all()) 51 | 52 | def test_oculomotor_rk(self): 53 | openclplatform = 0 54 | opencldevice = 0 55 | openclkernel = 'oculomotor.cl' 56 | solver = 2 57 | dt = 1e-6 58 | tspan = 0.1 59 | ksteps = 400 60 | localgroupsize = 0 61 | 62 | orbits = 2 63 | nequat = 6 64 | nparams = 6 65 | nnoi = 0 66 | 67 | # Initial conditions 68 | initx = numpy.ndarray((orbits, nequat)) 69 | for o in range(orbits): 70 | initx[o][0] = 0.0 71 | initx[o][1] = 0.0 72 | initx[o][2] = 0.0 73 | initx[o][3] = 0.0 74 | initx[o][4] = 0.0 75 | initx[o][5] = 2.0 76 | 77 | # Parameters values 78 | params = numpy.ndarray((orbits, nparams)) 79 | for o in range(orbits): 80 | params[o][0] = 120 81 | params[o][1] = 1.5 82 | params[o][2] = 0.0045 83 | params[o][3] = 0.05 84 | params[o][4] = 600 85 | params[o][5] = 9 86 | 87 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 88 | initx, params, solver, 89 | orbits, nequat, nnoi, 90 | dt, tspan, ksteps, localgroupsize) 91 | 92 | test_results = pickle.load(open("data/oculomotor_rk.pkl", "rb")) 93 | self.assertTrue(numpy.isclose(results, test_results).all()) 94 | 95 | def test_oculomotor_ie(self): 96 | openclplatform = 0 97 | opencldevice = 0 98 | openclkernel = 'oculomotor.cl' 99 | solver = 3 100 | dt = 1e-6 101 | tspan = 0.1 102 | ksteps = 400 103 | localgroupsize = 0 104 | 105 | orbits = 2 106 | nequat = 6 107 | nparams = 6 108 | nnoi = 0 109 | 110 | # Initial conditions 111 | initx = numpy.ndarray((orbits, nequat)) 112 | for o in range(orbits): 113 | initx[o][0] = 0.0 114 | initx[o][1] = 0.0 115 | initx[o][2] = 0.0 116 | initx[o][3] = 0.0 117 | initx[o][4] = 0.0 118 | initx[o][5] = 2.0 119 | 120 | # Parameters values 121 | params = numpy.ndarray((orbits, nparams)) 122 | for o in range(orbits): 123 | params[o][0] = 120 124 | params[o][1] = 1.5 125 | params[o][2] = 0.0045 126 | params[o][3] = 0.05 127 | params[o][4] = 600 128 | params[o][5] = 9 129 | 130 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 131 | initx, params, solver, 132 | orbits, nequat, nnoi, 133 | dt, tspan, ksteps, localgroupsize) 134 | 135 | test_results = pickle.load(open("data/oculomotor_ie.pkl", "rb")) 136 | self.assertTrue(numpy.isclose(results, test_results).all()) 137 | 138 | def test_oculomotor_im(self): 139 | openclplatform = 0 140 | opencldevice = 0 141 | openclkernel = 'oculomotor.cl' 142 | solver = 4 143 | dt = 1e-6 144 | tspan = 0.1 145 | ksteps = 400 146 | localgroupsize = 0 147 | 148 | orbits = 2 149 | nequat = 6 150 | nparams = 6 151 | nnoi = 0 152 | 153 | # Initial conditions 154 | initx = numpy.ndarray((orbits, nequat)) 155 | for o in range(orbits): 156 | initx[o][0] = 0.0 157 | initx[o][1] = 0.0 158 | initx[o][2] = 0.0 159 | initx[o][3] = 0.0 160 | initx[o][4] = 0.0 161 | initx[o][5] = 2.0 162 | 163 | # Parameters values 164 | params = numpy.ndarray((orbits, nparams)) 165 | for o in range(orbits): 166 | params[o][0] = 120 167 | params[o][1] = 1.5 168 | params[o][2] = 0.0045 169 | params[o][3] = 0.05 170 | params[o][4] = 600 171 | params[o][5] = 9 172 | 173 | t, results = sodecl.sodecl(openclplatform, opencldevice, openclkernel, 174 | initx, params, solver, 175 | orbits, nequat, nnoi, 176 | dt, tspan, ksteps, localgroupsize) 177 | 178 | test_results = pickle.load(open("data/oculomotor_im.pkl", "rb")) 179 | self.assertTrue(numpy.isclose(results, test_results).all()) 180 | 181 | if __name__ == '__main__': 182 | unittest.main() 183 | -------------------------------------------------------------------------------- /tests/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.13.4) 2 | 3 | project(unit_tests) 4 | 5 | add_executable(unittest_opencl sodecl_tests.cpp) 6 | target_include_directories(unittest_opencl PRIVATE 7 | ${CMAKE_SOURCE_DIR}/src 8 | ${CMAKE_SOURCE_DIR}/src/sodecl 9 | ${CMAKE_SOURCE_DIR}/external/include) 10 | target_link_libraries(unittest_opencl PUBLIC OpenCL::OpenCL sodecl_lib) 11 | add_test(NAME unittest_opencl COMMAND unittest_opencl) -------------------------------------------------------------------------------- /tests/unit/sodecl_tests.cpp: -------------------------------------------------------------------------------- 1 | #define CATCH_CONFIG_MAIN 2 | 3 | #include "catch.hpp" 4 | #include "sodecl.hpp" 5 | 6 | TEST_CASE("Test OpenCL platforms.") 7 | { 8 | SECTION("Count OpenCL platforms test.") 9 | { 10 | sodecl::opencl_mgr m_opencl_mgr; 11 | int platforms_num = m_opencl_mgr.get_opencl_platform_count(); 12 | 13 | CHECK(platforms_num != -1); 14 | if (platforms_num == -1) 15 | { 16 | FAIL("Failed to count the OpenCL platforms! Try to reinstall OpenCL runtime(s) for your device(s)."); 17 | } 18 | 19 | CHECK(platforms_num > 0); 20 | if (platforms_num == 0) 21 | { 22 | FAIL("No OpenCL platforms! Try to reinstall OpenCL runtime(s) for your device(s)."); 23 | } 24 | } 25 | 26 | SECTION("Create OpenCL platform objects.") 27 | { 28 | sodecl::opencl_mgr m_opencl_mgr; 29 | int platforms_num = m_opencl_mgr.get_opencl_platform_count(); 30 | int status_value = m_opencl_mgr.create_opencl_platforms(); 31 | 32 | CHECK(status_value == 1); 33 | if (status_value == -1) 34 | { 35 | FAIL("Failed to generate the OpenCL platforms objects! Try to reinstall OpenCL runtime(s) for your device(s)."); 36 | } 37 | } 38 | } 39 | 40 | TEST_CASE("Test choosing the first OpenCL device.") 41 | { 42 | SECTION("Choose the first OpenCL device of the first OpenCL platform.") 43 | { 44 | sodecl::opencl_mgr m_opencl_mgr; 45 | int platforms_num = m_opencl_mgr.get_opencl_platform_count(); 46 | int status_value = m_opencl_mgr.create_opencl_platforms(); 47 | 48 | status_value = m_opencl_mgr.choose_opencl_device(0, sodecl::device_Type::ALL, 0); 49 | 50 | CHECK(status_value == 1); 51 | if (status_value == -1) 52 | { 53 | FAIL("Failed to choose the OpenCL device selected!"); 54 | } 55 | } 56 | } 57 | 58 | TEST_CASE("Test creation of OpenCL context.") 59 | { 60 | SECTION("Create OpenCL context.") 61 | { 62 | sodecl::opencl_mgr m_opencl_mgr; 63 | int platforms_num = m_opencl_mgr.get_opencl_platform_count(); 64 | int status_value = m_opencl_mgr.create_opencl_platforms(); 65 | status_value = m_opencl_mgr.choose_opencl_device(0, sodecl::device_Type::ALL, 0); 66 | 67 | status_value = m_opencl_mgr.create_opencl_context(); 68 | 69 | CHECK(status_value == 1); 70 | if (status_value == -1) 71 | { 72 | FAIL("Failed to create the OpenCL context for the selected platform and device!"); 73 | } 74 | } 75 | } 76 | 77 | // TEST_CASE("Test creation of OpenCL kernel.") 78 | // { 79 | // SECTION("Create Euler solver kernel.") 80 | // { 81 | // sodecl::opencl_mgr m_opencl_mgr; 82 | // int platforms_num = m_opencl_mgr.get_opencl_platform_count(); 83 | // int status_value = m_opencl_mgr.create_opencl_platforms(); 84 | // status_value = m_opencl_mgr.choose_opencl_device(0, sodecl::device_Type::ALL, 0); 85 | // status_value = m_opencl_mgr.create_context(); 86 | 87 | // int number_of_orbits = 10; 88 | // int number_of_states = 4; 89 | // int number_of_params = 6; 90 | // cl_double *y0 = new cl_double[number_of_orbits*number_of_states]; 91 | // for (int i=0; i