GPU
RecurrenceMicrostatesAnalysis.jl supports GPU acceleration for computing RMA distributions. The GPU backend is implemented using KernelAbstractions.jl, which enables portable GPU execution across different hardware backends.
The GPU pipeline is implemented via a GPUCore, which defines a single internal kernel used to compute microstate histograms across supported devices.
Data requirements
The GPU backend supports only Float32 data. Therefore, input datasets must be explicitly converted before being used:
using RecurrenceMicrostatesAnalysis, Distributions
data = StateSpaceSet(Float32.(rand(Uniform(0, 1), 1000)))1-dimensional StateSpaceSet{Float32} with 1000 points
0.14377917
0.67664564
0.075778745
0.6407332
0.66440666
0.8474236
0.1413314
0.53737825
0.18213958
0.2772973
⋮
0.33788076
0.30877522
0.060387507
0.06340307
0.10326237
0.17285343
0.5770751
0.87220806
0.06731922When using the GPU backend, inputs must be of type Float32. RecurrenceMicrostatesAnalysis.jl is not compatible with Float64 on GPU.
Recurrence expressions and metrics
When defining a RecurrenceExpression for GPU execution, the distance metric must be a subtype of GPUMetric. Metrics from Distances.jl are not supported on GPU.
For example:
expr = Standard(0.27f0; metric = GPUEuclidean())Standard{Float32, GPUEuclidean}(0.27f0, GPUEuclidean())The GPU backend is not compatible with metrics from Distances.jl.
Moving data to GPU memory
To enable GPU computation, the data must be transferred to GPU memory. For example:
- Using CUDA:
using CUDA
gpu_data = data |> CuVector - Using Metal:
using Metal
gpu_data = data |> MtlVectorOutput handling
Results computed on the GPU are automatically transferred back to the CPU:
histogramreturns aCountsobject.distributionreturns aProbabilitiesobject.
No manual data transfer is required for the output.
Metrics for GPU
Since the GPU backend does not support Distances.jl, distance metrics must be implemented explicitly as subtypes of GPUMetric.
RecurrenceMicrostatesAnalysis.GPUMetric — Type
GPUMetric <: MetricAbstract supertype for metrics compatible with the GPU backend.
Metrics subtyping GPUMetric must implement the internal evaluation function gpu_evaluate, which is used during GPU-based computations.
Implementations
Implemented GPU metrics
RecurrenceMicrostatesAnalysis.GPUEuclidean — Type
GPUEuclidean <: GPUMetricGPU-compatible implementation of the Euclidean distance metric.
\[d(\vec{x}, \vec{y}) = \sqrt{\sum_{i = 1}^{m} (x_i - y_i)^2}\]