Skip to content
Pedro Mediano edited this page Nov 25, 2018 · 2 revisions

How to use GPU estimators

Demos > GPU

JIDT now ships with GPU implementations for the KSG estimators (for mutual information and conditional mutual information, and measures using these such as transfer entropy and active information storage).

In order to use these, there are three steps to follow:

  1. Install CUDA toolkit;
  2. Compile the JIDT GPU estimator library;
  3. Call the JIDT GPU estimators from your code.

These are outlined in the following:

Install CUDA toolkit

Before making or using the JIDT GPU estimators, you need to have the NVIDIA CUDA toolkit installed. This may be packaged for your platform, e.g. the nvidia-cuda-toolkit package on Ubuntu, or else obtained from NVIDIA.

Compile JIDT GPU library

On each platform you install JIDT and wish to run the GPU estimators, you should build the JIDT GPU library, by running ant gpu and then re-packaging the jar file by running ant jar. You can test the GPU library with ant gputest.

Alternatively, to turn GPU compilation on by default, you can set the enablegpu flag to true in build.xml, and then clean and recompile by running ant clean jar.

By default the GPU code is compiled as a dynamic (.so) library, packaged into the jar and then loaded through a temporary directory at run-time. If you wish to modify this library you can set the path manually through the GPU_LIBRARY_PATH property (javadoc).

Call the JIDT GPU estimators

In order to use the JIDT GPU estimators, you simply set the property "USE_GPU" to true on the KSG estimator that you want to run in GPU mode rather than in CPU. That's all!

There are several ways to see the code for this in more detail:

  1. Simple Java demos: see the Example10GPUBenchmark.java in the demos/java/infodynamics/demos folder; you can run this with demos/java/example10GPUBenchmark.sh and then plotExample10BenchmarkResults.sh
  2. Unit tests: see the three JUnit tests GPUCondMutualInfoTester.java, GPUMutualInfoTester.sh and GPUPerformanceTester.sh in the folder java/unittests/infodynamics/measures/continuous/kraskov; you can run these with ant gputest from the top level folder
  3. AutoAnalyser: For any of the relevant KSG estimators, set the property "USE_GPU" to true using the drop-down property menus; generate the code in your language of choice (Java, Matlab or Python) and then run the generated code in that language.

To get the most out of the GPU library, it is useful to understand what GPUs are good at, and what they're bad at: in general, GPUs are good at solving massively parallel problems, but they lag behind CPUs when it comes to sequential computation. In JIDT, GPU parallelisation is implemented at the level of surrogates -- which means that calls with few or no surrogates won't exploit the full potential of the GPU.

If you only use a single call to computeAverageLocalOfObservations you will likely not benefit from the GPU library (unless your GPU is disproportionately more expensive than your CPU!). Instead, you should be calling the computeSignificance(int) method implemented by all relevant GPU-enabled calculators, and will return the observed value of the quantity being measured (e.g. MI, TE) as well as the null distribution.

Please read the relevant section of the javadocs and section A5 of the JIDT paper for more information on surrogates and significance testing.

Clone this wiki locally