struct.BufferBuilder.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `BufferBuilder` struct in crate `ocl`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, BufferBuilder">
  9. <title>ocl::builders::BufferBuilder - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle">
  14. <script src="../../storage.js"></script>
  15. </head>
  16. <body class="rustdoc struct">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Struct BufferBuilder</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.context">context</a><a href="#method.queue">queue</a><a href="#method.flags">flags</a><a href="#method.use_host_slice">use_host_slice</a><a href="#method.copy_host_slice">copy_host_slice</a><a href="#method.len">len</a><a href="#method.fill_val">fill_val</a><a href="#method.fill_event">fill_event</a><a href="#method.build">build</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Debug">Debug</a></div></div><p class='location'><a href='../index.html'>ocl</a>::<wbr><a href='index.html'>builders</a></p><script>window.sidebarCurrent = {name: 'BufferBuilder', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>ocl</a>::<wbr><a href='index.html'>builders</a>::<wbr><a class="struct" href=''>BufferBuilder</a></span><span class='out-of-band'><span id='render-detail'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2137-2143' title='goto source code'>[src]</a></span></h1>
  50. <pre class='rust struct'><div class="docblock attributes">#[must_use = "builders do nothing unless \'::build\' is called"]
  51. </div>pub struct BufferBuilder&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../ocl/traits/trait.OclPrm.html" title="trait ocl::traits::OclPrm">OclPrm</a>,&nbsp;</span> { /* fields omitted */ }</pre><div class='docblock'><p>A buffer builder.</p>
  52. </div>
  53. <h2 id='methods' class='small-section-header'>
  54. Methods<a href='#methods' class='anchor'></a>
  55. </h2>
  56. <h3 id='impl' class='impl'><span class='in-band'><code>impl&lt;'a, T&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'a + <a class="trait" href="../../ocl/traits/trait.OclPrm.html" title="trait ocl::traits::OclPrm">OclPrm</a>,&nbsp;</span></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2145-2415' title='goto source code'>[src]</a></span></h3>
  57. <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2147-2155' title='goto source code'>[src]</a></span></h4>
  58. <div class='docblock'><p>Returns a new buffer builder.</p>
  59. </div><h4 id='method.context' class="method"><span id='context.v' class='invisible'><code>pub fn <a href='#method.context' class='fnname'>context</a>&lt;'o&gt;(self, context: &amp;'o <a class="struct" href="../../ocl/struct.Context.html" title="struct ocl::Context">Context</a>) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;'o: 'a,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2162-2167' title='goto source code'>[src]</a></span></h4>
  60. <div class='docblock'><p>Sets the context with which to associate the buffer.</p>
  61. <p>May not be used in conjunction with <a href="builders/struct.BufferBuilder.html#method.queue"><code>::queue</code></a> (use one or the other).</p>
  62. </div><h4 id='method.queue' class="method"><span id='queue.v' class='invisible'><code>pub fn <a href='#method.queue' class='fnname'>queue</a>&lt;'b&gt;(self, default_queue: <a class="struct" href="../../ocl/struct.Queue.html" title="struct ocl::Queue">Queue</a>) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2192-2196' title='goto source code'>[src]</a></span></h4>
  63. <div class='docblock'><p>Specifies the default queue used to be used by the buffer for all
  64. command enqueue operations (reads, writes, etc.).</p>
  65. <p>The default queue is the queue which will be used when enqueuing
  66. commands if no queue is specified.</p>
  67. <p>Without a default queue:</p>
  68. <div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
  69. <span class="ident">buffer</span>.<span class="ident">read</span>(<span class="ident">data</span>).<span class="ident">queue</span>(<span class="kw-2">&amp;</span><span class="ident">queue</span>).<span class="ident">enq</span>()<span class="question-mark">?</span>;</pre>
  70. <p>With a default queue:</p>
  71. <div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
  72. <span class="ident">buffer</span>.<span class="ident">read</span>(<span class="ident">data</span>).<span class="ident">enq</span>()<span class="question-mark">?</span>;</pre>
  73. <p>If this is set, the context associated with the <code>default_queue</code> will
  74. be used when creating the buffer. Attempting to specify the context
  75. separately (by calling <a href="builders/struct.BufferBuilder.html#method.context"><code>::context</code></a>) will cause a panic.</p>
  76. </div><h4 id='method.flags' class="method"><span id='flags.v' class='invisible'><code>pub fn <a href='#method.flags' class='fnname'>flags</a>&lt;'b&gt;(self, flags: <a class="struct" href="../../ocl/flags/struct.MemFlags.html" title="struct ocl::flags::MemFlags">MemFlags</a>) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2212-2218' title='goto source code'>[src]</a></span></h4>
  77. <div class='docblock'><p>Sets the flags used when creating the buffer.</p>
  78. <p>Defaults to <code>flags::MEM_READ_WRITE</code> aka.
  79. <code>MemFlags::new().read_write()</code> if this is not set. See the <a href="https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateBuffer.html">SDK Docs</a>
  80. for more information about flags. Note that the names of all flags in
  81. this library have the <code>CL_</code> prefix removed for brevity.</p>
  82. <h3 id="panics" class="section-header"><a href="#panics">Panics</a></h3>
  83. <p>Due to its unsafety, setting the
  84. <code>MEM_USE_HOST_PTR</code>/<code>MemFlags::new()::use_host_ptr()</code> flag will cause a
  85. panic. Use the <code>::use_host_slice</code> method instead.</p>
  86. </div><h4 id='method.use_host_slice' class="method"><span id='use_host_slice.v' class='invisible'><code>pub unsafe fn <a href='#method.use_host_slice' class='fnname'>use_host_slice</a>&lt;'d&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;host_slice: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'d [T]</a><br>) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;'d: 'a,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2249-2255' title='goto source code'>[src]</a></span></h4>
  87. <div class='docblock'><p>Specifies a region of host memory to use as storage for the buffer.</p>
  88. <p>OpenCL implementations are allowed to cache the buffer contents
  89. pointed to by <code>host_slice</code> in device memory. This cached copy can be
  90. used when kernels are executed on a device.</p>
  91. <p>The result of OpenCL commands that operate on multiple buffer objects
  92. created with the same <code>host_slice</code> or overlapping host regions is
  93. considered to be undefined</p>
  94. <p>Refer to the <a href="https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/dataTypes.html">description of the alignment</a> rules for
  95. <code>host_slice</code> for memory objects (buffer and images) created using
  96. this method.</p>
  97. <p>Automatically sets the <code>flags::MEM_USE_HOST_PTR</code> aka.
  98. <code>MemFlags::new().use_host_ptr()</code> flag.</p>
  99. <h3 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h3>
  100. <p><code>::copy_host_slice</code> or <code>::use_host_slice</code> must not have already been
  101. called.</p>
  102. <h3 id="safety" class="section-header"><a href="#safety">Safety</a></h3>
  103. <p>The caller must ensure that <code>host_slice</code> lives until the buffer is
  104. destroyed. The caller must also ensure that only one buffer uses
  105. <code>host_slice</code> and that it is not tampered with inappropriately.</p>
  106. </div><h4 id='method.copy_host_slice' class="method"><span id='copy_host_slice.v' class='invisible'><code>pub fn <a href='#method.copy_host_slice' class='fnname'>copy_host_slice</a>&lt;'d&gt;(self, host_slice: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'d [T]</a>) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;'d: 'a,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2267-2273' title='goto source code'>[src]</a></span></h4>
  107. <div class='docblock'><p>Specifies a region of memory to copy into the buffer upon creation.</p>
  108. <p>Automatically sets the <code>flags::MEM_COPY_HOST_PTR</code> aka.
  109. <code>MemFlags::new().copy_host_ptr()</code> flag.</p>
  110. <h3 id="panics-2" class="section-header"><a href="#panics-2">Panics</a></h3>
  111. <p><code>::copy_host_slice</code> or <code>::use_host_slice</code> must not have already been
  112. called.</p>
  113. </div><h4 id='method.len' class="method"><span id='len.v' class='invisible'><code>pub fn <a href='#method.len' class='fnname'>len</a>&lt;'b, D&gt;(self, len: D) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="enum" href="../../ocl/enum.SpatialDims.html" title="enum ocl::SpatialDims">SpatialDims</a>&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2281-2285' title='goto source code'>[src]</a></span></h4>
  114. <div class='docblock'><p>Sets the length for this buffer.</p>
  115. <p>Note that although sizes in the standard OpenCL API are expressed in
  116. bytes, sizes, lengths, and dimensions in this library are always
  117. specified in <code>bytes / sizeof(T)</code> (like everything else in Rust) unless
  118. otherwise noted.</p>
  119. </div><h4 id='method.fill_val' class="method"><span id='fill_val.v' class='invisible'><code>pub fn <a href='#method.fill_val' class='fnname'>fill_val</a>(self, fill_val: T) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2306-2309' title='goto source code'>[src]</a></span></h4>
  120. <div class='docblock'><p>Allows the caller to automatically fill the buffer with a value (such
  121. as zero) immediately after creation.</p>
  122. <p>Use <a href="builders/struct.BufferBuilder.html#method.fill_event"><code>::fill_event</code></a> to set an event associated with the completion of
  123. the fill command if you want it to execute asynchronously (it will
  124. otherwise block the calling thread).</p>
  125. <p>Platforms that have trouble with <code>clEnqueueFillBuffer</code> such as
  126. <a href="http://portablecl.org/">pocl</a> should not use this option and should
  127. handle initializing buffers manually (using a kernel or copy host data
  128. flag).</p>
  129. <h3 id="examples" class="section-header"><a href="#examples">Examples</a></h3>
  130. <ul>
  131. <li>TODO: Provide examples once this stabilizes.</li>
  132. </ul>
  133. <p>[UNSTABLE]: May be changed or removed.</p>
  134. </div><h4 id='method.fill_event' class="method"><span id='fill_event.v' class='invisible'><code>pub fn <a href='#method.fill_event' class='fnname'>fill_event</a>&lt;'b, 'e, En&gt;(self, enew: En) -&gt; <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;'e: 'a,<br>&nbsp;&nbsp;&nbsp;&nbsp;En: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="enum" href="../../ocl/builders/enum.ClNullEventPtrEnum.html" title="enum ocl::builders::ClNullEventPtrEnum">ClNullEventPtrEnum</a>&lt;'e&gt;&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2326-2334' title='goto source code'>[src]</a></span></h4>
  135. <div class='docblock'><p>Specifies the (empty) event to use for association with the completion
  136. of the fill command.</p>
  137. <p><code>enew</code> specifies an empty event (generally a <code>&amp;mut Event</code>) to be
  138. associated with the fill command which will be enqueued after creation
  139. and just before returning the new buffer. It is up to the caller to
  140. ensure that the command has completed before performing any other
  141. operations on the buffer. Failure to do so may cause the fill command
  142. to run <strong>after</strong> subsequently queued commands if multiple or
  143. out-of-order queues are being used.</p>
  144. <p>Not calling this method at all will cause the fill command to block
  145. before returning the new buffer and is the safe option if you don't
  146. want to worry about it.</p>
  147. </div><h4 id='method.build' class="method"><span id='build.v' class='invisible'><code>pub fn <a href='#method.build' class='fnname'>build</a>(self) -&gt; <a class="type" href="../../ocl/error/type.Result.html" title="type ocl::error::Result">OclResult</a>&lt;<a class="struct" href="../../ocl/struct.Buffer.html" title="struct ocl::Buffer">Buffer</a>&lt;T&gt;&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2340-2414' title='goto source code'>[src]</a></span></h4>
  148. <div class='docblock'><p>Creates a buffer and returns it.</p>
  149. <p>Dimensions and either a context or default queue must be specified
  150. before calling <code>::build</code>.</p>
  151. </div></div>
  152. <h2 id='implementations' class='small-section-header'>
  153. Trait Implementations<a href='#implementations' class='anchor'></a>
  154. </h2>
  155. <h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl&lt;'a, T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../ocl/builders/struct.BufferBuilder.html" title="struct ocl::builders::BufferBuilder">BufferBuilder</a>&lt;'a, T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../ocl/traits/trait.OclPrm.html" title="trait ocl::traits::OclPrm">OclPrm</a>,&nbsp;</span></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2136' title='goto source code'>[src]</a></span></h3>
  156. <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, __arg_0: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/ocl/standard/buffer.rs.html#2136' title='goto source code'>[src]</a></span></h4>
  157. <div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
  158. </div></div></section>
  159. <section id='search' class="content hidden"></section>
  160. <section class="footer"></section>
  161. <aside id="help" class="hidden">
  162. <div>
  163. <h1 class="hidden">Help</h1>
  164. <div class="shortcuts">
  165. <h2>Keyboard Shortcuts</h2>
  166. <dl>
  167. <dt><kbd>?</kbd></dt>
  168. <dd>Show this help dialog</dd>
  169. <dt><kbd>S</kbd></dt>
  170. <dd>Focus the search field</dd>
  171. <dt><kbd>↑</kbd></dt>
  172. <dd>Move up in search results</dd>
  173. <dt><kbd>↓</kbd></dt>
  174. <dd>Move down in search results</dd>
  175. <dt><kbd>↹</kbd></dt>
  176. <dd>Switch tab</dd>
  177. <dt><kbd>&#9166;</kbd></dt>
  178. <dd>Go to active search result</dd>
  179. <dt><kbd>+</kbd></dt>
  180. <dd>Expand all sections</dd>
  181. <dt><kbd>-</kbd></dt>
  182. <dd>Collapse all sections</dd>
  183. </dl>
  184. </div>
  185. <div class="infos">
  186. <h2>Search Tricks</h2>
  187. <p>
  188. Prefix searches with a type followed by a colon (e.g.
  189. <code>fn:</code>) to restrict the search to a given type.
  190. </p>
  191. <p>
  192. Accepted types are: <code>fn</code>, <code>mod</code>,
  193. <code>struct</code>, <code>enum</code>,
  194. <code>trait</code>, <code>type</code>, <code>macro</code>,
  195. and <code>const</code>.
  196. </p>
  197. <p>
  198. Search functions by type signature (e.g.
  199. <code>vec -> usize</code> or <code>* -> vec</code>)
  200. </p>
  201. </div>
  202. </div>
  203. </aside>
  204. <script>
  205. window.rootPath = "../../";
  206. window.currentCrate = "ocl";
  207. </script>
  208. <script src="../../main.js"></script>
  209. <script defer src="../../search-index.js"></script>
  210. </body>
  211. </html>