feat: Added MLX GPU Acceleration to Tensor, MuitiVector, and Topology crate#433
feat: Added MLX GPU Acceleration to Tensor, MuitiVector, and Topology crate#433marvin-hansen merged 55 commits intodeepcausality-rs:mainfrom
Conversation
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…epo. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…on. Updated relativistic_current_kernel to use manifold. Updated downstream physics example. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
… spec. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…ssue deepcausality-rs#428 Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…loses deepcausality-rs#432 Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…aration for backend impl. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…ckend specific implementations of tensor ops. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
… for CPU. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…or CPU. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
… impl. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…X execution. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
….md. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…README.md. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…ability of the crate. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…ltiField type with MLX acceleration. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…tiField type. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…support. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
… underlyuing tensor, multivector, and topology crates. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…iField. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…usalMultiFied. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
… HKT physics Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to be92279
Previous suggestionsSuggestions up to commit be92279
✅ Suggestions up to commit 3a2a365
✅ Suggestions up to commit 8848b13
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #433 +/- ##
==========================================
- Coverage 94.79% 86.32% -8.48%
==========================================
Files 723 777 +54
Lines 28710 31698 +2988
==========================================
+ Hits 27217 27362 +145
- Misses 1493 4336 +2843 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…not be tested on CI. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…les for better maintainabiliy. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…improvements. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…improvements. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
…improvements. Signed-off-by: Marvin Hansen <marvin.hansen@gmail.com>
|
Persistent suggestions updated to latest commit be92279 |
User description
Describe your changes
This PR adds MLX hardware acceleration to the causal tensor, causal multivector, and causal topology crate.
Furthermore, the Multi-Backend implementation has been prepared for a future NVIDIA CUDA backend.
Issue ticket number and link
Closes #432
Closes #428
Code checklist before requesting a review
For details on make, please see BUILD.md
Note: The CI runs all of the above and fixing things before they hit CI speeds
up the review and merge process. Thank you.
PR Type
Enhancement, Tests
Description
MLX GPU Acceleration: Implements
TensorBackendandLinearAlgebraBackendtraits for MLX GPU acceleration with comprehensive tensor operations (create, reshape, permute, slice, stack, einsum) and linear algebra operations (matmul, QR, SVD, inverse, Cholesky)Tensor Architecture Refactoring: Refactors tensor implementation from
CausalTensor<T>toInternalCpuTensor<T>with simplified trait bounds and improved API consistency across CPU and backend implementationsMultivector Enhancements: Adds Higher-Kinded Type (HKT) operations for
CausalMultiFieldenabling functional programming patterns (Functor, Applicative, Monad, Comonad)Physics Implementations: Introduces Particle Data Group (PDG) database, Lund string fragmentation kernel for QCD hadronization, and Regge geometry metric signature computation
Comprehensive Test Coverage: Adds extensive test suites for multivector algebra operations, Clifford algebra products, grade projections, differential operators, metric operations, and arithmetic operations
Example Applications: Includes SCUBA diving decompression planner demonstrating physics simulation and modular multi-physics pipeline using Causal Monad pattern
Backend Tensor Operations: Implements arithmetic trait operations (Add, Sub, Mul, Div) and einsum AST execution for backend tensors
Diagram Walkthrough
File Walkthrough
10 files
ein_sum_impl.rs
Refactor EinSum operations to InternalCpuTensor with improvedvalidationdeep_causality_tensor/src/types/cpu_tensor/ops/tensor_ein_sum/ein_sum_impl.rs
CausalTensortoInternalCpuTensorwithsimplified trait bounds
execute_ein_sumcalls with directEinSumOp::TensorSourcepattern matching in operand extractioncontract()method with comprehensive validation andmulti-dimensional index iteration logic
pub(in crate::types::causal_tensor)topub(crate)andpub(in crate::types::cpu_tensor)mlx_backend_tensor.rs
MLX GPU Backend Implementation for Tensor Operationsdeep_causality_tensor/src/types/backend/mlx/mlx_backend_tensor.rs
TensorBackendtrait for MLX GPU acceleration with 588 linesof new code
stack, ravel
broadcasting, arg_sort
(slice, arg_sort, shifted_view)
mod.rs
Refactor CPU Tensor API to Use InternalCpuTensor Typedeep_causality_tensor/src/types/cpu_tensor/api/mod.rs
InternalCpuTensorinstead ofCausalTensorqr(),svd(), andstack()for linear algebraoperations
TensorDatainstead of multipleindividual bounds
ops.rs
Backend Tensor Arithmetic and Operations Implementationdeep_causality_tensor/src/types/backend_tensor/ops.rs
BackendTensor: Add, Sub,Mul, Div
operations
DivAssign
types
main.rs
Modular Multi-Physics Pipeline via Causal Monad Patternexamples/physics_examples/multi_physics_pipeline/main.rs
the Causal Monad pattern
hadronization()call withlund_string_fragmentation_kernel()for realistic QCD stringfragmentation
fragmentation, thermalization, and quantum detection
modular composition
mlx_backend_linear_algebra.rs
MLX GPU Linear Algebra Backend Implementationdeep_causality_tensor/src/types/backend/mlx/mlx_backend_linear_algebra.rs
LinearAlgebraBackendtrait for MLX GPU backend withoperations:
matmul,qr,svd,inverse,cholesky_decomposition,solve_least_squares_cholsky,tensor_productfor GPU compatibility (fallback to CPU for non-4x4 cases)
reshaping on MLX arrays
mod.rs
Higher-Kinded Type Operations for CausalMultiFielddeep_causality_multivector/src/extensions/hkt_multifield/mod.rs
CausalMultiField:fmap,pure,apply,bind,extract,extendCausalMultiFieldWitnessto work around HKT traitincompatibilities with
TensorDataconstraintsComonad) on fields
pdg.rs
Particle Data Group (PDG) Database Implementationdeep_causality_physics/src/nuclear/pdg.rs
ParticleDatastructcontaining PDG ID, mass, charge, spin, and name
mesons, light/strange/charmed baryons, Delta and Omega baryons
pdg_lookup(),pdg_mass(), and quarkconstituent mass constants
mod.rs
Regge Geometry Metric Signature Computationdeep_causality_topology/src/types/regge_geometry/mod.rs
metric_at()to compute metric signature from Cayley-MengerGram matrix using edge lengths
compute_signature()function that builds Gram matrix andcomputes eigenvalues via Jacobi algorithm
euclidean_metric_at()fast-path for known Euclidean geometriescompute_eigenvalues()using Jacobi rotation method forsmall symmetric matrices
signatures
fragmentation.rs
Lund String Fragmentation Kernel Implementationdeep_causality_physics/src/nuclear/lund/fragmentation.rs
lund_string_fragmentation_kernel()for QCD stringfragmentation into hadrons
transverse momentum, selects quark flavor, forms mesons
number, strangeness
conservation, multiplicity scaling with energy
1 files
main.rs
Add SCUBA decompression planner example with physics simulationexamples/medicine_examples/diving_decompression/main.rs
Bühlmann ZH-L16C algorithm
CausalTensorfor tissue compartment tracking andCausalEffectPropagationProcessfor monadic dive phase chainingtoxicity, and decompression ceiling computation
risk analysis, and safety recommendations
11 files
ein_sum_impl_tests.rs
Update EinSum tests to use InternalCpuTensor APIdeep_causality_tensor/src/types/cpu_tensor/ops/tensor_ein_sum/ein_sum_impl_tests.rs
CausalTensor::methods toInternalCpuTensor::methods.into_inner()conversions on test utility functions to extractinternal tensor representation
EinSumASTandEinSumOpfromcpu_tensormodule
implementation behavior
mod.rs
Add CausalMultiField algebra operation testsdeep_causality_multivector/tests/types/multifield/algebra/mod.rs
CausalMultiFieldalgebra operations(scale, normalize, inverse, reversion, commutators)
inversion, and grade reversion
and relationship verification
field operations
cpu_tests.rs
Add CpuGammaLoader Clifford algebra matrix testsdeep_causality_multivector/tests/types/multifield/gamma/cpu_tests.rs
CpuGammaLoaderimplementingBackendGammatraitanticommutation relations {γ_i, γ_j} = 0
orthogonality checks
across different signatures
grmhd_tests.rs
Remove deprecated relativistic current kernel testsdeep_causality_physics/tests/mhd/grmhd_tests.rs
relativistic_current_kernelthat are nowincompatible with updated API
wrappers_tests.rswith
ManifoldandLorentzianMetricrequirementstest_energy_momentum_tensortest for electromagnetic tensorvalidation
arithmetic_tests.rs
Comprehensive Arithmetic Tests for CausalMultiFielddeep_causality_multivector/tests/types/multifield/arithmetic/arithmetic_tests.rs
CausalMultiFieldarithmeticoperations (446 lines)
negative)
products_tests.rs
Clifford Algebra Products and Commutator Testsdeep_causality_multivector/tests/types/multifield/ops/products_tests.rs
outer_product, cross
changes)
grades_tests.rs
Grade Projection and Part Extraction Testsdeep_causality_multivector/tests/types/multifield/ops/grades_tests.rs
CausalMultiFieldtrivector_part, pseudoscalar_part
cases
mod.rs
Add Gamma Tests Module Structuredeep_causality_multivector/tests/types/multifield/gamma/mod.rs
metric_tests.rs
Comprehensive Metric Type Test Suitedeep_causality_metric/tests/types/metric_tests.rs
Metrictype covering dimension,signature, and sign operations
to_generic(),from_signature(),from_signs(),to_signs()flip_time_space(),tensor_product(),is_compatible()conversions_tests.rs
CausalMultiField Conversion Operations Test Suitedeep_causality_multivector/tests/types/multifield/ops/conversions_tests.rs
CausalMultiFieldconversion operations:zeros(),ones(),from_coefficients(),to_coefficients()through conversion cycles
compute_matrix_dim()helper function with various inputdimensions
discretization parameters
differential_tests.rs
Differential Operators Test Suite for CausalMultiFielddeep_causality_multivector/tests/types/multifield/ops/differential_tests.rs
CausalMultiField:partial_derivative(),gradient(),curl(),divergence()Axisenum (X, Y, Z) indexing and equalitygrade-2, divergence as grade-0)
101 files