.. _ogn_tutorial_cpu_gpu_bundles:

Tutorial 22 - Bundles On The GPU
================================

Bundles are not exactly data themselves, they are a representation of a collection of attributes whose composition is
determined at runtime. As such, they will always live on the CPU. However the attributes they are encapsulating have
the same flexibility as other attributes to live on the CPU, GPU, or have their location decided at runtime.

For that reason it's convenient to use the same "cpu", "cuda", and "any" memory types for the bundle attributes, with
a slightly different interpretation.

- **cpu** all attributes in the bundle will be on the CPU
- **gpu** all attributes in the bundle will be on the GPU
- **any** either some attributes in the bundle are on the CPU and some are on the GPU, or that decision will be made at runtime

For example if you had a bundle of attributes consisting of a large array of points and a boolean that controls the
type of operation you will perform on them it makes sense to leave the boolean on the CPU and move the points to the
GPU for more efficient processing.


OgnTutorialCpuGpuBundles.ogn
----------------------------------
The *ogn* file shows the implementation of a node named "omni.graph.tutorials.CpuGpuBundles" with an input bundle on
the CPU, an input bundle on the GPU, and an output bundle whose memory location is decided at runtime by a boolean.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial22/OgnTutorialCpuGpuBundles.ogn
    :linenos:
    :language: json

OgnTutorialCpuGpuBundles.cpp
----------------------------------
The *cpp* file contains the implementation of the compute method. It creates a merged bundle in either the CPU or
GPU based on the input boolean and runs an algorithm on the output location.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial22/OgnTutorialCpuGpuBundles.cpp
    :linenos:
    :language: c++

OgnTutorialCpuGpuBundlesPy.py
-----------------------------------
The *py* file contains the same algorithm as the C++ node, with the node implementation language being different.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial22/OgnTutorialCpuGpuBundlesPy.py
    :linenos:
    :language: python
