Skip to content

GPU accelerated Functions

parsa roshanak edited this page Jul 3, 2025 · 1 revision

GPU-Accelerated Fractional Calculus

Overview

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.


GL_gpu – GPU-Accelerated Grünwald-Letnikov Fractional Derivative

Mathematical Background

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.

Implementation Notes

  • 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.

Function Signature

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

Parameters

  • alpha (float): The order of the fractional derivative.
  • f_name (Callable, list, or np.ndarray): Function, lambda, or sequence of function values to be differintegrated. If callable, it will be evaluated at num_points equally spaced points on the CPU and transferred to the GPU.
  • domain_start (float, optional): Start of the domain. Default is 0.0.
  • domain_end (float, optional): End of the domain. Default is 1.0.
  • num_points (int, optional): Number of points in the domain. Default is 100.

Returns

  • result (np.ndarray): Array of the Grünwald-Letnikov fractional derivative values (on the CPU).

Example Usage

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])

Installation

Install CuPy with CUDA support (choose the correct version for your CUDA toolkit):

pip install cupy-cuda12x

Replace 12x with your CUDA version if needed (see [CuPy installation docs](https://docs.cupy.dev/en/stable/install.html)).


Notes

  • 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 RuntimeError is raised.

See Also

  • GL: CPU version of the Grünwald-Letnikov fractional derivative.
  • GLI: Improved GL method (CPU).

Clone this wiki locally