jgrusewski fdb2a843b5 merge: nsys hot-kernel optimisations (kernels #1 + #3)
L40S nsys profile (commit 0d630c799) identified three hot kernels:
- backtest_state_gather: 37.2% / 60k calls
- cuBLAS gemvx:          25.0% / 242k calls (val TLOB SGEMMs)
- compute_expected_q:    12.9% / 1.4k calls

Kernels #1 + cuBLAS #2 (folded together because most gemvx calls were
val TLOB SGEMMs) — commit 072ca4568:
* Added backtest_state_gather_chunk kernel that writes [chunk_len,
  n_windows, padded_sd] directly into chunked_states_buf in a single
  launch with chunk_len*n_windows threads (1 thread per output row).
* Refactored submit_dqn_step_loop_cublas Phase 1: per-step launch +
  DtoD copy loop replaced by a single batched call. Per-chunk launch
  count: 2*chunk_len -> 1 (1024x reduction at chunk_len=512).
* Val TLOB now sized to DQN_BACKTEST_CHUNK_SIZE * n_windows so it
  runs once per chunk on chunked_states_buf at batch=chunk_len*n_windows
  instead of chunk_len separate calls. Per-chunk cuBLAS reduction:
  chunk_len*4=2048 -> 4 (~500x).
* Single-step backtest_state_gather retained for evaluate() /
  evaluate_ppo() / evaluate_supervised() paths.

Kernel #3 (compute_expected_q) — commit 5f26c5751:
* Replaced 3-pass softmax (max -> sum_exp -> normalize+expected+entropy)
  with online softmax (Page-Olshen running-max + running-sum). Inner
  atom loop: 3 -> 2 passes, ~33% fewer global loads of adv_a[z] per
  (action, branch) pair.
* Bit-stable when atoms processed in fixed order. Underflow safety
  preserved analytically (no prob*log(prob) edge case).
* ABI unchanged; no Rust caller migration needed.

Deferred: Q/K/V SGEMM fusion (~50% of remaining ~500 val + ~300k
training calls) gated by tlob_sdp_forward kernel ABI changes
(stride parameter or unpacking step). ~200 LOC follow-up; recommend
re-profiling post-deploy to confirm training-side TLOB still hot.
2026-04-28 23:36:11 +02:00

Foxhunt

Production HFT trading system in Rust.

Architecture

The workspace contains 32 crates organized as follows:

Core Libraries (16)

Crate Purpose
trading_engine Order processing, FIX 4.4, IB TWS, SIMD, RDTSC timing
risk VaR, Kelly, circuit breakers, kill switches, compliance
risk-data Risk data types and shared structures
trading-data Trading data types
ml DQN Rainbow, PPO, TFT, Mamba2, ensemble inference
ml-data ML data types and feature definitions
data Market data ingestion and storage
backtesting Replay engine, strategy tester
adaptive-strategy Ensemble execution, microstructure analysis
common Shared types, resilience, error handling
storage S3 and local model storage
model_loader Model serialization and loading
market-data Market data feed handlers
database PostgreSQL access layer (SQLx)
config Configuration management
tli CLI commands and tooling

Services (8)

Service Purpose
backtesting_service gRPC backtesting service
broker_gateway_service FIX routing, broker connectivity
trading_service Core trading operations
ml_training_service Model training orchestration
data_acquisition_service Market data acquisition
trading_agent_service Autonomous trading agents
api_gateway gRPC API gateway with auth
web-gateway Axum REST + WebSocket gateway

Frontend

web-dashboard/ -- React 19 + TypeScript + Vite + TradingView charts.

Building

# Check compilation (no PostgreSQL required)
SQLX_OFFLINE=true cargo check --workspace

# Run tests for a specific crate
SQLX_OFFLINE=true cargo test -p <crate> --lib

# Clippy
SQLX_OFFLINE=true cargo clippy --workspace

ML Models

Four production model architectures on Candle v0.9.1 with CUDA:

  • DQN Rainbow -- Deep Q-Network with prioritized replay, dueling heads, noisy nets
  • PPO -- Proximal Policy Optimization with GAE and LSTM policies
  • TFT -- Temporal Fusion Transformer for multi-horizon forecasting
  • Mamba2 -- State space model for sequence prediction

Each model has a standalone trainer and a UnifiedTrainable adapter for the hyperopt pipeline.

Infrastructure

  • Git: Gitea at git.fxhnt.ai (Tailscale-only), Scaleway DEV1-S
  • Observability: OpenTelemetry OTLP (env OTEL_EXPORTER_OTLP_ENDPOINT)
  • Database: PostgreSQL with SQLx offline mode for CI

License

Proprietary. All rights reserved.

Description
No description provided
Readme 849 MiB
Languages
Rust 88.2%
Cuda 7.7%
Python 1.3%
Shell 1.1%
PLpgSQL 0.8%
Other 0.8%