GPU Acceleration

Drop-in GPU-accelerated replacements for core fractal analysis modules

Supported GPU Modules

CPU ModuleGPU ModuleTypical Speedup
FAImageFD.CFAImageFDFAImageFDGPU.CFAImageFDGPU3–10×
FAImageMFS.CFAImageMFSFAImageMFSGPU.CFAImageMFSGPU5–20×
FAImageLAC.CFAImageLACFAImageLACGPU.CFAImageLACGPU5–15×

Requirements

Usage

Drop-in Import Replacement

# CPU from FreeAeonFractal.FAImageMFS import CFAImageMFS # GPU (identical API) from FreeAeonFractal.FAImageMFSGPU import CFAImageMFSGPU as CFAImageMFS

Fractal Dimension (GPU)

from FreeAeonFractal.FAImageFDGPU import CFAImageFDGPU fd_bc = CFAImageFDGPU(bin_image, device='cuda').get_bc_fd() fd_dbc = CFAImageFDGPU(gray, device='cuda').get_dbc_fd() fd_sdbc = CFAImageFDGPU(gray, device='cuda').get_sdbc_fd()

Multifractal Spectrum (GPU)

import numpy as np from FreeAeonFractal.FAImageMFSGPU import CFAImageMFSGPU as CFAImageMFS MFS = CFAImageMFS(gray, q_list=np.linspace(-5, 5, 51)) df_mass, df_fit, df_spec = MFS.get_mfs() MFS.plot(df_mass, df_fit, df_spec)

Lacunarity (GPU)

from FreeAeonFractal.FAImageLACGPU import CFAImageLACGPU calc = CFAImageLACGPU(gray, device='cuda') lac_result = calc.get_lacunarity() fit_result = calc.fit_lacunarity(lac_result)

Batch Processing (GPU)

import glob, cv2, numpy as np from FreeAeonFractal.FAImageMFSGPU import CFAImageMFSGPU images = [cv2.imread(f, cv2.IMREAD_GRAYSCALE) for f in glob.glob('./images/*.png')] results = CFAImageMFSGPU.get_batch_mfs(images, q_list=np.linspace(-5, 5, 26)) for df_mass, df_fit, df_spec in results: print(df_fit[['q', 'Dq']].head(3))

Performance Notes

ScenarioExpected Speedup
Single large image (1024×1024)5–10×
Batch 100+ images10–20×
Many q values (51+)5–15×
Many scales (80+)3–8×

API Differences from CPU

FeatureCPUGPU
p_valueComputedNone (not computed)
Default dtypefloat64float64 (single), float32 (batch)
device parameterN/A'cuda' or 'cpu'

CUDA Availability Check

import torch print("CUDA available:", torch.cuda.is_available())

If CUDA is unavailable, GPU modules fall back to CPU computation.