-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Sep 25, 2023
1 parent
f5602f9
commit bd25790
Showing
23 changed files
with
16,341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Array programming · Metal.jl</title><script data-outdated-warner src="../../assets/warner.js"></script><link rel="canonical" href="https://metal.juliagpu.org/stable/api/array/"/><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.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/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="../../siteinfo.js"></script><script src="../../../versions.js"></script><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><link href="../../assets/favicon.ico" rel="icon" type="image/x-icon"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../"><img src="../../assets/logo.png" alt="Metal.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../../">Metal.jl</a></span></div><form class="docs-search" action="../../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../../">Home</a></li><li><span class="tocitem">Usage</span><ul><li><a class="tocitem" href="../../usage/overview/">Overview</a></li><li><a class="tocitem" href="../../usage/array/">Array programming</a></li><li><a class="tocitem" href="../../usage/kernel/">Kernel programming</a></li></ul></li><li><a class="tocitem" href="../../profiling/">Profiling</a></li><li><span class="tocitem">API reference</span><ul><li><a class="tocitem" href="../essentials/">Essentials</a></li><li><a class="tocitem" href="../compiler/">Compiler</a></li><li><a class="tocitem" href="../kernel/">Kernel programming</a></li><li class="is-active"><a class="tocitem" href>Array programming</a></li><li><a class="tocitem" href="../mps/">Metal Performance Shaders</a></li></ul></li><li><span class="tocitem">FAQ</span><ul><li><a class="tocitem" href="../../faq/faq/">Frequently Asked Questions</a></li><li><a class="tocitem" href="../../faq/contributing/">Contributing</a></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"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">API reference</a></li><li class="is-active"><a href>Array programming</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Array programming</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/JuliaGPU/Metal.jl/blob/main/docs/src/api/array.md#" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Array-programming"><a class="docs-heading-anchor" href="#Array-programming">Array programming</a><a id="Array-programming-1"></a><a class="docs-heading-anchor-permalink" href="#Array-programming" title="Permalink"></a></h1><p>The Metal array type, <code>MtlArray</code>, generally implements the Base array interface and all of its expected methods.</p><p>However, there is the special function <code>mtl</code> for transferring an array over to the gpu. For compatibility reasons, it will automatically convert arrays of <code>Float64</code> to <code>Float32</code>.</p><article class="docstring"><header><a class="docstring-binding" id="Metal.mtl" href="#Metal.mtl"><code>Metal.mtl</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">mtl(A; storage=Private)</code></pre><p><code>storage</code> can be <code>Private</code> (default) or <code>Shared</code>.</p><p>Opinionated GPU array adaptor, which may alter the element type <code>T</code> of arrays:</p><ul><li>For <code>T<:AbstractFloat</code>, it makes a <code>MtlArray{Float32}</code> for performance and compatibility reasons (except for <code>Float16</code>).</li><li>For <code>T<:Complex{<:AbstractFloat}</code> it makes a <code>MtlArray{ComplexF32}</code>.</li><li>For other <code>isbitstype(T)</code>, it makes a <code>MtlArray{T}</code>.</li></ul><p>By contrast, <code>MtlArray(A)</code> never changes the element type.</p><p>Uses Adapt.jl to act inside some wrapper structs.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> mtl(ones(3)') | ||
1×3 adjoint(::MtlVector{Float32, Metal.MTL.MTLResourceStorageModePrivate}) with eltype Float32: | ||
1.0 1.0 1.0 | ||
|
||
julia> mtl(zeros(1,3); storage=Shared) | ||
1×3 MtlMatrix{Float32, Metal.MTL.MTLResourceCPUCacheModeDefaultCache}: | ||
0.0 0.0 0.0 | ||
|
||
julia> mtl(1:3) | ||
1:3 | ||
|
||
julia> MtlArray(1:3) | ||
3-element MtlVector{Int64, Metal.MTL.MTLResourceStorageModePrivate}: | ||
1 | ||
2 | ||
3 | ||
|
||
julia> mtl[1,2,3] | ||
3-element MtlVector{Int64, Metal.MTL.MTLResourceStorageModePrivate}: | ||
1 | ||
2 | ||
3</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaGPU/Metal.jl/blob/8696f2c9117f3638c9d454b51a16a085732344c1/src/array.jl#L339-L380">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../kernel/">« Kernel programming</a><a class="docs-footer-nextpage" href="../mps/">Metal Performance Shaders »</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="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.23 on <span class="colophon-date" title="Sunday 24 September 2023 20:54">Sunday 24 September 2023</span>. Using Julia version 1.8.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Compiler · Metal.jl</title><script data-outdated-warner src="../../assets/warner.js"></script><link rel="canonical" href="https://metal.juliagpu.org/stable/api/compiler/"/><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.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/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="../../siteinfo.js"></script><script src="../../../versions.js"></script><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><link href="../../assets/favicon.ico" rel="icon" type="image/x-icon"/></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="../../"><img src="../../assets/logo.png" alt="Metal.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="../../">Metal.jl</a></span></div><form class="docs-search" action="../../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../../">Home</a></li><li><span class="tocitem">Usage</span><ul><li><a class="tocitem" href="../../usage/overview/">Overview</a></li><li><a class="tocitem" href="../../usage/array/">Array programming</a></li><li><a class="tocitem" href="../../usage/kernel/">Kernel programming</a></li></ul></li><li><a class="tocitem" href="../../profiling/">Profiling</a></li><li><span class="tocitem">API reference</span><ul><li><a class="tocitem" href="../essentials/">Essentials</a></li><li class="is-active"><a class="tocitem" href>Compiler</a><ul class="internal"><li><a class="tocitem" href="#Execution"><span>Execution</span></a></li><li><a class="tocitem" href="#Reflection"><span>Reflection</span></a></li></ul></li><li><a class="tocitem" href="../kernel/">Kernel programming</a></li><li><a class="tocitem" href="../array/">Array programming</a></li><li><a class="tocitem" href="../mps/">Metal Performance Shaders</a></li></ul></li><li><span class="tocitem">FAQ</span><ul><li><a class="tocitem" href="../../faq/faq/">Frequently Asked Questions</a></li><li><a class="tocitem" href="../../faq/contributing/">Contributing</a></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"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">API reference</a></li><li class="is-active"><a href>Compiler</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Compiler</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/JuliaGPU/Metal.jl/blob/main/docs/src/api/compiler.md#" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Compiler"><a class="docs-heading-anchor" href="#Compiler">Compiler</a><a id="Compiler-1"></a><a class="docs-heading-anchor-permalink" href="#Compiler" title="Permalink"></a></h1><h2 id="Execution"><a class="docs-heading-anchor" href="#Execution">Execution</a><a id="Execution-1"></a><a class="docs-heading-anchor-permalink" href="#Execution" title="Permalink"></a></h2><p>The main entry-point to the compiler is the <code>@metal</code> macro:</p><article class="docstring"><header><a class="docstring-binding" id="Metal.@metal" href="#Metal.@metal"><code>Metal.@metal</code></a> — <span class="docstring-category">Macro</span></header><section><div><pre><code class="language-julia hljs">@metal threads=... groups=... [kwargs...] func(args...)</code></pre><p>High-level interface for executing code on a GPU.</p><p>The <code>@metal</code> macro should prefix a call, with <code>func</code> a callable function or object that should return nothing. It will be compiled to a Metal function upon first use, and to a certain extent arguments will be converted and managed automatically using <code>mtlconvert</code>. Finally, a call to <code>mtlcall</code> is performed, creating a command buffer in the current global command queue then committing it.</p><p>There is one supported keyword argument that influences the behavior of <code>@metal</code>:</p><ul><li><code>launch</code>: whether to launch this kernel, defaults to <code>true</code>. If <code>false</code> the returned kernel object should be launched by calling it and passing arguments again.</li><li><code>name</code>: the name of the kernel in the generated code. Defaults to an automatically- generated name.</li><li><code>queue</code>: the command queue to use for this kernel. Defaults to the global command queue.</li></ul></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaGPU/Metal.jl/blob/8696f2c9117f3638c9d454b51a16a085732344c1/src/compiler/execution.jl#L10-L28">source</a></section></article><p>If needed, you can use a lower-level API that lets you inspect the compiler kernel:</p><article class="docstring"><header><a class="docstring-binding" id="Metal.mtlconvert" href="#Metal.mtlconvert"><code>Metal.mtlconvert</code></a> — <span class="docstring-category">Function</span></header><section><div><p>mtlconvert(x, [cce])</p><p>This function is called for every argument to be passed to a kernel, allowing it to be converted to a GPU-friendly format. By default, the function does nothing and returns the input object <code>x</code> as-is.</p><p>Do not add methods to this function, but instead extend the underlying Adapt.jl package and register methods for the the <code>Metal.Adaptor</code> type.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaGPU/Metal.jl/blob/8696f2c9117f3638c9d454b51a16a085732344c1/src/compiler/execution.jl#L123-L132">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Metal.mtlfunction" href="#Metal.mtlfunction"><code>Metal.mtlfunction</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">mtlfunction(f, tt=Tuple{}; kwargs...)</code></pre><p>Low-level interface to compile a function invocation for the currently-active GPU, returning a callable kernel object. For a higher-level interface, use <a href="#Metal.@metal"><code>@metal</code></a>.</p><p>The output of this function is automatically cached, i.e. you can simply call <code>mtlfunction</code> in a hot path without degrading performance. New code will be generated automatically when the function changes, or when different types or keyword arguments are provided.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaGPU/Metal.jl/blob/8696f2c9117f3638c9d454b51a16a085732344c1/src/compiler/execution.jl#L145-L154">source</a></section></article><h2 id="Reflection"><a class="docs-heading-anchor" href="#Reflection">Reflection</a><a id="Reflection-1"></a><a class="docs-heading-anchor-permalink" href="#Reflection" title="Permalink"></a></h2><p>If you want to inspect generated code, you can use macros that resemble functionality from the InteractiveUtils standard library:</p><pre><code class="nohighlight hljs">@device_code_lowered | ||
@device_code_typed | ||
@device_code_warntype | ||
@device_code_llvm | ||
@device_code_air | ||
@device_code_agx | ||
@device_code</code></pre><p>For more information, please consult the GPUCompiler.jl documentation. <code>code_air</code> is actually <code>code_native</code>:</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../essentials/">« Essentials</a><a class="docs-footer-nextpage" href="../kernel/">Kernel programming »</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="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.23 on <span class="colophon-date" title="Sunday 24 September 2023 20:54">Sunday 24 September 2023</span>. Using Julia version 1.8.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Oops, something went wrong.