{"id":394,"date":"2020-11-02T11:10:59","date_gmt":"2020-11-02T11:10:59","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/sustainable-software\/?p=394"},"modified":"2020-12-01T08:50:30","modified_gmt":"2020-12-01T08:50:30","slug":"vlc-energy-optimization-with-gpu","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/sustainable-software\/vlc-energy-optimization-with-gpu\/","title":{"rendered":"VLC Energy Optimization With GPU"},"content":{"rendered":"<p>For the past few years, sustainable software engineering has arisen as one of the major topics in the daily discussions I have with software developers. Due to the advancements in technology, as well as the increasing awareness we share on climate change and the overall impact of tech on the environment, sustainable software engineering is now deeply integrated with innovation, user experience or application performance. This is the journey taken by the media player <a href=\"https:\/\/www.videolan.org\/vlc\/index.en-GB.html\">VLC<\/a>, to adopt Sustainable Software Engineering practices and reduce their carbon emissions. In this post, I will share how you can reconcile hardware innovations, application performance, and energy consumption.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture1.jpg\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-401\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/10\/Cone-Interface-large.png\" alt=\"Green VLC\" width=\"244\" height=\"300\" \/><\/a><\/p>\n<h2>What is VLC?<\/h2>\n<p><a href=\"https:\/\/www.videolan.org\/\">VLC<\/a> is a free and open-source media player written by the <a href=\"https:\/\/code.videolan.org\/\">VideoLAN project<\/a>. VLC is available for desktop operating systems and mobile platforms, such as Windows 10, Windows, Linux, Mac, Android, Tizen, iPad, iPhone, and Apple TV. VLC is also available on App stores such as Apple App Store, Google Play store, and Windows Store.<\/p>\n<p>The generation of electricity is responsible for almost half of global carbon emissions, and thus, the <a href=\"https:\/\/principles.green\/principles\/electricity\/\">2nd principle of Sustainable Software Engineering<\/a> is to build applications that are <strong>energy efficient<\/strong>. (https:\/\/principles.green\/principles\/electricity\/)<\/p>\n<p>Displaying video and decoding media are some of the most energy intensive software applications. Decoding is well suited to energy optimization since certain types of processing can be done on a GPU rather than a CPU, which results in fewer CPU cycles and lower power usage. Developers can take advantage by offloading the codec decoding of video scenarios to the more efficient GPU implementations. This has two advantages: performance and power usage.<\/p>\n<p>The codecs used in decoding are expensive, computation-wise, and very repetitive because of the size of the data. The use of hardware codecs and video filters on the GPU can reduce power consumption significantly.<\/p>\n<p>Typically, a developer has the choice between a &#8220;typical&#8221; algorithm utilizing the CPU or a more optimized algorithm leveraging the GPU. The optimized algorithm will reduce energy consumption and will provide better performance.<\/p>\n<p>In Windows, DirectX is the main software interface used for handling game programming and video. It consists of multiple components including Direct3D, DirectDraw, DirectMusic, DirectPlay, and DirectSound.<\/p>\n<p>One component, DirectX Video Acceleration (DXVA) can be used for hardware acceleration to speed up video processing. Software codecs and software video processors can use DXVA to offload certain CPU-intensive operations to the GPU. For example, a software decoder can offload the inverse Discrete Cosine Transform (iDCT) to the GPU.<\/p>\n<p>Using a combination of DXVA and Direct3D shaders permits access to the right codec for a specific video format and can provide this information to stages further along in the graphics pipeline. Activating the filters in Direct 3D shaders removes a copy from the CPU, avoiding expensive CPU cycles.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-402\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture2.png\" alt=\"Decode Image\" width=\"624\" height=\"83\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture2.png 624w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture2-300x40.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<h2>How to measure the impact of energy optimization?<\/h2>\n<p>To gauge the impact of different methods of decoding, two different VLC decoding scenarios were analyzed with powercfg: first with codec using hardware acceleration (GPU) codec, and second with hardware acceleration disabled. For more information on powercfg read <a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/measuring-your-application-power-and-carbon-impact-part-1\/\">Measuring Your Application Power and Carbon Impact (Part 1)<\/a><\/p>\n<p>In both scenarios, the playback of a standard video was chosen using a native render size of 4000 x 2250 (source <a href=\"http:\/\/distribution.bbb3d.renderfarming.net\/video\/mp4\/bbb_sunflower_native_60fps_normal.mp4\">here<\/a>). The video was encoded with x264 and contained both an AC-3 5.1 surround sound track as well as a normal MP3 stereo track. The setup for the test is: Surface Laptop 3 with Core i7 \u2013 1065G7 (Windows 2004) and VLC 3.0.11.<\/p>\n<p>In the preference dialog of VLC, you can now choose the hardware acceleration.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture3.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-403\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture3.png\" alt=\"VLC Options\" width=\"780\" height=\"333\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture3.png 780w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture3-300x128.png 300w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture3-768x328.png 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/a><\/p>\n<p>If you have multiple GPUs on your device, you can choose the GPU you want to use per application. In this case the intel GPU integrated is better regarding energy consumption.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture4.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-404\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture4.png\" alt=\"Image Picture4\" width=\"513\" height=\"391\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture4.png 513w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture4-300x229.png 300w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/a><\/p>\n<h2>Energy consumption CPU vs GPU<\/h2>\n<p>For 1-minute video playing and <strong>GPU acceleration<\/strong> we have this energy consumption in millijoules:<\/p>\n<table>\n<thead>\n<tr>\n<th><strong>CPUEnergy<\/strong><\/th>\n<th><strong>DisplayEnergy<\/strong><\/th>\n<th><strong>DiskEnergy<\/strong><\/th>\n<th><strong>TotalEnergy<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>49 169<\/strong><\/td>\n<td>256 061<\/td>\n<td>154<\/td>\n<td>305 386<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>For 1-minute video playback <strong>without GPU acceleration<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th><strong>CPUEnergy<\/strong><\/th>\n<th><strong>DisplayEnergy<\/strong><\/th>\n<th><strong>DiskEnergy<\/strong><\/th>\n<th><strong>TotalEnergy<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>799 157<\/strong><\/td>\n<td>245 231<\/td>\n<td>131<\/td>\n<td>1 044 397<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>By default, in the task manager you can see the power usage here without GPU acceleration:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture5.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-405\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture5.png\" alt=\"Image Picture5\" width=\"624\" height=\"29\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture5.png 624w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/11\/Picture5-300x14.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p><img decoding=\"async\" src=\"RackMultipart20201030-4-576jlw_html_46f30eef5c725229.png\" alt=\"\" \/><\/p>\n<p><em>As you can see a GPU enabled VLC is 70% more energy efficient than using the CPU!<\/em><\/p>\n<p>Summary<\/p>\n<p>There are other tools available on the market to monitor real-time applications&#8217; energy consumption, like this <a href=\"https:\/\/software.intel.com\/content\/www\/us\/en\/develop\/articles\/intel-power-gadget.htmlhttps:\/software.intel.com\/content\/www\/us\/en\/develop\/articles\/intel-power-gadget.html\">tool<\/a> for devices with Intel shipsets.<\/p>\n<p>We are also seeing several promising hardware innovations made by Intel, Qualcomm, NVIDIA, even at the silicon level to enable reduced energy consumption. For example, with their project <a href=\"https:\/\/blogs.nvidia.com\/blog\/2020\/10\/05\/gan-video-conferencing-maxine\/\">AI Can See Clearly Now<\/a>, NVIDIA uses a neural network in place of the video codec software typically used to compress and decompress video for transmission over the net. It enables a video call with one-tenth of the network bandwidth users typically need. In addition, we have developed new Artificial Intelligence (AI) instructions on SQ1 processor for Surface Pro X, that allows you, for example, to <a href=\"https:\/\/blogs.windows.com\/devices\/2020\/08\/20\/make-a-more-personal-connection-with-eye-contact-now-generally-available\/\">maintain Eye contact<\/a> during a call.<\/p>\n<p>This use case with VLC is part of a global initiative we have launched within the Windows applications ecosystem called <a href=\"https:\/\/www.microsoft.com\/en-us\/devices\/sustainability-report\">Devices Sustainability at Microsoft<\/a>.. We are convinced that algorithm optimizations, when used by millions of users and hundreds of minutes around the world, can have a significant impact on carbon emissions reduction. This type of optimization can also be leveraged for several other scenarios like database, compression, and AI. Green coding is one promising approach that developers can take to tackle environmental challenges.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the past few years, sustainable software engineering has arisen as one of the major topics in the daily discussions I have with software developers. Due to the advancements in technology, as well as the increasing awareness we share on climate change and the overall impact of tech on the environment, sustainable software engineering is [&hellip;]<\/p>\n","protected":false},"author":38745,"featured_media":410,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[91],"tags":[95,94,93,92],"class_list":["post-394","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-applications","tag-arm","tag-gpu","tag-media","tag-video"],"acf":[],"blog_post_summary":"<p>For the past few years, sustainable software engineering has arisen as one of the major topics in the daily discussions I have with software developers. Due to the advancements in technology, as well as the increasing awareness we share on climate change and the overall impact of tech on the environment, sustainable software engineering is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/users\/38745"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/comments?post=394"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/media\/410"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}