Enterprise NIF Acceleration
View SourceThis guide explains how to enable high-performance Rust NIFs for enterprise users.
Overview
macula-tweann has two editions:
| Feature | Community (hex.pm) | Enterprise (private git) |
|---|---|---|
| Core TWEANN | Yes | Yes |
| Pure Erlang fallback | Yes | Yes |
| Bundled Rust NIFs | No | Yes |
| Enterprise NIF package | No | Yes |
| Performance | Baseline | 10-15x faster |
| Rust toolchain required | No | Yes |
Performance Improvements
Enterprise NIFs provide significant speedups for compute-intensive operations:
| Operation | Speedup |
|---|---|
| Network evaluation | ~10x |
| Batch mutation | ~13x |
| KNN novelty (search) | ~12x |
| Fitness statistics | ~12x |
| Weight distance | ~15x |
Installation
Community Edition (Default)
Install from hex.pm - no additional setup required:
{deps, [
{macula_tweann, "~> 0.17.0"}
]}.Uses pure Erlang fallbacks automatically.
Enterprise Edition
Add the private enterprise NIF package alongside macula-tweann:
{deps, [
{macula_tweann, "~> 0.17.0"},
{macula_nn_nifs, {git, "git@github.com:macula-io/macula-nn-nifs.git", {tag, "v0.2.0"}}}
]}.Requirements:
- Rust 1.70+ and Cargo installed
- SSH access to the private macula-nn-nifs repository
How It Works
The tweann_nif module automatically detects and uses enterprise NIFs:
Priority Order:
1. macula_nn_nifs (enterprise) - If available and loaded
2. Bundled NIF (tweann_nif) - If compiled with Rust
3. Pure Erlang (tweann_nif_fallback) - Always availableNo code changes required - detection is automatic at startup.
Verification
Check which implementation is being used:
1> tweann_nif:is_loaded().
true %% NIFs available (enterprise or bundled)
2> macula_nn_nifs:is_loaded().
true %% Enterprise NIFs specificallyAccelerated Functions
The enterprise NIFs accelerate 67 functions across these categories:
Network Evaluation
compile_network/3- Compile topology for fast evaluationevaluate/2- Forward propagationevaluate_batch/2- Batch evaluationcompatibility_distance/5- NEAT speciation distancebenchmark_evaluate/3- Performance benchmarking
Signal Aggregation
dot_product_flat/3- Weighted sum with biasdot_product_batch/1- Batch weighted sumsdot_product_preflattened/3- Pre-optimized dot productflatten_weights/1- Weight structure optimization
LTC/CfC Neurons
evaluate_cfc/4- Closed-form continuous-time evaluationevaluate_cfc_with_weights/6- CfC with custom weightsevaluate_ode/5- ODE-based LTC evaluationevaluate_ode_with_weights/7- ODE with custom weightsevaluate_cfc_batch/4- Batch CfC for time series
Novelty Search
euclidean_distance/2- Vector distanceeuclidean_distance_batch/2- Batch distancesknn_novelty/4- K-nearest neighbor noveltyknn_novelty_batch/3- Batch novelty computation
Statistics
fitness_stats/1- Single-pass min/max/mean/variance/stddev/sumweighted_moving_average/2- WMA computationshannon_entropy/1- Entropy calculationhistogram/4- Histogram binning
Selection
build_cumulative_fitness/1- Roulette wheel setuproulette_select/3- Binary search roulette selectionroulette_select_batch/3- Batch selectiontournament_select/2- Tournament selection
Meta-Controller
z_score/3- Z-score normalizationcompute_reward_component/2- Reward signal computationcompute_weighted_reward/1- Multi-component rewards
Evolutionary Genetics
mutate_weights/4- Gaussian weight mutationmutate_weights_seeded/5- Reproducible mutationmutate_weights_batch/1- Batch mutation with per-genome paramsmutate_weights_batch_uniform/4- Batch with uniform paramsrandom_weights/1- Generate random weightsrandom_weights_seeded/2- Seeded random weightsrandom_weights_gaussian/3- Gaussian distributed weightsrandom_weights_batch/1- Batch weight generationweight_distance_l1/2- L1 (Manhattan) distanceweight_distance_l2/2- L2 (Euclidean) distanceweight_distance_batch/3- Batch distance computation
SIMD Batch Activations (NEW in v0.2.0)
tanh_batch/1- Vectorized tanh activationsigmoid_batch/1- Vectorized sigmoid activationrelu_batch/1- Vectorized ReLU activationsoftmax_batch/1- Vectorized softmax activation
Layer-Specific Mutation (NEW in v0.2.0)
layer_specific_mutate/3- Mutate with per-layer rateslayer_specific_mutate_batch/1- Batch layer-specific mutation
Plasticity Rules (NEW in v0.2.0)
hebbian_update/4- Hebbian plasticity weight updatemodulated_hebbian_batch/4- Batch modulated Hebbian learningstdp_update/5- STDP (Spike-Timing Dependent Plasticity)oja_update/5- Oja's learning rule
Extended CfC/LTC (NEW in v0.2.0)
evaluate_cfc_sequence/5- Sequential CfC evaluationevaluate_cfc_parallel/1- Parallel CfC for multiple neuronsltc_state_batch/4- Batch LTC state computation
Population Analysis (NEW in v0.2.0)
population_diversity/1- Mean/min/max/variance of populationweight_covariance_matrix/1- Weight correlation analysispairwise_distances_batch/2- Batch pairwise distance matrix
NEAT Crossover (NEW in v0.2.0)
neat_crossover/4- NEAT-style genome crossoveralign_genes_by_innovation/2- Align genes by innovation numbercount_excess_disjoint/2- Count excess and disjoint genes
Speciation (NEW in v0.2.0)
kmeans_speciation/3- K-means based speciation clustering
Matrix Operations (NEW in v0.2.0)
matmul_add_bias/3- Matrix multiply with bias additionlayer_forward/3- Single layer forward passmulti_layer_forward/2- Multi-layer forward pass
Meta-Learning (NEW in v0.2.0)
gradient_free_meta_learn/4- Gradient-free meta-learning
Network Compression (NEW in v0.2.0)
network_prune/2- Prune small weightsweight_quantize/2- Quantize weights to fixed precision
Enterprise Licensing
Contact licensing@macula.io for enterprise access to:
- Private macula-nn-nifs repository
- Priority support
- Custom NIF development
Troubleshooting
NIFs not detected
Check if macula_nn_nifs is in your dependency path:
code:which(macula_nn_nifs).
%% Should return path, not 'non_existing'Rust compilation fails
Ensure Rust toolchain is installed:
rustc --version # Should be 1.70+
cargo --version
Performance not improved
Verify NIFs are loaded:
macula_nn_nifs:is_loaded(). %% Should be trueIf false, check for NIF loading errors in the Erlang shell output.