Skip to content

Commit

Permalink
build based on 0d50f05
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Aug 27, 2024
1 parent e1aed4c commit 7d19623
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 66 deletions.
2 changes: 1 addition & 1 deletion previews/PR653/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-27T13:37:14","documenter_version":"1.5.0"}}
{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-27T13:55:01","documenter_version":"1.6.0"}}
53 changes: 29 additions & 24 deletions previews/PR653/assets/documenter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions previews/PR653/config/index.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions previews/PR653/generated-plugin-api/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Dispatch Analysis · JET.jl</title><meta name="title" content="Dispatch Analysis · JET.jl"/><meta property="og:title" content="Dispatch Analysis · JET.jl"/><meta property="twitter:title" content="Dispatch Analysis · JET.jl"/><meta name="description" content="Documentation for JET.jl."/><meta property="og:description" content="Documentation for JET.jl."/><meta property="twitter:description" content="Documentation for JET.jl."/><script data-outdated-warner src="../../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="../.."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../../assets/documenter.js"></script><script src="../../search_index.js"></script><script src="../../siteinfo.js"></script><script src="../../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-mocha.css" data-theme-name="catppuccin-mocha"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-macchiato.css" data-theme-name="catppuccin-macchiato"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-frappe.css" data-theme-name="catppuccin-frappe"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/catppuccin-latte.css" data-theme-name="catppuccin-latte"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../../">JET.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../../">README</a></li><li><a class="tocitem" href="../../tutorial/">Tutorial</a></li><li><span class="tocitem">Analyses</span><ul><li><a class="tocitem" href="../../jetanalysis/">Error Analysis</a></li><li><a class="tocitem" href="../../optanalysis/">Optimization Analysis</a></li></ul></li><li><a class="tocitem" href="../../config/">Configurations</a></li><li><a class="tocitem" href="../../internals/">Internals</a></li><li><span class="tocitem"><code>AbstractAnalyzer</code> Framework</span><ul><li><a class="tocitem" href="../../generated-plugin-api/">API</a></li><li><input class="collapse-toggle" id="menuitem-6-2" type="checkbox" checked/><label class="tocitem" for="menuitem-6-2"><span class="docs-label">Examples</span><i class="docs-chevron"></i></label><ul class="collapsed"><li class="is-active"><a class="tocitem" href>Dispatch Analysis</a><ul class="internal"><li><a class="tocitem" href="#Motivation"><span>Motivation</span></a></li><li><a class="tocitem" href="#Implementation"><span>Implementation</span></a></li><li><a class="tocitem" href="#Usages"><span>Usages</span></a></li></ul></li><li><a class="tocitem" href="../find_unstable_api/">&quot;Unstable API&quot; Analysis</a></li></ul></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled"><code>AbstractAnalyzer</code> Framework</a></li><li><a class="is-disabled">Examples</a></li><li class="is-active"><a href>Dispatch Analysis</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Dispatch Analysis</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/aviatesk/JET.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/aviatesk/JET.jl/blob/master/examples/dispatch_analysis.jl" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Dispatch-Analysis"><a class="docs-heading-anchor" href="#Dispatch-Analysis">Dispatch Analysis</a><a id="Dispatch-Analysis-1"></a><a class="docs-heading-anchor-permalink" href="#Dispatch-Analysis" title="Permalink"></a></h1><h2 id="Motivation"><a class="docs-heading-anchor" href="#Motivation">Motivation</a><a id="Motivation-1"></a><a class="docs-heading-anchor-permalink" href="#Motivation" title="Permalink"></a></h2><p>When Julia compiles your code and type inference on it was not so successful, the compiler is likely to be unable to determine which method should be called at each generic function callsite, and then it will be looked up at runtime. That is called &quot;runtime dispatch&quot;, which is known as a common source of performance problem – the compiler can&#39;t do various kinds of optimizations including inlining when it can&#39;t determine a single matching method, and method lookup itself can also be a bottleneck if the call happens many times.</p><p>In order to avoid this problem, we usually use <code>code_typed</code>, inspect its output, and check if there is anywhere type is not well inferred (i.e. where is &quot;type-instable&quot;) and optimization was not successful. But the problem is that <code>code_typed</code> can only present the &quot;final&quot; output of inference or optimization, and we can&#39;t inspect an entire call graph and <em>may</em> not be able to find where a problem happened and how the &quot;type instability&quot; has been propagated.</p><p>There is a nice package called <a href="https://github.com/JuliaDebug/Cthulhu.jl">Cthulhu.jl</a>, which allows us to inspect the output of <code>code_typed</code> by <em>descending</em> into a call tree, recursively and interactively. The workflow with Cthulhu is much more powerful, but still, it&#39;s tedious.</p><p>So, why not automate it ? We can use JET&#39;s pluggable analysis framework and create such an analyzer that automatically analyzes your code and alarms you when it detects anywhere Julia can&#39;t determine matching method statically and thus runtime dispatch will happen at runtime.</p><h2 id="Implementation"><a class="docs-heading-anchor" href="#Implementation">Implementation</a><a id="Implementation-1"></a><a class="docs-heading-anchor-permalink" href="#Implementation" title="Permalink"></a></h2><p>In this analysis, the analyzer will be designed to detect:</p><ol><li>where Julia compiler gives up optimization</li><li>where a runtime dispatch will happen</li></ol><p>The case 1. will happen when there are (mutually) recursive calls and Julia compiler decided not to do inference in order to make sure the inference&#39;s termination. In such a case, optimization won&#39;t happen and method dispatches aren&#39;t resolved statically, so we will just report it (as <code>OptimizationFailureReport</code>). In order to detect the case 2., we will inspect the optimized IR and look for <code>:call</code> expressions. <code>:call</code> expressions are such calls that were not resolved statically and will be dispatched at runtime (as opposed to <a href="https://docs.julialang.org/en/v1/devdocs/ast/#Expr-types"><code>:invoke</code></a> expressions, that represent staticall resolved generic function calls).</p><p>We will define <code>DispatchAnalyzer &lt;: AbstractAnalyzer</code>, and overload some of <code>Core.Compiler</code> methods with it:</p><ul><li><code>Core.Compiler.finish(frame::CC.InferenceState, analyzer::DispatchAnalyzer)</code> to check if optimization will happen or not (the case 1.)</li><li><code>Core.Compiler.finish!(analyzer::DispatchAnalyzer, caller::CC.InferenceResult)</code> to inspect an optimized IR (the case 2.)</li></ul><pre><code class="language-julia hljs">using JET.JETInterface
const CC = Core.Compiler
import JET: JET
using JET: JET

struct DispatchAnalyzer{T} &lt;: AbstractAnalyzer
state::AnalyzerState
Expand Down Expand Up @@ -210,4 +210,4 @@
<span class="sgr91"></span><span class="sgr1">compute(</span><span class="sgr90">x</span>::Int64<span class="sgr1">)</span> <span class="sgr91">@ Main ./timing.jl:286</span>
<span class="sgr91">│ runtime dispatch detected: </span><span class="sgr1">Core.kwcall([quote]<span class="sgr96">::@NamedTuple{msg::Nothing}</span>, Base.time_print, %104<span class="sgr96">::IO</span>, %61<span class="sgr96">::UInt64</span>, %85<span class="sgr96">::Int64</span>, %100<span class="sgr96">::Int64</span>, %103<span class="sgr96">::Int64</span>, %66<span class="sgr96">::UInt64</span>, %68<span class="sgr96">::UInt64</span>, true)<span class="sgr96">::Any</span></span>
<span class="sgr91">└────────────────────</span>
</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../../generated-plugin-api/">« API</a><a class="docs-footer-nextpage" href="../find_unstable_api/">&quot;Unstable API&quot; Analysis »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.5.0 on <span class="colophon-date" title="Tuesday 27 August 2024 13:37">Tuesday 27 August 2024</span>. Using Julia version 1.10.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../../generated-plugin-api/">« API</a><a class="docs-footer-nextpage" href="../find_unstable_api/">&quot;Unstable API&quot; Analysis »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.6.0 on <span class="colophon-date" title="Tuesday 27 August 2024 13:55">Tuesday 27 August 2024</span>. Using Julia version 1.10.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 7d19623

Please sign in to comment.