A backend-agnostic Julia framework for 3D modeling and inversion of gravity data.
This package implements a high-performance framework for three-dimensional gravity modeling and inversion in Julia. The framework addresses computational complexity, ill-posedness, and non-uniqueness in gravity inversion through:
- Data-space inversion to reduce dimensionality
- Backend-agnostic implementation using KernelAbstractions.jl
- Multi-GPU support (NVIDIA CUDA, Apple Metal, AMD, Intel oneAPI)
- Advanced regularization with depth weighting and sparsity constraints
using Pkg
Pkg.add("https://github.com/naimat04/GravityInversionGPU.jl.git")Or clone and activate:
git clone https://github.com/naimat04/GravityInversionGPU.jl.git
cd GravityInversionGPU.jl
julia --project=. -e 'using Pkg; Pkg.instantiate()'This package supports multiple GPU backends. Install only the package for your GPU type:
| GPU Type | Package to Install |
|---|---|
| NVIDIA (CUDA) | Pkg.add("CUDA") |
| Apple Silicon (Metal) | Pkg.add("Metal") |
| AMD | Pkg.add("AMDGPU") |
| Intel (Arc/Xe) | Pkg.add("oneAPI") |
Note: GPU packages are optional. If none are installed, the package automatically uses CPU.
Run the included example to verify everything works:
# Test with small mesh (recommended first test)
julia --project=. examples/run_inversion.jl --nx 4 --ny 4 --nz 2
# Test with medium mesh (more realistic)
julia --project=. examples/run_inversion.jl --nx 10 --ny 10 --nz 5
# Test with parameters from paper
julia --project=. examples/run_inversion.jl --nx 40 --ny 40 --nz 20After running, check the output:
ls -la examples/gravity_inversion_output_ka/You should see files like model.mesh, model_gpu.true, model_gpu.inv, etc.
# Same code runs on CPU/GPU
@kernel function compute_gravity_kernel(A, cells, data)
i, j = @index(Global, NTuple)
# Gravity computation - runs on any backend
endThe framework automatically detects and uses available GPU hardware:
- NVIDIA GPUs: CUDA.jl backend
- Apple Silicon: Metal.jl backend
- AMD GPUs: AMDGPU.jl backend
- Intel GPUs: oneAPI.jl backend
- Fallback: CPU backend if no GPU available
src/
├── GravityInversionGPU.jl # Main module
└── modules/
├── CoreFunctions.jl # Math functions
├── GPUBackend.jl # GPU detection
├── ForwardModeling.jl # Forward modeling
├── Inversion.jl # Inversion algorithms
├── IOUtils.jl # File I/O
└── Visualization.jl # Plotting
| Total Cells (nx×ny×nz) | CPU Time (s) | GPU Time (s) | Speedup |
|---|---|---|---|
| 1,000 | 0.22 | 19.25 | 0.01× |
| 36,000 | 0.23 | 19.23 | 0.01× |
| 133,100 | 0.77 | 20.46 | 0.04× |
| 1,056,000 | 0.65 | 19.94 | 0.03× |
| 1,000,800 | 374.01 | 20.42 | 18.3× |
| 1,458,000 | 512.19 | 20.62 | 24.8× |
| 2,448,000 | 892.93 | 20.63 | 43.3× |
| 3,168,000 | 1139.62 | 22.17 | 51.4× |
| 3,213,000 | 1153.07 | 22.20 | 51.9× |
Note: GPU shows significant speedup for problems >1 million cells
- Small problems (<100k cells): CPU performs better due to GPU overhead
- Medium problems (100k-1M cells): GPU begins to show advantage
- Large problems (>1M cells): GPU provides 20-50× speedup
mesh = (
xm_min = -20.0, ym_min = -20.0, z0 = 0.0,
dx = 500.0, dy = 500.0, dz = 500.0,
nx = 40, ny = 40, nz = 20,
eps = 0.1, delta = 1e-4
)
write_mesh_UBC(mesh) # Save to UBC format# Run inversion with custom parameters
inverted_model = Inversion_GPU(G_matrix, Q_diag, D_diag, obs_data,
delta=1e-4, itmax=10, igmax=20)# Generate comparison plots
composite_surface_plot(xobs, yobs, observed_data, predicted_data)
composite_model_plot(true_model, inverted_model, mesh)The framework generates standard output files:
model.mesh- Mesh definition (UBC format)model_gpu.true- True density modelmodel_gpu.inv- Inverted modeldata.obs- Observed/synthetic datadata_gpu.pred- Predicted datadata_fit_gpu.png- Data fit visualizationmodel_plot_gpu.png- Model comparison plots
- Two Vertical Dykes: Tests resolution of multiple bodies
- Examples from real field data are presented in our accompanying paper
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
MIT License - see LICENSE file for details.
For questions and support:
- Open an issue on GitHub
- Contact: 24D0455@iitb.ac.in
- Indian Institute of Technology Bombay
- Geological Survey of Finland
- Julia community for excellent tooling
Note: This is research software. Please report any issues or suggestions for improvement.