<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" xml:lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> <meta http-equiv="X-UA-Compatible" content="IE=edge"></meta> <meta name="copyright" content="(C) Copyright 2005"></meta> <meta name="DC.rights.owner" content="(C) Copyright 2005"></meta> <meta name="DC.Type" content="concept"></meta> <meta name="DC.Title" content="NVIDIA CUDA Developer Guide for Nvidia Optimus Platforms"></meta> <meta name="abstract" content="The API reference guide for GPU querying of Optimus systems."></meta> <meta name="description" content="The API reference guide for GPU querying of Optimus systems."></meta> <meta name="DC.Coverage" content="Programming Guides"></meta> <meta name="DC.subject" content="CUDA Optimus, CUDA Optimus query, CUDA Optimus graphics, CUDA Optimus DirectX, CUDA Optimus OpenGL, CUDA Optimus control panel, CUDA Optimus driver, CUDA Optimus display, CUDA Optimus restrictions, CUDA Optimus application profile"></meta> <meta name="keywords" content="CUDA Optimus, CUDA Optimus query, CUDA Optimus graphics, CUDA Optimus DirectX, CUDA Optimus OpenGL, CUDA Optimus control panel, CUDA Optimus driver, CUDA Optimus display, CUDA Optimus restrictions, CUDA Optimus application profile"></meta> <meta name="DC.Format" content="XHTML"></meta> <meta name="DC.Identifier" content="abstract"></meta> <link rel="stylesheet" type="text/css" href="../common/formatting/commonltr.css"></link> <link rel="stylesheet" type="text/css" href="../common/formatting/site.css"></link> <title>Developer Guide for Optimus :: CUDA Toolkit Documentation</title> <!--[if lt IE 9]> <script src="../common/formatting/html5shiv-printshiv.min.js"></script> <![endif]--> <script type="text/javascript" charset="utf-8" src="//assets.adobedtm.com/b92787824f2e0e9b68dc2e993f9bd995339fe417/satelliteLib-7ba51e58dc61bcb0e9311aadd02a0108ab24cc6c.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.min.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.ba-hashchange.min.js"></script> <script type="text/javascript" charset="utf-8" src="../common/formatting/jquery.scrollintoview.min.js"></script> <script type="text/javascript" src="../search/htmlFileList.js"></script> <script type="text/javascript" src="../search/htmlFileInfoList.js"></script> <script type="text/javascript" src="../search/nwSearchFnt.min.js"></script> <script type="text/javascript" src="../search/stemmers/en_stemmer.min.js"></script> <script type="text/javascript" src="../search/index-1.js"></script> <script type="text/javascript" src="../search/index-2.js"></script> <script type="text/javascript" src="../search/index-3.js"></script> <link rel="canonical" href="http://docs.nvidia.com/cuda/optimus-developer-guide/index.html"></link> <link rel="stylesheet" type="text/css" href="../common/formatting/qwcode.highlight.css"></link> </head> <body> <header id="header"><span id="company">NVIDIA</span><span id="site-title">CUDA Toolkit Documentation</span><form id="search" method="get" action="search"> <input type="text" name="search-text"></input><fieldset id="search-location"> <legend>Search In:</legend> <label><input type="radio" name="search-type" value="site"></input>Entire Site</label> <label><input type="radio" name="search-type" value="document"></input>Just This Document</label></fieldset> <button type="reset">clear search</button> <button id="submit" type="submit">search</button></form> </header> <div id="site-content"> <nav id="site-nav"> <div class="category closed"><a href="../index.html" title="The root of the site.">CUDA Toolkit v10.1.168</a></div> <div class="category"><a href="index.html" title="Developer Guide for Optimus">Developer Guide for Optimus</a></div> <ul> <li> <div class="section-link"><a href="#introduction-to-optimus">1. Introduction to Optimus</a></div> </li> <li> <div class="section-link"><a href="#cuda-applications-and-optimus">2. CUDA Applications and Optimus</a></div> </li> <li> <div class="section-link"><a href="#querying-for-a-cuda-device">3. Querying for a CUDA Device</a></div> <ul> <li> <div class="section-link"><a href="#applications-without-graphics-interoperability">3.1. Applications without Graphics Interoperability</a></div> </li> <li> <div class="section-link"><a href="#applications-with-graphics-interoperability">3.2. Applications with Graphics Interoperability</a></div> </li> <li> <div class="section-link"><a href="#cuda-support-with-directx-interoperability">3.3. CUDA Support with DirecX Interoperability</a></div> </li> <li> <div class="section-link"><a href="#cuda-support-with-opengl-interoperability">3.4. CUDA Support with OpenGL Interoperability</a></div> </li> <li> <div class="section-link"><a href="#control-panel-settings-and-driver-updates-with-optimus">3.5. Control Panel Settings and Driver Updates</a></div> </li> </ul> </li> </ul> </nav> <div id="resize-nav"></div> <nav id="search-results"> <h2>Search Results</h2> <ol></ol> </nav> <div id="contents-container"> <div id="breadcrumbs-container"> <div id="release-info">Developer Guide for Optimus (<a href="../../pdf/Optimus_Developer_Guide.pdf">PDF</a>) - v10.1.168 (<a href="https://developer.nvidia.com/cuda-toolkit-archive">older</a>) - Last updated April 24, 2019 - <a href="mailto:CUDAIssues@nvidia.com?subject=CUDA Toolkit Documentation Feedback: Developer Guide for Optimus">Send Feedback</a></div> </div> <article id="contents"> <div class="topic nested0" id="abstract"><a name="abstract" shape="rect"> <!-- --></a><h2 class="title topictitle1"><a href="#abstract" name="abstract" shape="rect">NVIDIA CUDA Developer Guide for Nvidia Optimus Platforms</a></h2> <div class="body conbody"> <p class="shortdesc">The API reference guide for GPU querying of Optimus systems.</p> </div> </div> <div class="topic concept nested0" id="introduction-to-optimus"><a name="introduction-to-optimus" shape="rect"> <!-- --></a><h2 class="title topictitle1"><a href="#introduction-to-optimus" name="introduction-to-optimus" shape="rect">1. Introduction to Optimus</a></h2> <div class="body conbody"> <p class="p"><strong class="ph b">NVIDIA<sup>®</sup> Optimus™ is a revolutionary technology that delivers great battery life and great performance, in a way that simply works.</strong> 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. </p> <p class="p">The result is long lasting battery life without sacrificing great graphics performance, delivering an experience that is fully automatic and behind the scenes. </p> <p class="p">When the GPU can provide an increase in performance, functionality, or quality over the <dfn class="term">IGP</dfn> 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. </p> <p class="p">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. </p> <p class="p">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. </p> <p class="p">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. </p> <p class="p">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. </p> </div> </div> <div class="topic concept nested0" id="cuda-applications-and-optimus"><a name="cuda-applications-and-optimus" shape="rect"> <!-- --></a><h2 class="title topictitle1"><a href="#cuda-applications-and-optimus" name="cuda-applications-and-optimus" shape="rect">2. CUDA Applications and Optimus</a></h2> <div class="body conbody"> <p class="p">Optimus systems all have an Intel <dfn class="term">IGP</dfn> 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: <a class="xref" href="http://www.nvidia.com/object/optimus_technology.html" target="_blank" shape="rect">http://www.nvidia.com/object/optimus_technology.html</a>. </p> <p class="p">CUDA developers should understand this scheme because it affects how applications should query for GPU capabilities. For example, a CUDA application launched on the <dfn class="term">LVDS</dfn> 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. </p> <p class="p">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 <dfn class="term">Direct3D</dfn> or <dfn class="term">OpenGL</dfn> context that will interoperate with CUDA. <a class="xref" href="index.html#cuda-support-with-directx-interoperability" shape="rect">CUDA Support with DirecX Interoperability</a> and <a class="xref" href="index.html#cuda-support-with-opengl-interoperability" shape="rect">CUDA Support with OpenGL Interoperability</a> in this guide discuss this topic in more detail. </p> </div> </div> <div class="topic concept nested0" id="querying-for-a-cuda-device"><a name="querying-for-a-cuda-device" shape="rect"> <!-- --></a><h2 class="title topictitle1"><a href="#querying-for-a-cuda-device" name="querying-for-a-cuda-device" shape="rect">3. Querying for a CUDA Device</a></h2> <div class="body conbody"> <p class="p">Depending on the application, there are different ways to query for a CUDA device.</p> </div> <div class="topic concept nested1" id="applications-without-graphics-interoperability"><a name="applications-without-graphics-interoperability" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#applications-without-graphics-interoperability" name="applications-without-graphics-interoperability" shape="rect">3.1. Applications without Graphics Interoperability</a></h3> <div class="body conbody"> <p class="p">For CUDA applications, finding the best CUDA capable device is done through the CUDA API. The CUDA API functions <samp class="ph codeph">cudaGetDeviceProperties</samp> (CUDA runtime API), and <samp class="ph codeph">cuDeviceComputeCapability</samp> (CUDA Driver API) are used. Refer to the CUDA Sample <samp class="ph codeph">deviceQuery</samp> or <samp class="ph codeph">deviceQueryDrv</samp> for more details. </p> <p class="p">The next two code samples illustrate the best method of choosing a CUDA capable device with the best performance. </p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA Runtime API Version</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">inline</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> cutGetMaxGflopsDeviceId() { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> current_device = 0, sm_per_multiproc = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> max_compute_perf = 0, max_perf_device = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> device_count = 0, best_SM_arch = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> arch_cores_sm[3] = { 1, 8, 32, 192 }; cudaDeviceProp deviceProp; cudaGetDeviceCount( &device_count ); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Find the best major SM Architecture GPU device</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">while</span> ( current_device < device_count ) { cudaGetDeviceProperties( &deviceProp, current_device ); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (deviceProp.major > 0 && deviceProp.major < 9999) { best_SM_arch = max(best_SM_arch, deviceProp.major); } current_device++; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Find the best CUDA capable GPU device</span> current_device = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">while</span>( current_device < device_count ) { cudaGetDeviceProperties( &deviceProp, current_device ); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (deviceProp.major == 9999 && deviceProp.minor == 9999) { sm_per_multiproc = 1; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (deviceProp.major <= 3) { sm_per_multiproc = arch_cores_sm[deviceProp.major]; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Device has SM major > 3</span> sm_per_multiproc = arch_cores_sm[3]; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> compute_perf = deviceProp.multiProcessorCount * sm_per_multiproc * deviceProp.clockRate; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span>( compute_perf > max_compute_perf ) { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// If we find GPU of SM major > 3, search only these</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> ( best_SM_arch > 3 ) { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// If device==best_SM_arch, choose this, or else pass</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (deviceProp.major == best_SM_arch) { max_compute_perf = compute_perf; max_perf_device = current_device; } } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> { max_compute_perf = compute_perf; max_perf_device = current_device; } } ++current_device; } cudaGetDeviceProperties(&deviceProp, max_compute_perf_device); printf(<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">"\nDevice %d: \"%s\"\n"</span>, max__perf_device, deviceProp.name); printf(<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">"Compute Capability : %d.%d\n"</span>, deviceProp.major, deviceProp.minor); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">return</span> max_perf_device; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA Driver API Version</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">inline</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> cutilDrvGetMaxGflopsDeviceId() { CUdevice current_device = 0, max_perf_device = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> device_count = 0, sm_per_multiproc = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> max_compute_perf = 0, best_SM_arch = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> major = 0, minor = 0, multiProcessorCount, clockRate; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> arch_cores_sm[3] = { 1, 8, 32, 192 }; cuInit(0); cuDeviceGetCount(&device_count); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Find the best major SM Architecture GPU device</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">while</span> ( current_device < device_count ) { cuDeviceComputeCapability(&major, &minor, current_device)); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (major > 0 && major < 9999) { best_SM_arch = MAX(best_SM_arch, major); } current_device++; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Find the best CUDA capable GPU device</span> current_device = 0; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">while</span>( current_device < device_count ) { cuDeviceGetAttribute( &multiProcessorCount, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, current_device ) ); cuDeviceGetAttribute( &clockRate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, current_device ) ); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (major == 9999 && minor == 9999) { sm_per_multiproc = 1; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (major <= 3) { sm_per_multiproc = arch_cores_sm[major]; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> { sm_per_multiproc = arch_cores_sm[3]; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> compute_perf = multiProcessorCount * sm_per_multiproc * clockRate; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span>( compute_perf > max_compute_perf ) { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// If we find GPU with SM major > 2, search only these</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> ( best_SM_arch > 2 ) { <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// If our device==dest_SM_arch, choose this, or else pass</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (major == best_SM_arch) { max_compute_perf = compute_perf; max_perf_device = current_device; } } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">else</span> { max_compute_perf = compute_perf; max_perf_device = current_device; } } ++current_device; } <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">char</span> name[100]; cuDeviceGetName(name, 100, max_perf_device); cuDeviceComputeCapability(&major, &minor, max_perf_device); printf(<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">"\nDevice %d: "</span>%s\n<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">", max_perf_device, name); </span> printf(<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">" Compute Capability : %d.%d\n"</span>, major, minor); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">return</span> max_perf_device; }</pre></div> </div> <div class="topic concept nested1" id="applications-with-graphics-interoperability"><a name="applications-with-graphics-interoperability" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#applications-with-graphics-interoperability" name="applications-with-graphics-interoperability" shape="rect">3.2. Applications with Graphics Interoperability</a></h3> <div class="body conbody"> <p class="p">For CUDA applications that use the CUDA interop capability with <dfn class="term">Direct3D</dfn> or <dfn class="term">OpenGL</dfn>, developers should be aware of the restrictions and requirements to ensure compatibility with the Optimus platform. For CUDA applications that meet these descriptions: </p> <ol class="ol"> <li class="li">Application requires CUDA interop capability with either Direct3D or OpenGL. </li> <li class="li">Application is <u class="ph u">not</u> directly linked against <samp class="ph codeph">cuda.lib</samp> or <samp class="ph codeph">cudart.lib</samp> or <samp class="ph codeph">LoadLibrary</samp> to dynamically load the <samp class="ph codeph">nvcuda.dll</samp> or <samp class="ph codeph">cudart*.dll</samp> and uses <samp class="ph codeph">GetProcAddress</samp> to retrieve function addresses from <samp class="ph codeph">nvcuda.dll</samp> or <samp class="ph codeph">cudart*.dll</samp>. </li> </ol> <p class="p">A Direct3D or OpenGL context has to be created before the CUDA context. The Direct3D or OpenGL context needs to pass this into the CUDA. See the sample calls below in red below. Your application will need to create the graphics context first. The sample code below does not illustrate this. </p> <p class="p">Refer to the CUDA Sample <samp class="ph codeph">simpleD3D9</samp> and <samp class="ph codeph">simpleD3D9Texture</samp> for details. </p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA/Direct3D9 interop</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// You will need to create the D3D9 context first</span> IDirect3DDevice9 * g_pD3D9Device; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Initialize D3D9 rendering device</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// After creation, bind your D3D9 context to CUDA</span> cudaD3D9SetDirect3DDevice(g_pD3D9Device);</pre><p class="p">Refer to the CUDA Sample <samp class="ph codeph">simpleD3D10</samp> and <samp class="ph codeph">simpleD3D10Texture</samp> for details. </p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA/Direct3D10 interop</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// You will need to create a D3D10 context first</span> ID3D10Device * g_pD3D10Device; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Initialize D3D10 rendering device</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// After creation, bind your D3D10 context to CUDA</span> cudaD3D10SetDirect3DDevice(g_pD3D10Device);</pre><p class="p">Refer to the CUDA Sample <samp class="ph codeph">simpleD3D11Texture</samp> for details. </p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA/Direct3D11 interop</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// You will need to first create the D3D11 context first</span> ID3D11Device * g_pD3D11Device; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Initialize D3D11 rendering device</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// After creation, bind your D3D11 context to CUDA</span> cudaD3D11SetDirect3DDevice(g_pD3D11Device);</pre><p class="p">Refer to the CUDA Samples <samp class="ph codeph">simpleGL</samp> and <samp class="ph codeph">postProcessGL</samp> for details. </p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// For CUDA/OpenGL interop</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// You will need to create the OpenGL Context first</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// After creation, bind your D3D11 context to CUDA</span> cudaGLSetGLDevice(deviceID);</pre><p class="p">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 <dfn class="term">IGP</dfn>. 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. </p> <p class="p">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 created manually through the NVIDIA control Panel (see <a class="xref" href="index.html#control-panel-settings-and-driver-updates-with-optimus" shape="rect">Control Panel Settings and Driver Updates</a>Section 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. </p> </div> </div> <div class="topic concept nested1" id="cuda-support-with-directx-interoperability"><a name="cuda-support-with-directx-interoperability" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#cuda-support-with-directx-interoperability" name="cuda-support-with-directx-interoperability" shape="rect">3.3. CUDA Support with DirecX Interoperability</a></h3> <div class="body conbody"> <p class="p">The following steps with code samples illustrate what is necessary to initialize your CUDA application to interoperate with <dfn class="term">Direct3D9</dfn>. </p> <div class="note note"><span class="notetitle">Note:</span> An application profile may also be needed. </div> <ol class="ol"> <li class="li"> <p class="p">Create a Direct3D9 Context:</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Create the D3D object</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))==NULL ) <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">return</span> E_FAIL;</pre></li> <li class="li"> <p class="p">Find the CUDA Device that is also a Direct3D device</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Find the first CUDA capable device, may also want to check </span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// number of cores with cudaGetDeviceProperties for the best </span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// CUDA capable GPU (see previous function for details)</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">for</span>(g_iAdapter = 0; g_iAdapter < g_pD3D->GetAdapterCount(); g_iAdapter++) { D3DCAPS9 caps; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (FAILED(g_pD3D->GetDeviceCaps(g_iAdapter, D3DDEVTYPE_HAL, &caps))) <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Adapter doesn't support Direct3D</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">continue</span>; D3DADAPTER_IDENTIFIER9 ident; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> device; g_pD3D->GetAdapterIdentifier(g_iAdapter, 0, &ident); cudaD3D9GetDevice(&device, ident.DeviceName); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (cudaSuccess == cudaGetLastError() ) <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">break</span>; }</pre></li> <li class="li"> <p class="p">Create the Direct3D device</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Create the D3DDevice</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">if</span> (FAILED( g_pD3D->CreateDevice( g_iAdapter, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pD3DDevice ) ) ) <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">return</span> E_FAIL;</pre></li> <li class="li"> <p class="p">Bind the CUDA Context to the Direct3D device:</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Now we need to bind a CUDA context to the DX9 device</span> cudaD3D9SetDirect3DDevice(g_pD3DDevice);</pre></li> </ol> </div> </div> <div class="topic concept nested1" id="cuda-support-with-opengl-interoperability"><a name="cuda-support-with-opengl-interoperability" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#cuda-support-with-opengl-interoperability" name="cuda-support-with-opengl-interoperability" shape="rect">3.4. CUDA Support with OpenGL Interoperability</a></h3> <div class="body conbody"> <p class="p">The following steps with code samples illustrate what is needed to initialize your CUDA application to interoperate with <dfn class="term">OpenGL</dfn>. </p> <div class="note note"><span class="notetitle">Note:</span> An application profile may also be needed. </div> <ol class="ol"> <li class="li"> <p class="p">Create an OpenGL Context and OpenGL window</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Create GL context</span> glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(window_width, window_height); glutCreateWindow(<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-string">"OpenGL Application"</span>); <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// default initialization of the back buffer</span> glClearColor(0.5, 0.5, 0.5, 1.0);</pre></li> <li class="li"> <p class="p">Create the CUDA Context and bind it to the OpenGL context</p><pre xml:space="preserve"><span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-comment">// Initialize CUDA context (ontop of the GL context)</span> <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> dev, deviceCount; cudaGetDeviceCount(&deviceCount); cudaDeviceProp deviceProp; <span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">for</span> (<span xmlns:xslthl="http://xslthl.sf.net" class="xslthl-keyword">int</span> i=0; i<deviceCount; i++) { cudaGetDeviceProperties(&deviceProp, dev)); } cudaGLSetGLDevice(dev);</pre></li> </ol> </div> </div> <div class="topic concept nested1" id="control-panel-settings-and-driver-updates-with-optimus"><a name="control-panel-settings-and-driver-updates-with-optimus" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#control-panel-settings-and-driver-updates-with-optimus" name="control-panel-settings-and-driver-updates-with-optimus" shape="rect">3.5. Control Panel Settings and Driver Updates</a></h3> <div class="body conbody"> <p class="p">This section is for developers who create custom application-specific profiles. It describes how end users can be sure that their CUDA applications run on Optimus and how they can receive the latest updates on drivers and application profiles. </p> <ul class="ul"> <li class="li">Profile updates are frequently sent to end user systems, similar to how virus definitions work. Systems are automatically updated with new profiles in the background with no user intervention required. Contact NVIDIA developer support to create the appropriate driver application profiles. This will ensure that your CUDA application is compatible on Optimus and included in these automatic updates. </li> <li class="li">End users can create their own application profiles in the NVIDIA Control panel and set when switch and not to switch to the NVIDIA GPU per application. The screenshot below shows you where to find these application profiles.<br clear="none"></br><a name="control-panel-settings-and-driver-updates-with-optimus__manage-3d-settings" shape="rect"> <!-- --></a><div class="imagecenter"><img class="image imagecenter" id="control-panel-settings-and-driver-updates-with-optimus__manage-3d-settings" src="graphics/manage-3d-settings.png" alt="Screenshot of application profiles in Control Panel"></img></div><br clear="none"></br></li> <li class="li">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: <a class="xref" href="http://www.nvidia.com/object/notebook_drivers.html" target="_blank" shape="rect">http://www.nvidia.com/object/notebook_drivers.html</a></li> </ul> </div> </div> </div> <div class="topic concept nested0" id="notices-header"><a name="notices-header" shape="rect"> <!-- --></a><h2 class="title topictitle1"><a href="#notices-header" name="notices-header" shape="rect">Notices</a></h2> <div class="topic reference nested1" id="notice"><a name="notice" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#notice" name="notice" shape="rect"></a></h3> <div class="body refbody"> <div class="section"> <h3 class="title sectiontitle">Notice</h3> <p class="p">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. </p> <p class="p">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. </p> </div> </div> </div> <div class="topic reference nested1" id="trademarks"><a name="trademarks" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#trademarks" name="trademarks" shape="rect"></a></h3> <div class="body refbody"> <div class="section"> <h3 class="title sectiontitle">Trademarks</h3> <p class="p">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. </p> </div> </div> </div> <div class="topic reference nested1" id="copyright-present"><a name="copyright-present" shape="rect"> <!-- --></a><h3 class="title topictitle2"><a href="#copyright-present" name="copyright-present" shape="rect"></a></h3> <div class="body refbody"> <div class="section"> <h3 class="title sectiontitle">Copyright</h3> <p class="p">© <span class="ph">2019</span> NVIDIA Corporation. All rights reserved. </p> <p class="p">This product includes software developed by the Syncro Soft SRL (http://www.sync.ro/).</p> </div> </div> </div> </div> <hr id="contents-end"></hr> </article> </div> </div> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/formatting/common.min.js"></script> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/scripts/google-analytics/google-analytics-write.js"></script> <script language="JavaScript" type="text/javascript" charset="utf-8" src="../common/scripts/google-analytics/google-analytics-tracker.js"></script> <script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script><script type="text/javascript">stLight.options({publisher: "998dc202-a267-4d8e-bce9-14debadb8d92", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script><script type="text/javascript">_satellite.pageBottom();</script></body> </html>