Algorithmic differentiation (AD) is a set of techniques that provide partial derivatives of computer-implemented functions. Such a function can be supplied to state-of-the-art AD tools via its source code, or via an intermediate representation produced while compiling its source code. We present the novel AD tool Derivgrind, which augments the machine code of compiled programs with forward-mode AD logic. Derivgrind leverages the Valgrind instrumentation framework for a structured access to the machine code, and a shadow memory tool to store dot values. Access to the source code is required at most for the files in which input and output variables are defined. Derivgrind's versatility comes at the price of scaling the run-time by a factor between 30 and 75, measured on a benchmark based on a numerical solver for a partial differential equation. Results of our extensive regression test suite indicate that Derivgrind produces correct results on GCC- and Clang-compiled programs, including a Python interpreter, with a small number of exceptions. While we provide a list of scenarios that Derivgrind does not handle correctly, nearly all of them are academic counterexamples or originate from highly optimized math libraries. As long as differentiating those is avoided, Derivgrind can be applied to an unprecedentedly wide range of cross-language or partially closed-source software with little integration efforts.
翻译:算法微分(AD)是一组提供计算机实现函数偏导数的技术。此类函数可通过其源代码,或编译源代码过程中产生的中间表示形式,提供给最先进的AD工具。我们提出新型AD工具Derivgrind,该工具通过前向模式AD逻辑增强编译程序的机器码。Derivgrind利用Valgrind检测框架实现对机器码的结构化访问,并采用影子内存技术存储点值。除定义输入输出变量的文件外,通常无需访问源代码。基于偏微分方程数值求解器的基准测试表明,Derivgrind的通用性以运行时放大30至75倍为代价。我们的大量回归测试套件结果显示,Derivgrind对GCC和Clang编译的程序(包括Python解释器)能产生正确结果,仅存在少数例外情况。虽然我们列出了Derivgrind无法正确处理的场景清单,但几乎全部属于学术反例或源自高度优化的数学库。只要避免对这些场景进行微分,Derivgrind即可以极小的集成工作量应用于前所未有的广泛跨语言或部分闭源软件。