Supported GPU Modules
| CPU Module | GPU Module | Typical Speedup |
|---|---|---|
| FAImageFD.CFAImageFD | FAImageFDGPU.CFAImageFDGPU | 3–10× |
| FAImageMFS.CFAImageMFS | FAImageMFSGPU.CFAImageMFSGPU | 5–20× |
| FAImageLAC.CFAImageLAC | FAImageLACGPU.CFAImageLACGPU | 5–15× |
Requirements
- NVIDIA GPU with CUDA support
- PyTorch with CUDA:
pip install torch --index-url https://download.pytorch.org/whl/cu118
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
| Scenario | Expected Speedup |
|---|---|
| Single large image (1024×1024) | 5–10× |
| Batch 100+ images | 10–20× |
| Many q values (51+) | 5–15× |
| Many scales (80+) | 3–8× |
API Differences from CPU
| Feature | CPU | GPU |
|---|---|---|
p_value | Computed | None (not computed) |
| Default dtype | float64 | float64 (single), float32 (batch) |
device parameter | N/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.