Optimus_Developer_Guide
Optimus_Developer_Guide
Reference Guide
TABLE OF CONTENTS
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | ii
Chapter 1.
INTRODUCTION TO OPTIMUS
NVIDIA® Optimus™ is a revolutionary technology that delivers great battery life and
great performance, in a way that simply works. It automatically and instantaneously
uses the best tool for the job – the high performance NVIDIA GPU for GPU-Compute
applications, video, and 3D games; and low power integrated graphics for applications
like Office, Web surfing, or email.
The result is long lasting battery life without sacrificing great graphics performance,
delivering an experience that is fully automatic and behind the scenes.
When the GPU can provide an increase in performance, functionality, or quality over the
IGP for an application, the NVIDIA driver will enable the GPU. When the user launches
an application, the NVIDIA driver will recognize whether the application being run can
benefit from using the GPU. If the application can benefit from running on the GPU, the
GPU is powered up from an idle state and is given all rendering calls.
Using NVIDIA’s Optimus technology, when the discrete GPU is handling all the
rendering duties, the final image output to the display is still handled by the Intel
integrated graphics processor (IGP). In effect, the IGP is only being used as a simple
display controller, resulting in a seamless, flicker-free experience with no need to reboot.
When the user closes all applications that benefit from the GPU, the discrete GPU is
powered off and the Intel IGP handles both rendering and display calls to conserve
power and provide the highest possible battery life.
The beauty of Optimus is that it leverages standard industry protocols and APIs to
work. From relying on standard Microsoft APIs when communicating with the Intel
IGP driver, to utilizing the PCI-Express bus to transfer the GPU’s output to the Intel IGP,
there are no proprietary hoops to jump through NVIDIA.
This document provides guidance to CUDA developers and explains how NVIDIA
CUDA APIs can be used to query for GPU capabilities in Optimus systems. It is
strongly recommended to follow these guidelines to ensure CUDA applications are
compatible with all notebooks featuring Optimus.
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 1
Chapter 2.
CUDA APPLICATIONS AND OPTIMUS
Optimus systems all have an Intel IGP and an NVIDIA GPU. Display heads may be
electrically connected to the IGP or the GPU. When a display is connected to a GPU
head, all rendering and compute on that display happens on the NVIDIA GPU just like
it would on a typical discrete system. When the display is connected to an IGP head, the
NVIDIA driver decides if an application on that display should be rendered on the GPU
or the IGP. If the driver decides to run the application on the NVIDIA GPU, the final
rendered frames are copied to the IGP’s display pipeline for scanout. Please consult the
Optimus white paper for more details on this behavior: http://www.nvidia.com/object/
optimus_technology.html.
CUDA developers should understand this scheme because it affects how applications
should query for GPU capabilities. For example, a CUDA application launched on the
LVDS panel of an Optimus notebook (which is an IGP-connected display), would see
that the primary display device is the Intel's graphic adapter – a chip not capable of
running CUDA. In this case, it is important for the application to detect the existence of
a second device in the system – the NVIDIA GPU – and then create a CUDA context on
this CUDA-capable device even when it is not the display device.
For applications that require use of Direct3D/CUDA or OpenGL/CUDA interop, there
are restrictions that developers need to be aware of when creating a Direct3D or OpenGL
context that will interoperate with CUDA. CUDA Support with DirecX Interoperability
and CUDA Support with OpenGL Interoperability in this guide discuss this topic in
more detail.
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 2
Chapter 3.
QUERYING FOR A CUDA DEVICE
Depending on the application, there are different ways to query for a CUDA device.
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 3
Querying for a CUDA Device
The next two code samples illustrate the best method of choosing a CUDA capable
device with the best performance.
// CUDA Runtime API Version
inline int cutGetMaxGflopsDeviceId()
{
int current_device = 0, sm_per_multiproc = 0;
int max_compute_perf = 0, max_perf_device = 0;
int device_count = 0, best_SM_arch = 0;
int arch_cores_sm[3] = { 1, 8, 32, 192 };
cudaDeviceProp deviceProp;
cudaGetDeviceCount( &device_count );
cudaGetDeviceProperties(&deviceProp, max_compute_perf_device);
printf("\nDevice %d: \"%s\"\n", max__perf_device,
deviceProp.name);
printf("Compute Capability : %d.%d\n",
deviceProp.major, deviceProp.minor);
return max_perf_device;
}
cuInit(0);
www.nvidia.com
CUDA cuDeviceGetCount(&device_count);
Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 4
// Find the best major SM Architecture GPU device
while ( current_device < device_count ) {
Querying for a CUDA Device
On an Optimus platform, this type of CUDA application will not work properly. If a
Direct3D or OpenGL graphics context is created before any CUDA API calls are used
or initialized, the Graphics context may be created on the Intel IGP. The problem here is
that the Intel IGP does not allow Graphics interoperability with CUDA running on the
NVIDIA GPU. If the Graphics context is created on the NVIDIA GPU, then everything
will work.
The solution is to create an application profile in the NVIDIA Control Panel. With an
application profile, the Direct3D or OpenGL context will always be created on the
NVIDIA GPU when the application gets launched. These application profiles can be
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 5
Querying for a CUDA Device
created manually through the NVIDIA control Panel (see Control Panel Settings and
Driver UpdatesSection 5 for details). Contact NVIDIA support to have this application
profile added to the drivers, so future NVIDIA driver releases and updates will include
it.
D3DADAPTER_IDENTIFIER9 ident;
int device;
g_pD3D->GetAdapterIdentifier(g_iAdapter,
0, &ident);
cudaD3D9GetDevice(&device, ident.DeviceName);
if (cudaSuccess == cudaGetLastError() )
break;
}
3. Create the Direct3D device
// Create the D3DDevice
if (FAILED( g_pD3D->CreateDevice( g_iAdapter, D3DDEVTYPE_HAL,
hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
&g_d3dpp, &g_pD3DDevice ) ) )
return E_FAIL;
4. Bind the CUDA Context to the Direct3D device:
// Now we need to bind a CUDA context to the DX9 device
cudaD3D9SetDirect3DDevice(g_pD3DDevice);
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 6
Querying for a CUDA Device
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 7
Querying for a CUDA Device
‣ NVIDIA regularly updates the graphics drivers through the NVIDIA Verde
Driver Program. End users will be able to download drivers which include
application-specific Optimus profiles for NVIDIA-powered notebooks from: http://
www.nvidia.com/object/notebook_drivers.html
www.nvidia.com
CUDA Developer Guide for NVIDIA Optimus Platforms DG-06715-001_v7.0 | 8
Notice
ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS,
DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY,
"MATERIALS") ARE BEING PROVIDED "AS IS." NVIDIA MAKES NO WARRANTIES,
EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE
MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF
NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR
PURPOSE.
Information furnished is believed to be accurate and reliable. However, NVIDIA
Corporation assumes no responsibility for the consequences of use of such
information or for any infringement of patents or other rights of third parties
that may result from its use. No license is granted by implication of otherwise
under any patent rights of NVIDIA Corporation. Specifications mentioned in this
publication are subject to change without notice. This publication supersedes and
replaces all other information previously supplied. NVIDIA Corporation products
are not authorized as critical components in life support devices or systems
without express written approval of NVIDIA Corporation.
Trademarks
NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA
Corporation in the U.S. and other countries. Other company and product names
may be trademarks of the respective companies with which they are associated.
Copyright
© 2014 NVIDIA Corporation. All rights reserved.
www.nvidia.com