{"id":18604963,"url":"https://github.com/finmath/finmath-lib-opencl-extensions","last_synced_at":"2025-06-19T15:39:29.692Z","repository":{"id":57737152,"uuid":"345417709","full_name":"finmath/finmath-lib-opencl-extensions","owner":"finmath","description":"Vector class (RandomVariable) running on GPUs using OpenCL.","archived":false,"fork":false,"pushed_at":"2021-03-14T21:09:15.000Z","size":6331,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T19:11:19.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/finmath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-07T18:07:47.000Z","updated_at":"2024-05-28T05:48:23.000Z","dependencies_parsed_at":"2022-08-24T14:57:20.394Z","dependency_job_id":null,"html_url":"https://github.com/finmath/finmath-lib-opencl-extensions","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/finmath/finmath-lib-opencl-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finmath%2Ffinmath-lib-opencl-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finmath%2Ffinmath-lib-opencl-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finmath%2Ffinmath-lib-opencl-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finmath%2Ffinmath-lib-opencl-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/finmath","download_url":"https://codeload.github.com/finmath/finmath-lib-opencl-extensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/finmath%2Ffinmath-lib-opencl-extensions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260780494,"owners_count":23062041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T02:19:30.788Z","updated_at":"2025-06-19T15:39:24.675Z","avatar_url":"https://github.com/finmath.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"finmath lib opencl extensions\n==========\n\nProject home page: https://finmath.net/finmath-lib-opencl-extensions\n\n****************************************\n\n**Vector class (RandomVariable) running on GPUs using OpenCL.**\n\n**Enabling finmath lib with OpenCL (via jocl). - Running finmath lib models on a GPU.**\n\n****************************************\n\nThe *finmath lib opencl extensions* provide an OpenCL implementation of the [finmath lib](http://finmath.net/finmath-lib/) interfaces `RandomVariable` and `BrownianMotion` compatible with finmath lib 5.1 or later\n(tested on GRID GPU Kepler GK105, GeForce GTX 1080, GeForce GT 750M, AMD Radeon Pro 560, Apple M1).\n\nFor Cuda support see finmath-lib-cuda-extensions.\n\nPerformance Characteristics\n-------------------------------------\n\n\u003cimg src=\"images/LIBORMarketModelCalibrationATMTest-Graph.png\" style=\"width: 50%; float: right;\"/\u003e\n\nThe current implementation uses very small OpenCL kernels which affects the performance. This may be optimized quite straight forwardly in future versions.\nThis implies a specific performance characteristic: the OpenCL communication overhead constitutes a certain amount of \"fixed costs\".\nDepending on GPU and CPU specifics the performance is at par for Monte Carlo simulations with 5000 paths.\nHowever, for larger number of paths, the CPU scales linear, while the GPU show almost no change. That is, For a\nMonte-Carlo simulation with 50000 paths, the GPU is 10 times faster than the CPU. For 100000 paths, the GPU is 20 times faster than the CPU.\n\n\n### Limitations\n\n\nThe main limitation is GPU memory. RandomVariable objects are held on the GPU and kept as long as they are referenced.\nSince multiple processes may aquire GPU memory, it may be less clear how much GPU memory is available.\n\nYou may check the memory profile of your calculation by running it on a CPU - the requirements are comparable.\n\nAnother aspect that may affect the performance is the OpenCL implementation.\n\n\u003cdiv style=\"clear: both;\"/\u003e\n\nInterfaces for which OpenCL Implementations are Provided\n-------------------------------------\n\n### RandomVariable\n\nA `RandomVariableOpenCLFactory` is provided (implementing `RandomVariableFactory`), which can be injected in any finmath lib model/algorithm using a random variable factory to construct `RandomVariable` objects.\n\nObjects created from this factory or from objects created from this factory perform their calculation on the OpenCL device (GPU).\n\nThe implementation supports type priorities (see http://ssrn.com/abstract=3246127 ) and the default priority of `RandomVariableOpenCL` is 20. For example: operators involving CPU and GPU vectors will result in GPU vectors.\n\nThe `RandomVariableOpenCLFactory` can be combined with *algorithmic differentiation* AAD wrappers, for example `RandomVariableDifferentiableAAD`, to allow algorithmic differentiation together with calculations performed on the GPU. For the type priority: objects allowing for algorithmic differentiation (AAD) have higher priority, AAD on GPU has higher priority than AAD on CPU.\n\n\nDistribution\n-------------------------------------\n\nfinmath-lib-opencl-extensions is distributed through the central Maven repository. It's coordinates are:\n\n    \u003cgroupId\u003enet.finmath\u003c/groupId\u003e\n    \u003cartifactId\u003efinmath-lib-opencl-extensions\u003c/artifactId\u003e\n\nThe project is currently build for OpenCL 2.0.\n\nExample\n-------------------------------------\n\nCreate a vector of floats on the GPU device\n\n```\nRandomVariable randomVariable = new RandomVariableOpenCL(new float[] {-4.0f, -2.0f, 0.0f, 2.0f, 4.0f} );\n```\n\nperform some calculations (still on the GPU device)\n\n```\nrandomVariable = randomVariable.add(4.0);\nrandomVariable = randomVariable.div(2.0);\n```\n\nperform a reduction on the GPU device\n\n```\ndouble average = randomVariable.getAverage();\n```\n\nor get the result vector (to the host)\n\n```\ndouble[] result = randomVariable.getRealizations();\n```\n\n(note: the result is always double, since different implementation may support float or double on the device).\n\nInstallation / Build\n-------------------------------------\n\nBinary distribution is available via Maven central.\n\nTo build the project yourself and run the unit tests from the source repository:\n\nObtain the finmath-lib-opencl-extensions source\n\n```\ngit clone https://github.com/finmath/finmath-lib-opencl-extensions.git\ncd finmath-lib-opencl-extensions\n```\n\n...then build the code.\n\n```\nmvn clean package\n```\n\nThis will build the version using OpenCL 2.0. For OpenCL 1.0 use\n\n```\nmvn -Dopencl.version=1.0 clean package\n```\n\nIf everything goes well, you will see unit test run. Note that some of the tests may fail if the device (GPU) has not enough memory. \n\nTrying more\n-------------------------------------\n\nYou may turn on logging using `-Djava.util.logging.config.file=logging.properties`. To try different configurations you may use\n\n  - `-Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceType=GPU -Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceIndex=0`\n  - `-Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceType=CPU -Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceIndex=0`\n  - `-Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceType=GPU -Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceIndex=1`\n\nfor example\n  \n```\nmvn clean install test -Djava.util.logging.config.file=logging.properties -Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceType=GPU -Dnet.finmath.montecarlo.opencl.RandomVariableOpenCL.deviceIndex=1\n```\n\nYou may run dedicated tests using\n\n  - `-Dtest=RandomVariableGPUTest`\n  - `-Dtest=MonteCarloBlackScholesModelTest`\n  - `-Dtest=LIBORMarketModelCalibrationATMTest`\n  - `-Dtest=LIBORMarketModelCalibrationTest`\n\nThe last tests are computationally heavy Monte-Carlo interest rate models. The test may fail on devices that lack sufficient memory.\n\nTrying on Amazon EC2\n-------------------------------------\n\nIf you do not have a machine with a suitable GPU at hand, you may try out the finmath-lib-opencl-extensions on an Amazon EC2 machine. To do so:\n\n* Create an Amazon AWS account (if needed) an go to your AWS console.\n* Select to start an EC2 virtual server.\n* Launch a GPU instance\n  - Filter the list of images (AMI) using `gpu` and select - e.g. - `Deep Learning Base AMI (Ubuntu) Version 19.0`.\n  - Filter the list of servers using the \"GPU instances\" and select an instance.\n* Login to your GPU instance.\n* Try finmath-lib-opencl-extensions as described in the previous section.\n\nPerformance\n-------------------------------------\n\n### Unit test for LIBOR Market Model calibration: Parametric model with Stochastic Volatility.\n\nThere are also a unit tests performing a brute force Monte-Carlo calibration of a LIBOR Market Model / discrete term structure model, with stochastic volatility.\n\nThe performance of a brute-force Monte-Carlo calibration with 80K and 160K paths are given below. Note: if the number of paths is increased, the GPU time remains almost the same (given that the GPU has sufficient memory), while the CPU time grows linearly. This is due to the fact that the GPU performance has a large part of fixed management overhead (which will be reduced in future versions).\n\nThe CPU version was run on a an Intel i7-7800X 3.5 GHz using multi-threadded calibration.\nTHe GPU version was run on an nVidia GeForce GTX 1080.\n\n#[[\n#### LMM with 81,920 paths\n]]#\n\n```\nRunning net.finmath.montecarlo.interestrates.LIBORMarketModelCalibrationTest\n\nCalibration to Swaptions using CPU    calculation time = 364.42 sec    RMS Error.....: 0.198%.\nCalibration to Swaptions using GPU    calculation time =  49.46 sec    RMS Error.....: 0.198%.\n```\n(LIBOR Market Model with stochastic volatility, 6 factors, 81920 paths)\n\n#### LMM with 163,840 paths\n\n```\nRunning net.finmath.montecarlo.interestrates.LIBORMarketModelCalibrationTest\n\nCalibration to Swaptions using CPU    calculation time = 719.33 sec    RMS Error.....: 0.480%.\nCalibration to Swaptions using GPU    calculation time =  51.70 sec    RMS Error.....: 0.480%.\n```\n(LIBOR Market Model with stochastic volatility, 6 factors, 163840 paths)\n\n\n### Unit test for LIBOR Market Model calibration: Model with High Number of Parameters with Piecewise-Constant Volatility Surface\n\n```\nRunning net.finmath.montecarlo.interestrates.LIBORMarketModelCalibrationATMTest\n\nOpenCL on GPU   number of paths: 5000\tComputation time: \t322.99\t sec.\tDeviation:\tmean:\t5.290e-07,\trms:\t6.54E-05\nOpenCL on GPU   number of paths: 12500\tComputation time: \t334.53\t sec.\tDeviation:\tmean:\t3.782e-07,\trms:\t6.90E-05\nOpenCL on GPU   number of paths: 25000\tComputation time: \t255.47\t sec.\tDeviation:\tmean:\t3.026e-07,\trms:\t6.61E-05\nOpenCL on GPU   number of paths: 50000\tComputation time: \t256.69\t sec.\tDeviation:\tmean:\t3.248e-07,\trms:\t6.59E-05\nOpenCL on GPU   number of paths: 100000\tComputation time: \t256.15\t sec.\tDeviation:\tmean:\t3.733e-07,\trms:\t6.49E-05\nCPU             number of paths: 5000\tComputation time: \t181.8\t sec.\tDeviation:\tmean:\t5.386e-07,\trms:\t6.54E-05\nCPU             number of paths: 12500\tComputation time: \t564.56\t sec.\tDeviation:\tmean:\t3.805e-07,\trms:\t6.90E-05\nCPU             number of paths: 25000\tComputation time: \t761.94\t sec.\tDeviation:\tmean:\t3.024e-07,\trms:\t6.61E-05\nCPU             number of paths: 50000\tComputation time: \t1561.47\t sec.\tDeviation:\tmean:\t3.249e-07,\trms:\t6.59E-05\nCPU             number of paths: 100000\tComputation time: \t3857.36\t sec.\tDeviation:\tmean:\t3.742e-07,\trms:\t6.49E-05\n```\n\nProfiles for Other OpenCL Versions\n-------------------------------------\n\nThe default profile will build the version using OpenCL 2.0 (it is compatible with OpenCL 1.0 and should run with older versions).\n\n#### OpenCL 1.0\n\nFor OpenCL 1.0 use\n\n```\nmvn -Dopencl.version=1.0 clean package\n```\n\n#### OpenCL 2.0\n\nFor OpenCL 2.0 use\n\n```\nmvn -Dopencl.version=2.0 clean package\n```\n\n\nReferences\n-------\n\n* [finmath lib Project documentation](http://finmath.net/finmath-lib/)\nprovides the documentation of the library api.\n* [finmath lib API documentation](http://finmath.net/finmath-lib/apidocs/)\nprovides the documentation of the library api.\n* [finmath.net special topics](http://www.finmath.net/topics)\ncover some selected topics with demo spreadsheets and uml diagrams.\nSome topics come with additional documentations (technical papers).\n\nLicense\n-------\n\nThe code of \"finmath lib\", \"finmath lib opencl extensions\" and \"finmath lib cuda extensions\" (packages\n`net.finmath.*`) are distributed under the [Apache License version\n2.0](http://www.apache.org/licenses/LICENSE-2.0.html), unless otherwise explicitly stated.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinmath%2Ffinmath-lib-opencl-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffinmath%2Ffinmath-lib-opencl-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffinmath%2Ffinmath-lib-opencl-extensions/lists"}