A More Intuitive Approach to Optimising Audio DSP Code - Gustav Andersson - ADC23

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025
  • audio.dev/ -- @audiodevcon​
    A More Intuitive Approach to Optimising Audio DSP Code - Guiding the Compiler Through Optimising Your Code for You - Gustav Andersson - ADC 2023
    As audio developers we all want our code to be blazingly fast, DSP code in particular. But when reading up on how to optimise audio DSP code, it is easy to get sucked into a world of counting divisions, vector instructions, compiler intrinsics and inline assembly, and think: this is impossible. These are techniques with a very steep learning curve and that require deep technical knowledge of how CPUs and compilers work. The resulting code is also often difficult to read, maintain, and possibly less flexible, as direct inline assembly or intrinsics are often tied to specific cpu architectures.
    This talk will present a completely different approach to optimising, one that is more intuitive and accessible, and doesn’t trade speed for readability and maintainability of the code - Simply let your compiler do the hard work for you!
    Compilers today are immensely good at optimising code. The difference between an optimised and un-optimised build of the same code can be an order of magnitude, if not more. Still there are things we as programmers can do when we write our code, that affects the level to which the compiler can optimise it.
    In this talk we will talk about techniques compilers use to optimise code, and how to write code in a way that enables the compiler to optimise it as efficiently as possible. We will show useful patterns, and anti-patterns, that facilitate or hinder optimisation respectively. We will discuss how to benchmark and measure code and different kinds of bottlenecks, i.e. cpu/memory/pipeline bound code, and how to get the compiler to tell us when it is not able to optimise efficiently.
    We will go through a few case studies comparing the performance and generated assembly code, before and after optimisation techniques have been employed. We will also take a look at how using functions from the c++ standard library compares to writing your own functions.
    The main focus will be on optimising small, tight loops of audio DSP code that generally run directly from cache. The focus will not be on optimising higher level architecture, memory layout or cache-friendliness.
    The talk will come with a companion repository posted on github.
    _
    Gustav Andersson
    Will code C++ and python for fun and profit. Developer, guitar player and electronic music producer with a deep fascination with everything that makes sounds in one form or another. Currently on my mind: modern C++ methods, DSP algos, vintage digital/analog hybrid synths.
    _
    Streamed & Edited by Digital Medium Ltd: online.digital...
    _
    Organized and produced by JUCE: juce.com/
    _
    Special thanks to the ADC23 Team:
    Sophie Carus
    Derek Heimlich
    Andrew Kirk
    Bobby Lombardi
    Tom Poole
    Ralph Richbourg
    Jim Roper
    Jonathan Roper
    Prashant Mishra
    #adc #audiodev #dsp #audio #cpp

ความคิดเห็น • 3

  • @pedrobotsaris2036
    @pedrobotsaris2036 3 หลายเดือนก่อน

    Incredible talk! Very clear and good examples

  • @gokk99
    @gokk99 6 หลายเดือนก่อน +1

    Great talk, it's kind of hard to find good information on DSP optimization as it is a very specific problem compared to general purpose optimizations. Wish more people saw this

  • @eyedl
    @eyedl 9 หลายเดือนก่อน +3

    Here is a summary of the talk with timestamps:
    Introduction @00:00
    Speaker is Gusta Anderson, senior software dev at Elk Audio
    Elk Audio makes Elk Audio OS (Linux-based OS for musical instruments) and Elk Live (low latency online music collaboration tool)
    Optimizing DSP code with compiler assistance @01:00
    Readability and clarity should be prioritized, but code should express intent so compiler can optimize
    Collapsing abstractions: abstractions like loops, functions, classes should disappear when compiling
    What affects performance @05:29
    CPU bound, memory bound, pipeline bound (long dependency chains)
    What compilers do @11:29
    Inlining, loop optimization, auto-vectorization, rearranging statements, removing unneeded variables
    Compilers are good at optimizing, so avoid sacrificing readability prematurely
    Promoting auto-vectorization @17:39
    Loop count should be known at compile time, no control flow in loop
    Fixed buffer sizes allow better optimization, but many plugin APIs don't support this well
    Fixed size arrays often faster than dynamic ones like std::vector
    Inlining and constants @21:01
    Functions in headers, especially member functions, are usually inlined
    Avoid virtual functions in inner loops
    Be careful with float/double division - multiply by reciprocal if dividing by a constant value
    Branchless code @26:06
    Branchless code is deterministic and doesn't depend on data
    Compilers can often make simple code branchless, like max(), even in loops - trust the compiler
    Use optimized math libraries before trying to hand-code branchless algorithms
    Reducing memory access @31:29
    Fastest data is in registers, then cache, then main memory
    Copying state variables to stack may allow better compiler optimization
    Aliasing (having multiple pointers to same data) can prevent optimization
    C++ lacks good "restrict" keyword to indicate no aliasing - raw pointers or compiler extensions needed
    Handling recursive filters @38:50
    Recursive algorithms like IIR filters are hard to optimize due to dependencies
    Interleaving samples from parallel instances (e.g. stereo) can help
    Adding delays between cascaded sections allows parallelizing higher-order filters
    Summary @42:29
    Use fixed buffer sizes
    Ensure functions are inlined
    Write clear branchless code
    Exploit parallelism opportunities
    Benchmark standard library functions
    Avoid float divisions
    More resources @43:52
    Compiler Explorer, Agner Fog's optimization guides, Elk Audio blog posts, CppCon/ADC talks