Integration Strategies

AADC provides flexible integration approaches to accommodate different project sizes, development constraints, and performance requirements. This section outlines the primary integration strategies, their trade-offs, and implementation considerations.

Template-Based Integration

Overview

For new or small projects, the template-based approach is commonly used in practice, allowing the same mathematical code to work with both native double and active idouble types.

template<typename mdouble>
class BlackScholesModel {
public:
    mdouble calculatePrice(mdouble spot, mdouble strike, mdouble vol, mdouble rate, mdouble time) {
        mdouble d1 = (std::log(spot/strike) + (rate + 0.5*vol*vol)*time) / (vol*std::sqrt(time));
        mdouble d2 = d1 - vol*std::sqrt(time);
        return spot*std::cdf_normal(d1) - strike*std::exp(-rate*time)*std::cdf_normal(d2);
    }
};

// Usage
BlackScholesModel<double> passive_model;    // Regular computation
BlackScholesModel<idouble> active_model;    // AADC-enabled computation

Pros

  • Performance optimal: No overhead when using native double
  • Future flexibility: Easy to add test with other numeric types (e.g., float, multi-precision, active types from other libraries)

Cons

  • Requires upfront design: Must template from the beginning
  • Slow compilation: Template instantiation significantly increases compile times for large projects, slowing development
  • Type incompatibility: Cannot use existing std::vector<double> or other native objects directly in recording - requires creating active copies, making recording transitions expensive
  • Library dependencies: External libraries must support template types or require wrappers
  • Learning curve: Developers need familiarity with template programming

When to Use

  • New mathematical libraries or analytical components
  • Projects with well-defined computational boundaries
  • Performance-critical applications requiring optimal efficiency on Windows

Type Redefinition Integration

Overview

For large existing codebases or straightforward development, the type redefinition approach allows gradual or wholesale adoption without extensive refactoring by replacing double with idouble through preprocessor definitions or search-and-replace operations.

// Before: double calculateValue(double x, double y);

// Conditional compilation approach
#ifdef AADC_ENABLED
    typedef idouble Real;
#else
    typedef double Real;
#endif
// After:  Real calculateValue(Real x, Real y);

// Or direct replacement approach
// After:  idouble calculateValue(idouble x, idouble y);

Automated Integration Process

Matlogica developed tools to facilitate this integration, which can be performed manually or through automated processes:

// Script-based transformation handles common patterns:
// - Function signatures: double func(double x) → idouble func(idouble x)
// - Variable declarations: double price = 100.0 → idouble price = 100.0
// - Type casting issues: Resolves mixed-type expressions
// - Template parameter updates: vector<double> → vector<idouble>

This tool can be executed in a separate branch to evaluate AADC benefits without disrupting the main development line. At the same time evaluation branch is in synchronization with main development, allowing easy migration at the end of evaluation.

Benefits

  1. Rapid adoption: Can integrate AADC into million-line codebases quickly
  2. Evidence-based decisions: Allows evaluation of AADC benefits before major commitments
  3. Non-disruptive: Main development branch remains unaffected during evaluation
  4. Comprehensive coverage: Ensures all mathematical operations are captured

Performance Considerations

Expected Performance Impact

The wholesale replacement approach introduces performance overhead in non-AADC sections:

  • 50-150% slowdown on average for code not using AADC recording
  • Overhead source: Additional checks on every mathematical operation

Trade-off Analysis

  • Performance penalty: Affects all mathematical operations, even when AADC is not actively recording
  • Expected outcome: Critical performance sections with AADC acceleration (Monte Carlo, calibration, risk calculations) should provide significant speedups that outweigh non-critical section slowdowns
  • Alternative: Refactoring to separate AADC-enabled from non-AADC sections requires extensive effort and may diverge from main development

AADC++ Compiler (Optimal Performance)

Overview

Matlogica provides AADC++, an LLVM/Clang-based compiler that eliminates the performance penalty of the wholesale replacement approach while maintaining the integration simplicity.

AADC++ is a proprietary optimization technology available with the production version of AADC. It delivers near-native performance with only 1-5% overhead when recording is disabled.

Benefits

  • Near-native performance: 1-5% overhead vs. native double when recording is disabled
  • Single code path: No need to maintain separate implementations of active and passive code
  • No need to template: Works with existing codebases without refactoring
  • Automatic optimization: Compiler handles the complexity transparently
  • Production ready: Available with production AADC versions
  • C++ compatibility: All language features (virtual functions, RTTI, static objects) work normally

Features

  • Optimized code generation: Eliminates recording checks in non-AADC recording paths
  • Fast recording toggle: Switching between modes happens in constant time. No need to copy from native to active objects
  • LLVM/Clang support: Works with modern compiler infrastructure

Integration Decision Framework

Choose Template-Based When:

  • Starting new projects or components
  • Performance is critical for both AADC and non-AADC code paths for non LLVM/Clang compilers
  • Development team has strong C++ template experience

Choose Type Redefinition When:

  • Integrating into large existing codebases (100K+ lines)
  • Need rapid AADC evaluation with minimal development effort
  • Acceptable to have performance trade-offs in non-critical sections
  • Want comprehensive AAD coverage across entire application

Choose AADC++ When:

  • Using LLVM/Clang compiler infrastructure
  • Need the simplicity of type redefinition with optimal performance
  • Deploying to production where performance is critical
  • Want the best of both approaches without the trade-offs

This is a preview of the Integration Strategies documentation.

The full documentation includes detailed implementation examples, benchmark results, and configuration guides.

Contact us to request a demo version and get access to the complete documentation.