CUDA Device Management
=======================

.. raw:: html

    <p>For multi-GPU machines, users may want to select which GPU to use.
    By default the CUDA driver selects the fastest GPU as the device 0,
    which is the default device used by NumbaPro.</p>
    <p>The features introduced on this page are generally not of interest
    unless working with systems hosting/offering more than one
    CUDA-capable GPU.</p>
    <div class="section" id="device-selection">
    <h2>Device Selection<a class="headerlink" href="#device-selection" title="Permalink to this headline">¶</a></h2>
    <p>Device selection must be done before any CUDA feature is used.</p>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">numbapro</span> <span class="kn">import</span> <span class="n">cuda</span>
    <span class="n">cuda</span><span class="o">.</span><span class="n">select_device</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
    </pre></div>
    </div>
    <p>The device can be closed by:</p>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cuda</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
    </pre></div>
    </div>
    <p>Users can then create a new context with another device.</p>
    <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">cuda</span><span class="o">.</span><span class="n">select_device</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># assuming we have 2 GPUs</span>
    </pre></div>
    </div>
    <div class="admonition note">
    <p class="first admonition-title">Note</p>
    <p class="last">Compiled functions are associated with the CUDA context.
    This makes it not very useful to close and create new devices,
    though it is certainly useful for choosing which device to use when the machine
    has multiple GPUs.</p>
