Skip to content

Commit

Permalink
deploy: 8a2c86d
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Nov 8, 2023
1 parent 557d92f commit e479462
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion getting_started/UsingEnzyme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
}
});
</script><link rel=apple-touch-icon sizes=180x180 href="/apple-touch-icon.png?v=1"><link rel=icon type=image/png sizes=32x32 href="/favicon-32x32.png?v=1"><link rel=icon type=image/png sizes=16x16 href="/favicon-16x16.png?v=1"><link rel=manifest href="/site.webmanifest?v=1"><link rel=mask-icon href="/safari-pinned-tab.svg?v=1" color=#3775e0><link rel="shortcut icon" href="/favicon.ico?v=1"><meta name=msapplication-TileColor content="#2d89ef"><meta name=theme-color content="#ffffff"><link rel=icon href=/favicon.svg type=image/svg+xml sizes=any><style>:root{}</style></head><body><div class=container><header><h1><div><a href=/ style=text-decoration:none;color:#000><img src=https://enzyme.mit.edu//logo.svg width=40px align=absmiddle>
Enzyme AD</a></div></h1><p class=description>Enzyme Automatic Differentiation Framework</p></header><div class=global-menu><nav><ul><li class=parent><a href>Community<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=https://groups.google.com/d/forum/enzyme-dev>Discussion List</a></li></ul></li><li><a href=https://github.com/EnzymeAD/Enzyme>GitHub</a></li><li><a href=https://github.com/wsmoses/Enzyme/issues>Bugs</a></li><li><a href=/explorer>Try Online</a></li><li><a href=/conference>Conference</a></li><li><a href=/getting_started/Faq/>FAQ</a></li></ul></nav></div><div class=content-container><main><h1>Using Enzyme</h1><h2 id=generating-llvm>Generating LLVM&nbsp;<a class=headline-hash href=#generating-llvm></a></h2><p>To begin, let&rsquo;s create a simple code <code>test.c</code> we want to differentiate. Enzyme will replace any calls to functions whose names contain &ldquo;__enzyme_autodiff&rdquo; with calls to the corresponding For now, let&rsquo;s ignore the details of Enzyme&rsquo;s calling convention/ABI which are described in detail
Enzyme AD</a></div></h1><p class=description>Enzyme Automatic Differentiation Framework</p></header><div class=global-menu><nav><ul><li class=parent><a href>Community<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=https://groups.google.com/d/forum/enzyme-dev>Discussion List</a></li></ul></li><li><a href=https://github.com/EnzymeAD/Enzyme>GitHub</a></li><li><a href=https://github.com/wsmoses/Enzyme/issues>Bugs</a></li><li><a href=/explorer>Try Online</a></li><li><a href=/conference>Conference</a></li><li><a href=/getting_started/Faq/>FAQ</a></li></ul></nav></div><div class=content-container><main><h1>Using Enzyme</h1><h2 id=differentiating-cc>Differentiating C/C++&nbsp;<a class=headline-hash href=#differentiating-cc></a></h2><p>Enzyme supports differentiating C/C++ code through ClangEnzyme and LLDEnzyme as compiler and linker plugins, respectively.
Clang gives our plugin more flexibility in adding and ordering optimization passes than LLD and therefore using ClangEnzyme could result in better performance than LLDEnzyme.
However, ClangEnzyme can only differentiate one compilation unit at a time and will therefore fail if the function which you try to differentiate calls functions
in other compilation units (generally other .c or .cpp files). In these cases we recommend the use of LLDEnzyme in combination with LTO.
Finally, for full control you can also compile your c/c++ project down to LLVM-IR and pass it directly to LLVMEnzyme, see the example below.</p><p>An example for using LLDEnzyme as part of CMake is available
<a href=https://github.com/EnzymeAD/Enzyme/blob/main/enzyme/test/test_find_package/CMakeLists.txt>here</a>
.
Examples for using ClangEnzyme or LLVMEnzyme without CMake are given below, but please keep in mind that the plugin infrastructure and syntax changed a few times
and will generally depend on your LLVM Version. Please open an issue if you encounter issues (and please extend this section
<a href=https://github.com/EnzymeAD/www>here</a>
if you have time!)</p><h2 id=generating-llvm>Generating LLVM&nbsp;<a class=headline-hash href=#generating-llvm></a></h2><p>To begin, let&rsquo;s create a simple code <code>test.c</code> we want to differentiate. Enzyme will replace any calls to functions whose names contain &ldquo;__enzyme_autodiff&rdquo; with calls to the corresponding For now, let&rsquo;s ignore the details of Enzyme&rsquo;s calling convention/ABI which are described in detail
<a href=/getting_started/CallingConvention/>here</a></p><div class=highlight><pre class=chroma><code class=language-c data-lang=c><span class=c1>// test.c
</span><span class=c1></span><span class=cp>#include</span> <span class=cpf>&lt;stdio.h&gt;</span><span class=cp>
</span><span class=cp></span><span class=k>extern</span> <span class=kt>double</span> <span class=nf>__enzyme_autodiff</span><span class=p>(</span><span class=kt>void</span><span class=o>*</span><span class=p>,</span> <span class=kt>double</span><span class=p>);</span>
Expand Down
2 changes: 1 addition & 1 deletion getting_started/index.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Getting Started on Enzyme AD</title><link>https://enzyme.mit.edu/getting_started/</link><description>Recent content in Getting Started on Enzyme AD</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Fri, 29 Nov 2019 15:26:15 +0000</lastBuildDate><atom:link href="https://enzyme.mit.edu/getting_started/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Enzyme</title><link>https://enzyme.mit.edu/getting_started/UsingEnzyme/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/UsingEnzyme/</guid><description>Generating LLVM To begin, let&amp;rsquo;s create a simple code test.c we want to differentiate. Enzyme will replace any calls to functions whose names contain &amp;ldquo;__enzyme_autodiff&amp;rdquo; with calls to the corresponding For now, let&amp;rsquo;s ignore the details of Enzyme&amp;rsquo;s calling convention/ABI which are described in detail here // test.c #include &amp;lt;stdio.h&amp;gt;extern double __enzyme_autodiff(void*, double); double square(double x) { return x * x; } double dsquare(double x) { // This returns the derivative of square or 2 * x return __enzyme_autodiff((void*) square, x); } int main() { for(double i=1; i&amp;lt;5; i++) printf(&amp;#34;square(%f)=%f, dsquare(%f)=%f&amp;#34;, i, square(i), i, dsquare(i)); } We can generate LLVM from this code by calling clang as follows.</description></item><item><title>Calling Convention</title><link>https://enzyme.mit.edu/getting_started/CallingConvention/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CallingConvention/</guid><description>Enzyme is invoked by calling a function __enzyme_autodiff with the function being differentiated, followed by the corresponding primal and shadow arguments. This will result in the original function being run with the corresponding derivative values being computed.
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Getting Started on Enzyme AD</title><link>https://enzyme.mit.edu/getting_started/</link><description>Recent content in Getting Started on Enzyme AD</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Fri, 29 Nov 2019 15:26:15 +0000</lastBuildDate><atom:link href="https://enzyme.mit.edu/getting_started/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Enzyme</title><link>https://enzyme.mit.edu/getting_started/UsingEnzyme/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/UsingEnzyme/</guid><description>Differentiating C/C++ Enzyme supports differentiating C/C++ code through ClangEnzyme and LLDEnzyme as compiler and linker plugins, respectively. Clang gives our plugin more flexibility in adding and ordering optimization passes than LLD and therefore using ClangEnzyme could result in better performance than LLDEnzyme. However, ClangEnzyme can only differentiate one compilation unit at a time and will therefore fail if the function which you try to differentiate calls functions in other compilation units (generally other .</description></item><item><title>Calling Convention</title><link>https://enzyme.mit.edu/getting_started/CallingConvention/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CallingConvention/</guid><description>Enzyme is invoked by calling a function __enzyme_autodiff with the function being differentiated, followed by the corresponding primal and shadow arguments. This will result in the original function being run with the corresponding derivative values being computed.
Function Hooks Enzyme replaces all calls to functions that contain the string __enzyme_autodiff with a call to the corresponding derivative. This is done to allow Enzyme to register multiple function signatures.
#include &amp;lt;stdio.h&amp;gt;template&amp;lt;typename T&amp;gt; T square(T x) { return x * x; } float __enzyme_autodiffFloat(float (*)(float), float); double __enzyme_autodiffDouble(double (*)(double), double); int main() { printf(&amp;#34;float d/dx %f\n&amp;#34;, __enzyme_autodiffFloat(square&amp;lt;float&amp;gt;, 1.</description></item><item><title>C++ Examples</title><link>https://enzyme.mit.edu/getting_started/Examples/</link><pubDate>Tue, 25 Jul 2023 00:00:00 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/Examples/</guid><description>There are many ways to implement a given calculation. This document contains examples of how to apply Enzyme to different kinds of patterns that show up frequently in C++. To make the code snippets below more concise, we&amp;rsquo;ll assume that each example snippet has the following definitions prepended to the translation unit:
int enzyme_dup; int enzyme_dupnoneed; int enzyme_out; int enzyme_const; template &amp;lt; typename return_type, typename ... T &amp;gt; return_type __enzyme_fwddiff(void*, T .</description></item><item><title>CUDA Guide</title><link>https://enzyme.mit.edu/getting_started/CUDAGuide/</link><pubDate>Wed, 20 Jan 2021 00:00:00 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CUDAGuide/</guid><description>Reference C++ example WARNING: CUDA support is highly experimental and in active development.
Expand Down
2 changes: 1 addition & 1 deletion index.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Enzyme AD</title><link>https://enzyme.mit.edu/</link><description>Recent content on Enzyme AD</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 19 Oct 2017 15:26:15 +0000</lastBuildDate><atom:link href="https://enzyme.mit.edu/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Enzyme</title><link>https://enzyme.mit.edu/getting_started/UsingEnzyme/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/UsingEnzyme/</guid><description>Generating LLVM To begin, let&amp;rsquo;s create a simple code test.c we want to differentiate. Enzyme will replace any calls to functions whose names contain &amp;ldquo;__enzyme_autodiff&amp;rdquo; with calls to the corresponding For now, let&amp;rsquo;s ignore the details of Enzyme&amp;rsquo;s calling convention/ABI which are described in detail here // test.c #include &amp;lt;stdio.h&amp;gt;extern double __enzyme_autodiff(void*, double); double square(double x) { return x * x; } double dsquare(double x) { // This returns the derivative of square or 2 * x return __enzyme_autodiff((void*) square, x); } int main() { for(double i=1; i&amp;lt;5; i++) printf(&amp;#34;square(%f)=%f, dsquare(%f)=%f&amp;#34;, i, square(i), i, dsquare(i)); } We can generate LLVM from this code by calling clang as follows.</description></item><item><title>Presentations</title><link>https://enzyme.mit.edu/talks/Talks/</link><pubDate>Wed, 29 Mar 2023 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/talks/Talks/</guid><description>Tech Talks Supercomputing (SC) 2022, Scalable Automatic Differentiation of Multiple Parallel Paradigms through Compiler Augmentation ; William S. Moses, Sri Hari Krishna Narayanan, Ludger Paehler, Valentin Churavy, Jan Hueckelheim, Michel Schanen, Johannes Doerfert, and Paul Hovland; video 2nd MODE Workshop on Differentiable Programming for Experiment Design 2022, Synthesization of Fast Gradients with Enzyme ; William S. Moses, Ludger Paehler, Tim Gymnich, and Valentin Churavy; slides ICPP Workshop on LLVM in Parallel Processing (LLPP) 2022, Enzyme: Automatic Differentiation of Parallel Programs ; William S.</description></item><item><title>Related Publications</title><link>https://enzyme.mit.edu/talks/Publications/</link><pubDate>Wed, 29 Mar 2023 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/talks/Publications/</guid><description>Papers SC 22, Scalable Automatic Differentiation of Multiple Parallel Paradigms through Compiler Augmentation ; William S. Moses, Sri Hari Krishna Narayanan, Ludger Paehler, Valentin Churavy, Michel Schanen, Jan Hueckelheim, Johannes Doerfert, and Paul Hovland. Best Student Paper SC 21, Reverse-Mode Automatic Differentiation and Optimization of GPU Kernels via Enzyme ; William S. Moses, Valentin Churavy, Ludger Paehler, Jan Hückelheim, Sri Hari Krishna Narayanan, Michel Schanen, and Johannes Doerfert. NeurIPS 2020, Instead of Rewriting Foreign Code for Machine Learning, Automatically Synthesize Fast Gradients ; William S.</description></item><item><title>Calling Convention</title><link>https://enzyme.mit.edu/getting_started/CallingConvention/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CallingConvention/</guid><description>Enzyme is invoked by calling a function __enzyme_autodiff with the function being differentiated, followed by the corresponding primal and shadow arguments. This will result in the original function being run with the corresponding derivative values being computed.
<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Enzyme AD</title><link>https://enzyme.mit.edu/</link><description>Recent content on Enzyme AD</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 19 Oct 2017 15:26:15 +0000</lastBuildDate><atom:link href="https://enzyme.mit.edu/index.xml" rel="self" type="application/rss+xml"/><item><title>Using Enzyme</title><link>https://enzyme.mit.edu/getting_started/UsingEnzyme/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/UsingEnzyme/</guid><description>Differentiating C/C++ Enzyme supports differentiating C/C++ code through ClangEnzyme and LLDEnzyme as compiler and linker plugins, respectively. Clang gives our plugin more flexibility in adding and ordering optimization passes than LLD and therefore using ClangEnzyme could result in better performance than LLDEnzyme. However, ClangEnzyme can only differentiate one compilation unit at a time and will therefore fail if the function which you try to differentiate calls functions in other compilation units (generally other .</description></item><item><title>Presentations</title><link>https://enzyme.mit.edu/talks/Talks/</link><pubDate>Wed, 29 Mar 2023 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/talks/Talks/</guid><description>Tech Talks Supercomputing (SC) 2022, Scalable Automatic Differentiation of Multiple Parallel Paradigms through Compiler Augmentation ; William S. Moses, Sri Hari Krishna Narayanan, Ludger Paehler, Valentin Churavy, Jan Hueckelheim, Michel Schanen, Johannes Doerfert, and Paul Hovland; video 2nd MODE Workshop on Differentiable Programming for Experiment Design 2022, Synthesization of Fast Gradients with Enzyme ; William S. Moses, Ludger Paehler, Tim Gymnich, and Valentin Churavy; slides ICPP Workshop on LLVM in Parallel Processing (LLPP) 2022, Enzyme: Automatic Differentiation of Parallel Programs ; William S.</description></item><item><title>Related Publications</title><link>https://enzyme.mit.edu/talks/Publications/</link><pubDate>Wed, 29 Mar 2023 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/talks/Publications/</guid><description>Papers SC 22, Scalable Automatic Differentiation of Multiple Parallel Paradigms through Compiler Augmentation ; William S. Moses, Sri Hari Krishna Narayanan, Ludger Paehler, Valentin Churavy, Michel Schanen, Jan Hueckelheim, Johannes Doerfert, and Paul Hovland. Best Student Paper SC 21, Reverse-Mode Automatic Differentiation and Optimization of GPU Kernels via Enzyme ; William S. Moses, Valentin Churavy, Ludger Paehler, Jan Hückelheim, Sri Hari Krishna Narayanan, Michel Schanen, and Johannes Doerfert. NeurIPS 2020, Instead of Rewriting Foreign Code for Machine Learning, Automatically Synthesize Fast Gradients ; William S.</description></item><item><title>Calling Convention</title><link>https://enzyme.mit.edu/getting_started/CallingConvention/</link><pubDate>Fri, 29 Nov 2019 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CallingConvention/</guid><description>Enzyme is invoked by calling a function __enzyme_autodiff with the function being differentiated, followed by the corresponding primal and shadow arguments. This will result in the original function being run with the corresponding derivative values being computed.
Function Hooks Enzyme replaces all calls to functions that contain the string __enzyme_autodiff with a call to the corresponding derivative. This is done to allow Enzyme to register multiple function signatures.
#include &amp;lt;stdio.h&amp;gt;template&amp;lt;typename T&amp;gt; T square(T x) { return x * x; } float __enzyme_autodiffFloat(float (*)(float), float); double __enzyme_autodiffDouble(double (*)(double), double); int main() { printf(&amp;#34;float d/dx %f\n&amp;#34;, __enzyme_autodiffFloat(square&amp;lt;float&amp;gt;, 1.</description></item><item><title>C++ Examples</title><link>https://enzyme.mit.edu/getting_started/Examples/</link><pubDate>Tue, 25 Jul 2023 00:00:00 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/Examples/</guid><description>There are many ways to implement a given calculation. This document contains examples of how to apply Enzyme to different kinds of patterns that show up frequently in C++. To make the code snippets below more concise, we&amp;rsquo;ll assume that each example snippet has the following definitions prepended to the translation unit:
int enzyme_dup; int enzyme_dupnoneed; int enzyme_out; int enzyme_const; template &amp;lt; typename return_type, typename ... T &amp;gt; return_type __enzyme_fwddiff(void*, T .</description></item><item><title>Enzyme Conference 2023</title><link>https://enzyme.mit.edu/talks/EnzymeCon/</link><pubDate>Wed, 29 Mar 2023 15:26:15 +0000</pubDate><guid>https://enzyme.mit.edu/talks/EnzymeCon/</guid><description>About The first Enzyme workshop took place from February 22-24 in Boulder, Co. The workshop&amp;rsquo;s aim was to bring together the contributors and users of Enzyme in particular, and people interested in automatic differentiation within the LLVM infrastructure in general, for two days of fast-paced high-bandwidth idea exchange and collaboration bootstrapping. For this the workshop was designed to have a flexible format, friendly to practitioners and researchers alike; its program consisted of a mix of presentations, tutorials, roundtable discussions and live programming sessions.</description></item><item><title>CUDA Guide</title><link>https://enzyme.mit.edu/getting_started/CUDAGuide/</link><pubDate>Wed, 20 Jan 2021 00:00:00 +0000</pubDate><guid>https://enzyme.mit.edu/getting_started/CUDAGuide/</guid><description>Reference C++ example WARNING: CUDA support is highly experimental and in active development.
Expand Down

0 comments on commit e479462

Please sign in to comment.