-
Notifications
You must be signed in to change notification settings - Fork 0
GPU accelerated Functions
This page documents GPU-accelerated functions for fractional calculus in the differintP package. GPU acceleration is provided via [CuPy](https://cupy.dev/), an open-source NumPy-compatible array library for NVIDIA CUDA GPUs. These implementations are designed for large-scale problems where significant speedup is possible by leveraging GPU hardware.
Currently, the following function is available:
-
GL_gpu: Grünwald-Letnikov fractional derivative using FFTs on the GPU.
Note: CuPy is an optional dependency and must be installed separately. If CuPy is not available, calling GPU functions will raise a
RuntimeError.
The method matches the standard GL implementation, but performs all array operations and FFT-based convolution on the GPU for substantial performance improvements, especially with large arrays.
- Uses CuPy for GPU arrays and FFTs.
- Automatically transfers results back to CPU as NumPy arrays for easy interoperability.
- Falls back to a runtime error with a helpful message if CuPy is not available.
GL_gpu(
alpha: float,
f_name: Callable | np.ndarray | list,
domain_start: float = 0.0,
domain_end: float = 1.0,
num_points: int = 100,
) -> np.ndarray-
alpha (
float): The order of the fractional derivative. -
f_name (
Callable,list, ornp.ndarray): Function, lambda, or sequence of function values to be differintegrated. If callable, it will be evaluated atnum_pointsequally spaced points on the CPU and transferred to the GPU. -
domain_start (
float, optional): Start of the domain. Default is0.0. -
domain_end (
float, optional): End of the domain. Default is1.0. -
num_points (
int, optional): Number of points in the domain. Default is100.
-
result (
np.ndarray): Array of the Grünwald-Letnikov fractional derivative values (on the CPU).
import numpy as np
from differintP import GL_gpu
# Compute D^0.5 sqrt(x) over [0, 1] using GPU acceleration
result_gpu = GL_gpu(0.5, np.sqrt, 0., 1., 100_000)
print(result_gpu[:10])Install CuPy with CUDA support (choose the correct version for your CUDA toolkit):
pip install cupy-cuda12xReplace 12x with your CUDA version if needed (see [CuPy installation docs](https://docs.cupy.dev/en/stable/install.html)).
- Results are returned as standard NumPy arrays for compatibility with the rest of your workflow.
- Speedup is most significant for large
num_points(thousands or more). - If CuPy is not installed or no GPU is available, a
RuntimeErroris raised.