==================
GPU Kernels |beta|
==================

In addition to Anaconda Notebook's :ref:`default environments <default_notebook_env>`, Anaconda provides access to remote GPU kernels powered by NVIDIA's A10 GPUs. These kernels are ideal for complex, compute-intensive workloads that would otherwise be too time consuming to run in a default environment. You can choose to run the entire notebook on GPU or apply GPU acceleration to specific cells. 

.. dropdown:: What is a GPU kernel?
	:animate: fade-in
	:color: primary

	Anaconda's GPU kernel runs a GPU-enabled environment called "anaconda-01 - nvidia-a10". This environment contains the libraries, drivers, and configurations necessary for communicating with NVIDIA GPUs, as well as the ``ipykernel`` package to enable interactive computing in Python. See below for a :ref:`list of all packages <using_gpu-kernels>` included in the default environment. 
	
	When you assign a GPU kernel to a notebook (or notebook cell), you're using the default GPU-enabled environment. For more information about kernels and environment, see :doc:`Environments <notebook-environments>`.
	
.. _paid_access:

.. note::

	At this time, Anaconda is offering free :ref:`credits <gpu_credits>` to select paid subscribers only. Free tier subscribers who would like to use GPU kernels can `upgrade <https://www.anaconda.com/pricing/?utm_campaign=pricing&utm_medium=documentation&utm_source=anacondadocs&utm_content=gpu>`_ to gain access.

Assigning GPU kernels
=====================

There are a few methods you can use to assign a GPU kernel to either an entire notebook or an individual cell:

.. tab-set::

    .. tab-item:: Launcher

		#. Open the Launcher.
		#. Under **Notebook**, click **Launch a Remote Kernel**.

			.. thumbnail:: /img/launcher_remote_kernel.png
				:align: center

		#. In the Launch a Kernel dialog, open the **Environment** dropdown and select a kernel.
		#. Use the slider or type a number in the text box to reserve time for the kernel session (in minutes). 
		#. Assign a name for your kernel or use the default kernel name.
		#. Click **Launch a Kernel**.

    .. tab-item:: Notebook

    	#. In an active notebook, click the kernel in the top right.
    	#. If you haven't launched a remote kernel yet, select *Connect to remote provider* and follow the steps in the Launcher tab. Otherwise, select the remote kernel (the default kernel name is "nvidia-a10").

    	    .. thumbnail:: /img/notebook_remote_kernel.png
      	        :align: center

      	#. In the Assign a Kernel dialog, make sure the remote kernel is selected in the dropdown.
      	#. Use the slider or type a number in the text box to reserve time for the kernel session (in minutes). 

		.. warning::

			Don't switch the Transfer variables toggle to **On**. Switching the toggle to **On** causes Notebooks to crash. This is a known issue that is currently being addressed.

      	#. Click **Assign**.

    .. tab-item:: Cell

    	#. In an active cell, click |kernel| **Assign a specific kernel to the cell**.
    	#. If you haven't launched a remote kernel yet, select *Connect to remote provider* and follow the steps in the Launcher tab. Otherwise, continue to the next step.

    	    .. thumbnail:: /img/notebook_cell_kernel.png
      	        :align: center

      	#. Click **Assign a Cell Kernel**.
      	#. Select the Environment and Kernel name.
      	#. Click **Assign from the Environment**.

      	A green bar appears beneath the cell, which indicates that the cell has successfully connected to the GPU kernel.

.. _using_gpu-kernels:

Using GPU kernels
=================

Once you assign a GPU kernel to a notebook or cell, you can run your code as you normally would. You should notice a considerable increase in processing speed, especially for more complex tasks. 

Anaconda's default GPU kernel, "anaconda-01 - nvidia-a10", is tied to a read-only GPU-enabled environment that includes the latest Anaconda, AI, and NVIDIA packages. 

.. dropdown:: Packages included in anaconda-01 - nvidia-a10
    :animate: fade-in 
    :color: primary 

    .. csv-table::
        :file: ../csv/nvidia-a10-kernel-packages.csv
        :header-rows: 1

.. _transfer_variables:

Transferring variables in GPU kernel cells
------------------------------------------

Because cells assigned a GPU kernel run in a separate environment from the rest of the notebook, variables must be transferred between the cell and the notebook to ensure they are accessible in both environments. 

Follow these steps to transfer variables: 

#. Click |transfer| **Variable transfer** beside a cell with a GPU kernel assigned.

	.. thumbnail:: /img/notebook_variable_transfer.png
		:align: center

#. Enter the inputs and/or outputs to be transferred between the notebook and cell environments.
#. Click **Set variables**.

The inputs and/or outputs can now be used in the GPU kernel cell and notebook.

Managing usage
--------------

When you assign a GPU kernel to a notebook, you are asked to reserve a defined number of minutes to use toward the notebook's GPU execution time. Reserved time is calculated in credits, with one credit equaling 100 real-world seconds. 

Once the notebook launches, the reserved time starts to count down. The reserved time continues to count down both when running code and when the notebook is idle. 

Track how much reserved time is left by hovering over the top-right countdown bar:

.. thumbnail:: /img/notebook_countdown_bar.png
    :align: center

.. caution::
    When your reserved time drops below five minutes (300 seconds), the countdown bar turns red. Once the reserved time hits zero, the GPU kernel session automatically terminates.

Anaconda recommends conserving your GPU usage by either assigning a GPU kernel to individual cells that require higher compute power rather than the entire notebook, or waiting to assign the GPU kernel until you're ready to run your code, and then stopping the GPU kernel session as soon as the code has executed.

There are multiple ways you can stop a GPU kernel session:

.. tab-set::

	.. tab-item:: Kernel menu

		#. Select **Kernels** from the top menu bar.
		#. Select **Shut Down All** to shut down all kernels.
		#. In the confirmation dialog, click **Shut Down All**.
	
	.. tab-item:: Jupyter kernels home page

		#. In a notebook with an assigned GPU kernel, click the top-right countdown bar.
		#. On the Jupyter Kernels page, click |trash| **Delete** next to the kernel you'd like to shut down.

Usage history
-------------

View your GPU usage stats and remaining credits by clicking the top-right |actions| actions dropdown on the Jupyter Kernels home page, then selecting `Usage`:

.. thumbnail:: /img/notebook_kernel_usage.png
    :align: center

* The **Overview** page shows your running GPU kernels, remaining credits, and historical credit consumption.

* The **History** page shows your usage history, including GPU session kernel names, types, start date, end date, credits used, and session duration. 

* The **Reservations** page shows any currently running GPU kernels, the credits assigned to the reservation session, and the reservation start and end times.


.. _gpu_credits:

Using credits
-------------

Anaconda offers credits to access GPU compute time. One credit equals 100 real-world seconds. Note that this is different from how :doc:`high-compute seconds <notebook-storage-memory>` are calculated for CPU use.

Credits are automatically deducted as reserved time is used. For example, if you use 10 minutes of reserved time, 6.00 credits will be deducted from your account. 

View your remaining credits on the Usage Overview page.

At this time, Anaconda is offering 500 free credits to select paid subscribers only. See :ref:`note <paid_access>` for details on upgrading your subscription to gain access.

Troubleshooting
===============

I ran out of credits
---------------------

To request additional GPU credits, `file a support ticket <https://support.anaconda.com/hc/en-us/requests/new?ticket_form_id=360000993773>`_.

The GPU kernel does not start up
---------------------------------

Reload the Anaconda Notebooks page and then click "Launch a Remote Kernel" from the Launcher. If you're still unable to run a GPU kernel, `file a support ticket <https://support.anaconda.com/hc/en-us/requests/new?ticket_form_id=360000993773>`_.

My code isn't running
----------------------

Check for missing import statements and verify that variables were correctly :ref:`transferred <transfer_variables>` to the GPU kernel.

.. |beta| raw:: html

    <svg class="inline" width="31" height="14" viewBox="0 0 31 14" xmlns="http://www.w3.org/2000/svg">
    <rect width="31" height="14" rx="3" fill="#6D5BF6"/>
    <path d="M6.88281 7.58203H5.41797L5.41016 6.68359H6.59766C6.8112 6.68359 6.98177 6.66016 7.10938 6.61328C7.23698 6.5638 7.32943 6.49219 7.38672 6.39844C7.44661 6.30469 7.47656 6.1875 7.47656 6.04688C7.47656 5.88542 7.44661 5.75521 7.38672 5.65625C7.32682 5.55729 7.23177 5.48568 7.10156 5.44141C6.97396 5.39453 6.80859 5.37109 6.60547 5.37109H5.93359V10H4.5625V4.3125H6.60547C6.95703 4.3125 7.27083 4.34505 7.54688 4.41016C7.82292 4.47266 8.05729 4.56901 8.25 4.69922C8.44531 4.82943 8.59375 4.99349 8.69531 5.19141C8.79688 5.38672 8.84766 5.61719 8.84766 5.88281C8.84766 6.11458 8.79818 6.33203 8.69922 6.53516C8.60026 6.73828 8.4349 6.90365 8.20312 7.03125C7.97396 7.15625 7.66016 7.22135 7.26172 7.22656L6.88281 7.58203ZM6.82812 10H5.08594L5.55469 8.94531H6.82812C7.01562 8.94531 7.16536 8.91667 7.27734 8.85938C7.39193 8.79948 7.47396 8.72135 7.52344 8.625C7.57552 8.52604 7.60156 8.41667 7.60156 8.29688C7.60156 8.15104 7.57682 8.02474 7.52734 7.91797C7.48047 7.8112 7.40495 7.72917 7.30078 7.67188C7.19661 7.61198 7.05729 7.58203 6.88281 7.58203H5.73047L5.73828 6.68359H7.11719L7.4375 7.04297C7.81771 7.02734 8.11849 7.08073 8.33984 7.20312C8.5638 7.32552 8.72396 7.48698 8.82031 7.6875C8.91667 7.88802 8.96484 8.09766 8.96484 8.31641C8.96484 8.6888 8.88411 9 8.72266 9.25C8.5638 9.5 8.32552 9.6875 8.00781 9.8125C7.6901 9.9375 7.29688 10 6.82812 10ZM14.6406 8.94531V10H11.6094V8.94531H14.6406ZM12.0977 4.3125V10H10.7266V4.3125H12.0977ZM14.25 6.57031V7.58984H11.6094V6.57031H14.25ZM14.6523 4.3125V5.37109H11.6094V4.3125H14.6523ZM19.0352 4.3125V10H17.6641V4.3125H19.0352ZM20.7461 4.3125V5.37109H15.9922V4.3125H20.7461ZM24.2617 5.50781L22.875 10H21.4023L23.4922 4.3125H24.4258L24.2617 5.50781ZM25.4102 10L24.0195 5.50781L23.8398 4.3125H24.7852L26.8867 10H25.4102ZM25.3555 7.87891V8.9375H22.4375V7.87891H25.3555Z" fill="white"/>

    </svg>

.. |kernel| raw:: html
	
	<svg xmlns="http://www.w3.org/2000/svg" width="16" viewBox="0 0 24 24" data-icon="ui-components:kernel"><path xmlns="http://www.w3.org/2000/svg" class="jp-icon2" d="M15 9H9v6h6V9zm-2 4h-2v-2h2v2zm8-2V9h-2V7c0-1.1-.9-2-2-2h-2V3h-2v2h-2V3H9v2H7c-1.1 0-2 .9-2 2v2H3v2h2v2H3v2h2v2c0 1.1.9 2 2 2h2v2h2v-2h2v2h2v-2h2c1.1 0 2-.9 2-2v-2h2v-2h-2v-2h2zm-4 6H7V7h10v10z"></path></svg>

.. |transfer| raw:: html

	<svg aria-hidden="true" focusable="false" class="octicon octicon-arrow-switch" viewBox="0 0 16 16" width="16" height="16" style="display: inline-block; user-select: none; vertical-align: text-bottom; overflow: visible;"><path d="M5.22 14.78a.75.75 0 0 0 1.06-1.06L4.56 12h8.69a.75.75 0 0 0 0-1.5H4.56l1.72-1.72a.75.75 0 0 0-1.06-1.06l-3 3a.75.75 0 0 0 0 1.06l3 3Zm5.56-6.5a.75.75 0 1 1-1.06-1.06l1.72-1.72H2.75a.75.75 0 0 1 0-1.5h8.69L9.72 2.28a.75.75 0 0 1 1.06-1.06l3 3a.75.75 0 0 1 0 1.06l-3 3Z"></path></svg>

.. |actions| raw:: html

	<i class="fa-solid fa-ellipsis"></i>

.. |trash| raw:: html
	
	<svg aria-hidden="true" focusable="false" class="octicon octicon-trash" viewBox="0 0 16 16" width="16" height="16" style="display: inline-block; user-select: none; vertical-align: text-bottom; overflow: visible;"><path d="M11 1.75V3h2.25a.75.75 0 0 1 0 1.5H2.75a.75.75 0 0 1 0-1.5H5V1.75C5 .784 5.784 0 6.75 0h2.5C10.216 0 11 .784 11 1.75ZM4.496 6.675l.66 6.6a.25.25 0 0 0 .249.225h5.19a.25.25 0 0 0 .249-.225l.66-6.6a.75.75 0 0 1 1.492.149l-.66 6.6A1.748 1.748 0 0 1 10.595 15h-5.19a1.75 1.75 0 0 1-1.741-1.575l-.66-6.6a.75.75 0 1 1 1.492-.15ZM6.5 1.75V3h3V1.75a.25.25 0 0 0-.25-.25h-2.5a.25.25 0 0 0-.25.25Z"></path></svg>

