<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by TonyM on Medium]]></title>
        <description><![CDATA[Stories by TonyM on Medium]]></description>
        <link>https://medium.com/@tonymongkolsmai?source=rss-9bf3c09af6c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_ghCTH7Ppi_1NiMaoY0U2w.png</url>
            <title>Stories by TonyM on Medium</title>
            <link>https://medium.com/@tonymongkolsmai?source=rss-9bf3c09af6c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 11:59:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tonymongkolsmai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging WSL and Multiple GPU issues]]></title>
            <link>https://medium.com/@tonymongkolsmai/debugging-wsl-and-multiple-gpu-issues-59f28a8cf5d?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/59f28a8cf5d</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oneapi]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 16:32:24 GMT</pubDate>
            <atom:updated>2023-02-01T16:32:24.544Z</atom:updated>
            <content:encoded><![CDATA[<p>Using PTI-GPU tools to Find an Odd Issue with WSL WDDM</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*ccqP6JCqNNXyrYDWdbIwqA.jpeg" /><figcaption>Test System, Image Courtesy of Author</figcaption></figure><h3>Introduction</h3><p>The Windows Subsystem for Linux (WSL) is a crucial piece of software for many developers. It provides the ability to do most Linux development tasks within Windows using a complete Linux workflow.</p><p>Previously I’ve written a couple of articles about how to use <a href="https://medium.com/better-programming/vscode-wsl2-and-oneapi-leveraging-tools-for-cross-platform-software-development-dbb8deaf10c9">WSL with Visual Studio Code and oneAPI</a>, <a href="https://medium.com/better-programming/vscode-wsl2-and-oneapi-leveraging-tools-for-cross-platform-software-development-dbb8deaf10c9">Docker, WSL and oneAPI</a> and how well <a href="https://medium.com/better-programming/wsl-extreme-usages-bdbb9ec218e7">WSL works with a variety of things like GUIs, USB ports and even Kuberentes.</a> In all of these applications, WSL has just been amazing.</p><p>Unfortunately, I finally ran into an issue within the wonderful world of WSL for my use cases…using multiple GPUs for compute acceleration at the same time.</p><h3>The Issue, Debugging, and Workaround</h3><p>As part of building my oneAPI test system with AMD, NVIDIA and Intel GPUs, I’ve been working to test a variety of workloads that run across all 3 GPUs using SYCL as a singular programming model. Generally, this has been a pretty seamless process using Ubuntu 22.04 (not WSL).</p><p>I decided to try to move some of this work to WSL on Windows as I had been doing some cross-compile testing for code. What I found when I did that was that even the simplest application was running into an issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6_Dxt51tS824sFOvnnoaA.png" /><figcaption>Issue in wddm_memory_manager.cpp</figcaption></figure><p>For reference, this is the same Mandelbrot sample from the <a href="https://github.com/oneapi-src/oneAPI-samples">oneAPI Samples</a> GitHub that I’ve used in the past.</p><p>Finding that a little odd, I did a little debugging and using the ze_tracer tool within the <a href="https://github.com/intel/pti-gpu">Profiling Tools Interfaces for GPU</a>, found that the SYCL runtime library was trying to allocate an event pool on multiple GPUs (the discrete Intel Arc A770 and the integrated Intel UHD 770).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBfvcEuQlrP-DKIl0PDSJA.png" /><figcaption>The output of ze_tracer profiling tool</figcaption></figure><p>A lot of text here, but you can see in the last line that right after the EventPoolCreate call we are getting the abort from the wddm_memory_manager.cpp code.</p><p>To workaround the problem, I disabled either one of the GPUs using the device manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*SMh9jEqxhuI-VD4gUhKYFg.png" /><figcaption>Disabled iGPU</figcaption></figure><p>After that simple step, the sample code ran fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*3EvsYWbMZlVcsI2G1El2Hg.png" /></figure><h3>Conclusion</h3><p>I’m not sure if the issue is actually the way WSL does virtualization around the WDDM driver or some other issue. What I can say is with non-WSL Linux it worked fine, but within WSL I ran into this issue. I spent about half a day on this issue trying to get my code to work in WSL; hopefully, this quick walk-through will help someone else who runs into the same issue.</p><p>To be very clear, this is not the type of development or application that I would expect many people to do, and very likely they don’t have a multiple GPU setup as excessive as mine. I also don’t want to dissuade people from using WSL, it’s a great tool, but knowing some potential limitations you may run into is important. Good luck and keep coding!</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter. Also, check out </em><a href="https://connectedsocialmedia.com/category/code-together/"><em>Code Together</em></a><em>, an Intel podcast for developers that I host where we talk tech.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He was architect of Intel VTune Profiler and other performance tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59f28a8cf5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CUDA, ROCm, oneAPI? — Running Code on a GPU, Any GPU]]></title>
            <link>https://medium.com/@tonymongkolsmai/cuda-rocm-oneapi-running-code-on-a-gpu-any-gpu-28b7bf4cf1d0?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/28b7bf4cf1d0</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[oneapi]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Tue, 27 Dec 2022 18:07:39 GMT</pubDate>
            <atom:updated>2022-12-29T02:20:17.814Z</atom:updated>
            <content:encoded><![CDATA[<h3>CUDA, ROCm, oneAPI? — Running Code on a GPU, Any GPU</h3><h4>Why knowing multiple vendor&#39;s GPU programming model is a necessary evil…or is it?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GY9oWHQcoE0dmli62Aai9g.jpeg" /><figcaption>Test System, Image courtesy of Author</figcaption></figure><h3>Introduction</h3><p>In my last <a href="https://medium.com/better-programming/synchronization-letting-accelerator-parallel-developers-run-free-809573b3b86a">two posts</a> about parallel and accelerator programming, I talked about the basics of accelerator and parallel programming and some of the programming concepts required to ensure the correctness of your code. The interesting question for the programmer learning accelerator programming is “Do I really need to learn CUDA, ROCm and SYCL to program for NVIDIA, AMD, and Intel accelerators?”</p><p>When planning this series, I was expecting to dive into the similarity and differences between the hardware execution and memory models of each architecture. I was going to talk about warps, wavefronts and workgroups, the respective constructs CUDA, ROCm and SYCL use to group execution on hardware threads. However, the more I think about it, the more that seems a little too much for a blog post. If you are interested in those topics, see the nice <a href="https://developer.codeplay.com/products/computecpp/ce/2.11.0/guides/sycl-for-cuda-developers">SYCL for CUDA developers</a> from Codeplay.</p><p>Instead today I’m going to focus on how to get you from no code to running on a GPU, any GPU, as quickly as possible. Nothing is as fun as seeing the performance benefits of your accelerator as quickly as possible. For me, this is fun because it coincides with the release of the Codeplay <a href="https://developer.codeplay.com/products/oneapi/nvidia/home/">oneAPI for NVIDIA</a> and <a href="https://developer.codeplay.com/products/oneapi/amd/home/">oneAPI for AMD (beta)</a>.</p><h3>SYCL and multiple vendor GPUs</h3><p>SYCL is a programming model that has compiler support for NVIDIA, AMD and Intel GPUs. You can write your code in SYCL and then build and run it on those vendor GPUs. Previously this required using various community compilers, or building the Intel Open Source compiler, depending on your GPU target. With the release of the latest Codeplay toolchains, you can now quickly and easily get your code running through a single, prebuilt toolchain. For more details on this, you can read Ruyman Reyes, Codeplay’s CTO, <a href="https://codeplay.com/portal/blogs/2022/12/16/bringing-nvidia-and-amd-support-to-oneapi.html">blog</a> on their new release.</p><p>One question you may be asking is can I actually build my code once and then decide at runtime which GPU to run on? The answer is <strong>YES</strong>! This is the nice thing about this support, you build your code once and at runtime, you can choose your target manually, or let the runtime library choose for you automatically.</p><p>Since you’ve gotten this far, I’ll assume this is of interest to you and my goal is to get you up and running on your GPU of choice. For my purposes, I’m testing all 3 vendor GPUs on Ubuntu 22.04 and be doing installing via APT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CZOlQz9t7KswtpB6vl4fw.jpeg" /><figcaption>Test System, Image courtesy of Author</figcaption></figure><h3>Installing the Codeplay toolchain</h3><p>First, we set up some basic system packages:</p><pre>sudo apt update<br>sudo apt -y install cmake pkg-config build-essential</pre><p>Next, we grab the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit.html">Intel® oneAPI Base Toolkit 2023.0</a>, which is used by the Codeplay toolchain. You can find Instructions for how to do this via APT at the <a href="https://www.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top/installation/install-using-package-managers/apt.html">Intel® oneAPI Toolkits Installation Guide for Linux* OS</a> page. Here are the steps I used, but refer to the original page if you have issues:</p><pre># download the key to system keyring<br>wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \<br>| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg &gt; /dev/null<br><br># add signed entry to apt sources and configure the APT client to use Intel repository:<br>echo &quot;deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main&quot; | sudo tee /etc/apt/sources.list.d/oneAPI.list<br><br>sudo apt-update<br>sudo apt install intel-basekit</pre><h3>Vendor Specific Setup</h3><p>Make sure you have the base drivers/frameworks you need for each GPU you have/want to target, again I’m linking Ubuntu instructions:</p><h4>Intel GPU Driver install</h4><p>Instructions for Intel GPUs on different OSes can be found <a href="https://dgpu-docs.intel.com/installation-guides/index.html">here</a>. Because I’m using an Intel Arc on Ubuntu 22.04, I followed these <a href="https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-jammy-arc.html">instructions</a>.</p><h4>oneAPI for NVIDIA Installation</h4><p>You can go <a href="https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu">here</a> to get the latest official instructions for how to install CUDA, I’m inlining what I use to get it up and running:</p><ol><li>Install CUDA keyring, CUDA and reboot</li></ol><pre>wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb<br>sudo dpkg -i cuda-keyring_1.0-1_all.deb<br><br>sudo apt-get update<br>sudo apt-get install cuda-11-7<br>sudo apt-get install nvidia-gds</pre><pre>sudo reboot</pre><p>2. Set paths to make sure my terminal can find CUDA:</p><pre>export PATH=/usr/local/cuda-11.7/bin${PATH:+:${PATH}}<br>export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64\<br>                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}</pre><p>3. Download the oneAPI for NVIDIA GPUs installer from Codeplay <a href="https://developer.codeplay.com/products/oneapi/nvidia/download/">here</a>.</p><p>4. Run the installation script</p><pre>sh oneapi-for-nvidia-gpus-2023.0.0-linux.sh</pre><p>5. Before each build in your terminal or in your .profile, make sure the build environment is set correctly to enable the oneAPI and to find CUDA.</p><pre>. /opt/intel/oneapi/setvars.sh --include-intel-llvm<br>export PATH=/usr/local/cuda-11.7/bin${PATH:+:${PATH}}<br>export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64\<br>                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}</pre><h4>oneAPI for AMD (beta) Installation</h4><p>You can go <a href="https://docs.amd.com/bundle/ROCm-Installation-Guide-v5.4.1/page/How_to_Install_ROCm.html#_How_to_Install">here</a> to get the latest official instructions for how to install ROCm, again inlining here to make things a little easier for you:</p><ol><li>Install the AMD amdgpu-install program via APT</li></ol><pre>sudo apt-get update<br>wget https://repo.radeon.com/amdgpu-install/5.4.1/ubuntu/jammy/amdgpu-install_5.4.50401-1_all.deb<br>sudo apt-get install ./amdgpu-install_5.4.50401-1_all.deb</pre><p>2. Install the latest ROCm Driver using the amdgpu-install program</p><pre>amdgpu-install --usecase=&quot;dkms,graphics,opencl,hip,hiplibsdk&quot;</pre><p>3. Download the oneAPI for AMD GPUs (beta) installer from Codeplay <a href="https://developer.codeplay.com/products/oneapi/amd/download/">here</a>.</p><p>4. Run the installation script</p><pre>sh oneapi-for-amd-gpus-2023.0.0-linux.sh</pre><p>5. Before each build in your terminal or in your .profile, make sure the build environment is set correctly to enable the oneAPI and to find ROCm.</p><pre>. /opt/intel/oneapi/setvars.sh --include-intel-llvm<br><br>export PATH=/PATH_TO_ROCM_ROOT/bin:$PATH<br>export LD_LIBRARY_PATH=/PATH_TO_ROCM_ROOT/lib:$LD_LIBRARY_PATH</pre><h3>Sample Code and Supporting Multiple GPUs at once</h3><p>There are a lot of different codes samples you can try in the open source, oneAPI samples GitHub repository:</p><p><a href="https://github.com/oneapi-src/oneAPI-samples">GitHub - oneapi-src/oneAPI-samples: Samples for Intel oneAPI toolkits</a></p><p>From the Codeplay example you can see they created this simple-sycl-app.cpp:</p><pre>#include &lt;sycl/sycl.hpp&gt;<br><br>int main() {<br>  // Creating buffer of 4 ints to be used inside the kernel code<br>  sycl::buffer&lt;sycl::cl_int, 1&gt; Buffer(4);<br><br>  // Creating SYCL queue<br>  sycl::queue Queue;<br><br>  // Size of index space for kernel<br>  sycl::range&lt;1&gt; NumOfWorkItems{Buffer.size()};<br><br>  // Submitting command group(work) to queue<br>  Queue.submit([&amp;](sycl::handler &amp;cgh) {<br>    // Getting write only access to the buffer on a device<br>    auto Accessor = Buffer.get_access&lt;sycl::access::mode::write&gt;(cgh);<br>    // Executing kernel<br>    cgh.parallel_for&lt;class FillBuffer&gt;(<br>        NumOfWorkItems, [=](sycl::id&lt;1&gt; WIid) {<br>          // Fill buffer with indexes<br>          Accessor[WIid] = (sycl::cl_int)WIid.get(0);<br>        });<br>  });<br><br>  // Getting read only access to the buffer on the host.<br>  // Implicit barrier waiting for queue to complete the work.<br>  const auto HostAccessor = Buffer.get_access&lt;sycl::access::mode::read&gt;();<br><br>  // Check the results<br>  bool MismatchFound = false;<br>  for (size_t I = 0; I &lt; Buffer.size(); ++I) {<br>    if (HostAccessor[I] != I) {<br>      std::cout &lt;&lt; &quot;The result is incorrect for element: &quot; &lt;&lt; I<br>                &lt;&lt; &quot; , expected: &quot; &lt;&lt; I &lt;&lt; &quot; , got: &quot; &lt;&lt; HostAccessor[I]<br>                &lt;&lt; std::endl;<br>      MismatchFound = true;<br>    }<br>  }<br><br>  if (!MismatchFound) {<br>    std::cout &lt;&lt; &quot;The results are correct!&quot; &lt;&lt; std::endl;<br>  }<br><br>  return MismatchFound;<br>}</pre><h4>Building for a specific GPU</h4><p>Typically to build for our various targets we could use command lines that look like this:</p><p>NVIDIA:</p><pre>clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda simple-sycl-app.cpp -o simple-sycl-app</pre><p>AMD:</p><pre>clang++ -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=&lt;ARCH&gt; simple-sycl-app.cpp -o simple-sycl-app</pre><p>Intel:</p><pre>clang++ -fsycl -fsycl-targets=spir64 simple-sycl-app.cpp -o simple-sycl-app</pre><p>Then I would just run ./simple-sycl-app and assuming I have the right GPU in my system my application would run. Sure that’s great, but I could probably do the same thing which CUDA/ROCm by themselves using their vendor-specific programming models.</p><h4>Building for multiple vendor GPUs</h4><p>Let’s say I wanted to run for NVIDIA and Intel GPUs at the same time, I can actually create a fat binary that will run on either an NVIDIA or Intel GPU. The trick here is setting your build command line parameters appropriately to have multiple SYCL targets.</p><pre>clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64 simple-sycl-app.cpp -o simple-sycl-app</pre><p>You can see I simply set the -fsycl-targets to target both the NVIDIA and Intel GPU by separating my target with a comma. Now when I go to run my program I can do something like this:</p><pre>tonym@LianLi-Linux:~/dev/2023.0Test$ clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda,spir64 simple-sycl-app.cpp -o simple-sycl-app<br> <br>tonym@LianLi-Linux:~/dev/2023.0Test$ SYCL_DEVICE_FILTER=cuda SYCL_PI_TRACE=1 ./simple-sycl-app<br>SYCL_PI_TRACE[basic]: Plugin found and successfully loaded: libpi_cuda.so [ PluginVersion: 11.15.1 ]<br>SYCL_PI_TRACE[all]: Selected device: -&gt; final score = 1500<br>SYCL_PI_TRACE[all]:   platform: NVIDIA CUDA BACKEND<br>SYCL_PI_TRACE[all]:   device: NVIDIA GeForce RTX 3080 Ti<br>The results are correct!<br>tonym@LianLi-Linux:~/dev/2023.0Test$<br> <br>tonym@LianLi-Linux:~/dev/2023.0Test$ SYCL_DEVICE_FILTER=ext_oneapi_level_zero:gpu:0 SYCL_PI_TRACE=1 ./simple-sycl-app<br>SYCL_PI_TRACE[basic]: Plugin found and successfully loaded: libpi_level_zero.so [ PluginVersion: 11.15.1 ]<br>SYCL_PI_TRACE[all]: Selected device: -&gt; final score = 1550<br>SYCL_PI_TRACE[all]:   platform: Intel(R) Level-Zero<br>SYCL_PI_TRACE[all]:   device: Intel(R) Graphics [0x56a0]<br>The results are correct!</pre><p>You can see that I can dynamically select my target using the SYCL_DEVICE_FILTER environment variable on the command line before running my program. Note that you can also do this programmatically as well. Here is some documentation about how to do that here:</p><p><a href="https://sycl.readthedocs.io/en/latest/iface/device-selector.html">SYCL Reference documentation</a></p><h3>Future Work</h3><p>Some astute readers may notice I did not include an AMD example in my multivendor GPU example. This happens to be because I recently replaced by AMD 6800XT GPU with a brand new AMD RX 7900XT GPU. Unfortunately, ROCm does not currently install properly on my Linux system regardless of the kernel I’m using with the RDNA3 card. Once this is updated, I will come back and provide instructions with an example running on all 3 cards.</p><p>Note that previously a version of this flow worked for the 6800XT, but that was before the Codeplay software was released using the open source DPC++ flow documented here:</p><p><a href="https://intel.github.io/llvm-docs/GetStartedGuide.html">oneAPI DPC++ Compiler documentation</a></p><h3>Conclusion</h3><p>The oneAPI for NVIDIA GPUs from Codeplay allowed me to create binaries for NVIDIA or Intel GPUs easily. The time to set up the additional oneAPI for NVIDIA GPUs was about 10 minutes on top of the time to install the Intel oneAPI Base Toolkit. This included installing CUDA and the Codeplay software.</p><p>The new Codeplay software unlocks a brand new option for individuals and companies considering multivendor GPU options. Before the options were open source, community-supported compilers. This is a fantastic option and what I typically use for day-to-day work.</p><p>However for people considering longer-term support, aka businesses come to rely on toolchains for their livelihood, having an officially supported option from Codeplay and Intel can help provide peace of mind.</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter. Also, check out </em><a href="https://connectedsocialmedia.com/category/code-together/"><em>Code Together</em></a><em>, an Intel podcast for developers that I host where we talk tech.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He was architect of Intel VTune Profiler and other performance tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28b7bf4cf1d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Things Developers Should Do to Ensure Career Success]]></title>
            <link>https://medium.com/@tonymongkolsmai/5-things-developers-should-do-to-ensure-career-success-6a06b6492b66?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a06b6492b66</guid>
            <category><![CDATA[career-advice]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 02 Dec 2022 04:39:12 GMT</pubDate>
            <atom:updated>2022-12-02T04:39:12.357Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>As a professional developer, architect, manager and mentor for the last 2 decades, I’ve worked with a variety of intelligent and successful people across the tech industry. As tech undergoes another round of layoffs across the industry, I thought I’d share some thoughts on what I’ve found useful for myself and people I’ve mentored or worked with to ensure their careers are successful.</p><h4>Find Something You Are Passionate About</h4><p>This may seem silly as most of us are in the tech industry because we like technology! However, within the technology industry, there is a wide variety of focus areas. We talk about things like AI, Cloud, Frontend, Backend, etc. While the layperson may think all developers are interchangeable, the reality is we are not.</p><p>The key point here is to grow your career, you are going to want to be in an area where you are interested in constantly learning and growing your knowledge base. Domain expertise is generally more valuable than just generic programming skills. If you choose something you enjoy learning about, you have a much better chance to grow your domain expertise and hence your value to employers.</p><h4>Understand the Why</h4><p>One of the more popular trends in technology is the rise of the product manager. Product managers provide a variety of functions, but to me, the most important thing they provide is to focus on why developers should build a particular solution.</p><p>I’m not saying developers should stop being developers, if you love it, you should do it! What I am saying is that quite often we build things for ourselves, the way we want to build them, and focused on how we would want to use them. This makes total sense, we do it because we love it and because we want solutions to the problems we perceive.</p><p>Sometimes this aligns exactly with what a business needs, but quite often what a customer needs is not quite what we think we should be building. Stepping back and understanding the relationship between what the customer needs, how to provide that solution, and how your company makes money out of that solution will allow you to build the right solutions for a business and increase your value to your company.</p><p>The reality is at the end of the day, customer happiness and the revenue or benefit it provides are really what your company will value.</p><h4>Focus on communication skills</h4><p>Great developers are valuable. Great developers who can explain technical solutions to business and marketing co-workers and can translate business requirements into technical solutions are indispensable.</p><p>As developers, we often focus on writing the most optimal or most elegant solutions we can. We do that, consider it a job well done and move on. What is equally important for your career is that others understand why this elegant or optimal solution is important to the customers, or the business.</p><p>It may seem that this is just talking about something for the sake of self-promotion, which many of us shy away from. Sharing the work you’ve done is important so those who do not understand the value of a solution understand it. Not just so they think your solution is great, but so they can maintain it, leverage it, and tie it to company success.</p><h4>Don’t Assume!</h4><p>Throughout the lifecycle of any product, there are always issues that arise. When we notice a potential issue, quite often we assume others must have considered this issue and decided it isn’t an issue.</p><p>Don’t do this! Quite often people are focused on one path or one solution that they haven’t considered what you see. There is immense value in raising an issue and making sure that it has been considered.</p><p>I’m not saying do it in an inappropriate manner. As I’ve learned over many years working with groups from many countries, there is a right time and place to raise any concerns and over time you will learn how and when to do this.</p><p>If you’re early in your career or new to a company, ask someone you can trust about how to do this when you see a potential issue. Over time, you will learn how your company wants you to do this, but trust me, they want you to do this!</p><h4>Interview Every Year</h4><p>This last one is probably the one that people find the most actionable, if not the most comfortable.</p><p>I have always suggested to those I mentor, or those who report to me, to interview a few times every year. This provides a few benefits:</p><ol><li>It helps you understand what technologies are in vogue</li><li>It helps you understand what the current interview practices companies are using</li><li>Corollary to 2 and most importantly, you will be comfortable with the interview processes that exist today</li></ol><p>Interviewing is generally not a process many people are comfortable with, but like many things in life the more you do it the easier it is. This means that when you really have to do it, the more relaxed you’ll be and the better answers you’ll be able to give in the interview to showcase yourself. Also, the reality is unless you go out and interview, you never know if there is a better job out there for you.</p><h3>Conclusion</h3><p>Just as it is necessary for a developer to design and layout their code, it’s equally important for every developer to put some time and thought into how best to manage their career. These suggestions are pretty general, but I hope they are insightful for some. Good luck to you as you navigate your way through the tech industry.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a06b6492b66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PyTorch Stable Diffusion Using Hugging Face and Intel Arc]]></title>
            <link>https://medium.com/data-science/pytorch-stable-diffusion-using-hugging-face-and-intel-arc-77010e9eead6?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/77010e9eead6</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 14:37:34 GMT</pubDate>
            <atom:updated>2022-11-09T14:37:34.798Z</atom:updated>
            <content:encoded><![CDATA[<h4>Running Stable Diffusion Using an Intel GPU</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*5dIcBvoZOcsM7GjYTuN7Sg.png" /><figcaption>Image created with Stable Diffusion by the author</figcaption></figure><h3>Introduction</h3><p>Text-to-image AI models have become hugely popular in the last couple of years. One of the most popular models is Stable Diffusion, created through a collaboration between <a href="https://github.com/CompVis">CompVis</a>, <a href="https://stability.ai/">Stability AI</a> and <a href="https://laion.ai/">LAION</a>. One of the easiest ways to try Stable Diffusion is through the <a href="https://huggingface.co/blog/stable_diffusion">Hugging Face Diffusers library</a>.</p><p>With the release of the latest Intel® Arc™ GPU, we’ve gotten quite a few questions about whether the Intel Arc card supports running Tensorflow and PyTorch models, and the answer is YES! Built using the oneAPI specification, the <a href="https://www.intel.com/content/www/us/en/developer/articles/guide/optimization-for-tensorflow-installation-guide.html">Intel® Optimization for TensorFlow*</a> and <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/extension-for-pytorch.html">Intel® Extension for PyTorch</a> allow users to run those frameworks on the latest Intel GPUs.</p><p>To help people understand how to get PyTorch up and running on an Intel GPU, this post will present a quick walkthrough of how we get one of the more fun AI workloads in the last couple of years up and running on the Intel Arc A770 GPU.</p><h3>Setup</h3><p>From my <a href="https://medium.com/@tonymongkolsmai">previous posts</a>, you may know I have an Intel Alder Lake Core i9–12900KF Alienware R13 system. I actually will not be using that system as the base for this walkthrough since I just put together a Raptor Lake 13th Gen Intel® Core™ i7-13700KF system using an MSI z690 Carbon WiFi motherboard with 64GB of 5600 DDR5 RAM and a brand new Intel Arc A770 for my testing. The system is running a fresh install of Ubuntu 22.04.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rM5f_vsCVfNHOQbZQ8aE_A.png" /><figcaption>Test System image courtesy of the author</figcaption></figure><h3>Stable Diffusion on Intel Arc</h3><p>With that as the hardware base, let’s go through all the steps required to get Stable Diffusion up and running on this system.</p><h4>Setting up the Base Software Stack</h4><p>First, we need to install the Intel Arc drivers and the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit.html">Intel® oneAPI Base Toolkit</a>, so we follow the instructions here:</p><p><a href="https://www.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top.html">Intel® oneAPI Toolkits Installation Guide for Linux* OS</a></p><p>Specifically, I am using the APT instructions located <a href="https://www.intel.com/content/www/us/en/develop/documentation/installation-guide-for-intel-oneapi-toolkits-linux/top/installation/install-using-package-managers/apt.html#apt">here</a>, taking special care to follow the instructions in the install the Intel GPU drivers (step 2) exactly. I tried this with the drivers included in the Linux 6.0.x kernel and ran into some issues, so I would recommend you try the DKMS instructions and use the kernel 5.17.xxx in the instructions.</p><p>Since we will be using Hugging Face repositories, we install Git and Git Large File Storage (Git LFS) as the Hugging Face repositories require them.</p><pre>&gt; sudo apt-get install git git-lfs</pre><h4>Python Setup</h4><p>Let’s next set up our Python environment to work with Intel Arc. I’m using Python 3.9.15, so if you have a different version of Python the instructions may vary a little.</p><p>Since this was a fresh Ubuntu installation and I do not have the pip Python package manager installed for some reason, the quick fix is to run:</p><pre>&gt; wget <a href="https://bootstrap.pypa.io/get-pip.py">https://bootstrap.pypa.io/get-pip.py</a><br>&gt; python get-pip.py</pre><p>There are quite a few ways to install pip, depending on your version of Ubuntu you may be able to use APT directly.</p><p>To keep our Python environment clean, we can set up the Python virtualenv module and create a virtual environment.</p><pre>&gt; python3 -m pip install --user virtualenv<br>&gt; python3 -m venv venv<br>&gt; source venv/bin/activate</pre><p>Every step after this will be run in our Python virtual environment.</p><h4>Hugging Face Setup</h4><p>The next step is setting up Stable Diffusion. Mostly we are just following the <a href="https://huggingface.co/blog/stable_diffusion">Hugging Face instructions here</a>, but I’ll inline them to make it easier.</p><p>If you don’t have a Hugging Face account, you need to go create one here:</p><p><a href="https://huggingface.co/">Hugging Face - The AI community building the future.</a></p><p>Back on our system, we set up Hugging Face Hub and some base libraries and grab the Diffusers and Stable Diffusion code from Hugging Face:</p><pre>&gt; pip install transformers scipy ftfy huggingface_hub<br>&gt; git clone <a href="https://github.com/huggingface/diffusers.git">https://github.com/huggingface/diffusers.git</a><br>&gt; git clone <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4">https://huggingface.co/CompVis/stable-diffusion-v1-4</a> -b fp16</pre><p>These checkouts should ask you to log in using the huggingface-cli which looks like this:</p><pre>Username for ‘<a href="https://huggingface.co&/#39;">https://huggingface.co&#39;</a>: &lt;your_user_name&gt;<br>Password for ‘<a href="https://tonym-intel@huggingface.co&/#39;">https://</a>&lt;your_user_name&gt;<a href="https://tonym-intel@huggingface.co&/#39;">@huggingface.co&#39;</a>:</pre><p>The final steps are to install some base components the Diffusers library needs and the library itself using pip and pointing it to the diffusers directory:</p><pre>&gt; pip install diffusers</pre><h4>PyTorch and Intel Extensions For PyTorch Setup</h4><p>Finally, we need to set up our Intel GPU configuration. Download PyTorch and the Intel Extensions for PyTorch:</p><pre>&gt; wget <a href="https://github.com/intel/intel-extension-for-pytorch/releases/download/v1.10.200%2Bgpu/intel_extension_for_pytorch-1.10.200+gpu-cp39-cp39-linux_x86_64.whl">https://github.com/intel/intel-extension-for-pytorch/releases/download/v1.10.200%2Bgpu/intel_extension_for_pytorch-1.10.200+gpu-cp39-cp39-linux_x86_64.whl</a><br>&gt; wget <a href="https://github.com/intel/intel-extension-for-pytorch/releases/download/v1.10.200%2Bgpu/torch-1.10.0a0+git3d5f2d4-cp39-cp39-linux_x86_64.whl">https://github.com/intel/intel-extension-for-pytorch/releases/download/v1.10.200%2Bgpu/torch-1.10.0a0+git3d5f2d4-cp39-cp39-linux_x86_64.whl</a></pre><p>And install the wheels using pip:</p><pre>&gt; source /opt/intel/oneapi/setvars.sh<br>&gt; pip install torch-1.10.0a0+git3d5f2d4-cp39-cp39-linux_x86_64.whl<br>&gt; pip install intel_extension_for_pytorch-1.10.200+gpu-cp39-cp39-linux_x86_64.whl</pre><p>Everything should now be set up to run a PyTorch workload on the Intel Arc GPU. If you optionally want to use the low CPU memory usage mode, you can install the accelerate library. This step should be done AFTER installing the Intel wheels otherwise you will get some errors in NumPy.</p><pre>&gt; pip install accelerate</pre><h4>Running Stable Diffusion</h4><p>On to the fun part! Stable Diffusion is ready to use through the Hugging Face Diffusers library and the Intel Arc GPU is ready to accelerate it courtesy of oneAPI. To make it easy to run, I created this simple Python script that prompts the user for input and then opens the resulting output image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edb5e960af0ee23f8e1fd95c5aba27cf/href">https://medium.com/media/edb5e960af0ee23f8e1fd95c5aba27cf/href</a></iframe><p>We can simply run the script, type something in and see the output:</p><pre>&gt; python run-stable-diffusion.py<br>Enter keywords:<br>AI GPU image for medium post</pre><p>which output the image at the top of this post.</p><h3>Conclusion</h3><p>Support for PyTorch and Tensorflow on discrete Intel GPUs is here! While many are excited about how Intel GPUs may affect the gaming GPU market, there are plenty of people who use GPUs for accelerated non-gaming workloads.</p><p>Just as <a href="https://code.blender.org/2022/09/intel-arc-gpu-support-for-cycles/">Intel GPU support for Blender</a> was exciting for many, the support for the popular AI frameworks is just another waypoint for the Intel GPU story. For those of us who do rendering, video editing, AI and other compute workloads, now is the time to get excited about Intel GPUs.</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter. Also, check out </em><a href="https://connectedsocialmedia.com/category/code-together/"><em>Code Together</em></a><em>, an Intel podcast for developers that I host where we talk tech.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He has worked on several software developer tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><p><em>Intel and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77010e9eead6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/pytorch-stable-diffusion-using-hugging-face-and-intel-arc-77010e9eead6">PyTorch Stable Diffusion Using Hugging Face and Intel Arc</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Deep Learning Enables Large-Scale Scientific Visualization]]></title>
            <link>https://medium.com/data-science/how-deep-learning-enables-large-scale-scientific-visualization-f574408a6b43?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f574408a6b43</guid>
            <category><![CDATA[science]]></category>
            <category><![CDATA[intel]]></category>
            <category><![CDATA[rendering]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 28 Oct 2022 15:36:57 GMT</pubDate>
            <atom:updated>2022-10-30T11:33:25.460Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using Neural Networks to Compress Information for Interactive Rendering</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eK7E5A3uDp1PoLO9mth8Yg.png" /><figcaption>Samples from Previous Work by the UC Davis VIDI group. Image courtesy of UC Davis VIDI group</figcaption></figure><h3>Introduction</h3><p>One of the great joys as a Software Architect and Technology Evangelist at Intel is the opportunity to see the fantastic work done by oneAPI Centers of Excellence (CoE) worldwide. Recently, the UC Davis Visualization &amp; Interface Design Innovation (VIDI) Lab shared how they are using deep learning for performant, interactive scientific visualization.</p><h4>Why does this matter?</h4><p>Scientific simulations and modeling have become exponentially more detailed in recent years. A simulation can easily generate hundreds of terabytes of data. For simulation models that result in a 3D representation of data, the best way to understand the simulation output is to visually inspect and examine it using a real-time renderer.</p><p>As one can imagine, rendering terabytes of data with high-fidelity methods like <a href="https://en.wikipedia.org/wiki/Ray_marching">ray marching</a> (think more advanced ray tracing) and <a href="https://en.wikipedia.org/wiki/Path_tracing">path tracing</a> using even the most powerful GPUs is challenging. A pure, brute-force rendering algorithm and standard compression algorithms don’t provide the performance or compression rates required to support real-time interaction at this scale. While seeing a rendering of simulation output is extremely valuable even at 1 frame per second (fps), providing an actual interactive rendering, say at 30fps, provides a significantly more useful experience for researchers.</p><p>This is where the work done by Professor Kwan-Liu Ma and his team: David Bauer and Qi Wu comes in. They combine the latest research in deep learning and rendering to provide something truly remarkable.</p><h3>Instant Neural Representation for Compression</h3><p>One of the great challenges mentioned above is compressing data and then quickly decompressing large data sets fast enough to enable a real-time, interactive rendering. If we are looking at rendering at 30fps, the decompression time of simulation data must be less the 33.3 milliseconds.</p><h4>Compression Types and Rates</h4><p>The second piece of the puzzle is compression rates. Compression algorithms may be lossless, meaning it is possible to recover the original input data exactly as it was created. They may also be lossy, meaning it is impossible to recreate the original data from the compressed representation. As one may expect, in general, lossless algorithms tend to result in smaller compression rates.</p><p>The typical compression that people use every day are things like zip, mp3 and JPEG. The former is lossless and may achieve compression rates of around 3:1. The latter are lossy and typically achieve compression rates of around 20:1 and 10:1. That means the largest compression ratio for these typical algorithms is about 1/20 the size of the original data.</p><p>For the purposes of real-time rendering, the main features one would look for are fast decompression and relatively minimal data loss. However, a compression rate of 20:1 may not be enough for many use cases.</p><h4>Instant Neural Representation to the Rescue</h4><p>As we’ve seen in the last 10 years, modern neural networks are extremely good at encoding information and decoding it quickly. These two characteristics make neural networks ideally suited as a compression method for large-scale data sets.</p><p>Another useful characteristic of using neural networks for compression is that, unlike most compression algorithms, the representation does not grow in size as the data set size grows. One would expect that as data complexity grows, the static representation becomes more lossy.</p><p>However, given a large enough network, this degradation is not linear. Because of the huge simulation model sizes, a large neural network may be used which results in good compression ratios and minimal information loss as the data set size grows. The VIDI team reports results that “10–1000x smaller than raw data and trained almost instantaneously using MLP and hash-grid encoding”¹</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*1nd2zw2HL3FkHeeBrdG0Nw.png" /><figcaption>Figure 1: Instant Neural Representation (VNR) quality versus naive method at a similar compression rate. Image courtesy of UC Davis VIDI group</figcaption></figure><p>We can clearly see the value of this compression algorithm versus traditional algorithms in Figure 1.</p><h4>Creating the Representation</h4><p>To train the model for compression, the VIDI team had to take the 3D simulation information and convert it into something that fits into a standard machine-learning workflow. Logically this was a relatively standard machine learning flow:</p><ol><li>Grab random samples of data in the 3D space</li><li>Encode each sample using a hash-grid encoding to create the tensor to pass to the DL model</li><li>Train the model for the sample points against the real sample output</li></ol><p>To make this as performant as possible, the VIDI team used the Intel® Open Volume Kernel Library, an implementation of the oneAPI OpenVKL specification, to generate training samples from the ground truth for the training stage. OpenVKL is helpful here because it enables efficient traversal and sampling of volumetric data.</p><p>With the right configuration, training the model for around 20k steps takes less than a minute. The result of this is a reasonable <a href="https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio">peak signal-to-noise ratio</a> (PSNR) of around 30dB in most cases and upwards of around 49dB in some datasets. For those unfamiliar with PSNR, it is measured in decibels (dB). The higher the value the closer the image is to the original.</p><h4>Closing the Rendering Gaps</h4><p>While Instant Neural Representation is impressive, alone it may not be enough to provide a performant, real-time interactive experience. To bridge this gap, the UC Davis VIDI team also has developed several sampling and rendering algorithms for Instant Neural Representation data.</p><p>Unfortunately, the techniques here are outside the scope of this post, but you can check out the details of the <a href="https://arxiv.org/abs/2207.11620v2">Instant Neural Representation and the associated rendering optimizations</a>.</p><p>Of course, the more fun thing is to see how all of this fits together to enable a truly interactive experience. You can see in the video below how quickly an Instant Neural Representation can be trained and the impressive results achieved by the UC Davis VIDI team.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fc4G-cWJW6PU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dc4G-cWJW6PU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fc4G-cWJW6PU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dc1125d1b3039c4a67fc6521c66a676/href">https://medium.com/media/2dc1125d1b3039c4a67fc6521c66a676/href</a></iframe><h3>Conclusion</h3><p>I’ve always thought of DL as a technology that can solve extremely complex problems that required a large solution space; I had not considered how it can be used to provide heuristic solutions to problems with “well-known” solutions. The Instant Neural Representation is a great example of taking the power of DL models and using it as a heuristic optimization of some data that can tolerate some level of lossy translation.</p><p>Techniques like Instant Neural Representation are enabling useable, real-time interaction with increasingly complex simulation data. Just to emphasize the difference between a 1fps interaction to a 60fps interaction, check out this fun video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEaa-V49GNLs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEaa-V49GNLs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEaa-V49GNLs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e577e3107025b3982e5c2888b62eff22/href">https://medium.com/media/e577e3107025b3982e5c2888b62eff22/href</a></iframe><p>I’m excited and optimistic that novel solutions like this will continue to drive scientific discovery. Enabling a 30+ fps interaction with simulation model data can be a game changer for scientists who will no longer have to live through the slideshow-type interaction with their data.</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter. Also, check out </em><a href="https://connectedsocialmedia.com/category/code-together/"><em>Code Together</em></a><em>, an Intel podcast for developers that I host where we talk tech.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He has worked on several software developer tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><h3>References</h3><p>[1] Qi Wu, David Bauer, Michael J. Doyle, Kwan-Liu Ma, <a href="https://arxiv.org/abs/2207.11620v2">Instant Neural Representation for Interactive Volume Rendering</a>, 2022, <a href="https://arxiv.org/abs/2207.11620v2">https://arxiv.org/abs/2207.11620v2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f574408a6b43" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-deep-learning-enables-large-scale-scientific-visualization-f574408a6b43">How Deep Learning Enables Large-Scale Scientific Visualization</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronized Code — Unlocking the Power of Accelerator and Parallel Programs]]></title>
            <link>https://medium.com/better-programming/synchronization-letting-accelerator-parallel-developers-run-free-809573b3b86a?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/809573b3b86a</guid>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[c-plus-plus-language]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 10:51:00 GMT</pubDate>
            <atom:updated>2022-10-21T16:58:12.096Z</atom:updated>
            <content:encoded><![CDATA[<h3>Synchronized Code — Unlocking the Power of Accelerator and Parallel Programs</h3><h4>Locks, semaphores, critical sections, and other synchronization constructs used to prevent crashes and bugs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uge6zCH-b6Groid6" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=medium&amp;utm_medium=referral">FLY:D</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my last article, <a href="https://betterprogramming.pub/an-accelerated-and-parallel-programming-introduction-2f91420fb4f0">An Introduction to Accelerator and Parallel Programming</a>, we talked about the basics of parallel programming, including some simple ways to take a program and run it on multiple CPUs or an accelerator. Of course, that post only scratched the surface of parallel and accelerated programming challenges.</p><p>In general, these types of programming use an asynchronous model of execution, meaning that multiple computations will be happening in a system at the same time. The challenge is ensuring that this execution is fast and correct.</p><p>In this post, I will talk about making sure programs run correctly using synchronization.</p><h3>Threads</h3><p>First, a little detour into the term “thread,” mostly because it will be easier to type thread versus a part of your program that is executing simultaneously with another part of your program and doing so over and over on a piece of hardware.</p><p>In the context of your parallel program, you write your code, which may run on multiple processors simultaneously. Each piece of simultaneously running code is a thread. This may sound complex, but fortunately, most programming paradigms allow us to focus on what to parallelize and how we want it parallelized without having to focus on the nitty-gritty details of using threads.</p><h3>Synchronization</h3><p>Synchronization constructs enforce an ordering of execution for our threads. As we allow threads to run, there are a variety of things we need to consider to make sure our program behaves the way we expect, including:</p><ol><li>Are multiple threads trying to access a shared resource at the same time?</li><li>Do multiple threads need to complete their work before moving to the next part of the program?</li><li>Are there issues that will cause our program to hang such that all threads are waiting for each other for some reason?</li></ol><h4>Why does synchronization matter?</h4><p>Imagine we want to do something simple like count the number of people in a stadium, and we have three people doing the counting. A simple algorithm would be:</p><p>1. split the stadium into sections</p><p>2. assign each section to one of the three people counting</p><p>3. have each person count the people in their assigned sections</p><p>4. sum the value from each of the three people into one total for the entire stadium</p><p>This seems straightforward, but there is a catch: To sum the values in step 4, each person has to read what the current total is, add to that value, and then write the updated total on the paper for everyone else to see. So, in reality, it is actually three actions that must happen (read, add, write) to update the total.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*ovDFv2JbEP9qm-od0WA1Dw.png" /><figcaption>figure 1</figcaption></figure><p>Per Figure 1, the correct answer to this problem is 18. Each thread has a variable, local_count that is created and used only in that thread, which means counting the sections is independent of other threads. However, when threads go to update the shared total value, there is a potential issue.</p><p>Let us suppose Thread 1 and Thread 2 simultaneously attempt to update Total. It is possible they both read a value of 0 for the total and then add their local_count to it, meaning they think the updated value for Total should be 0+4=4 or 0+6=6, respectively. When they go to update Total, the output could be 4 or 6.</p><p>In either case, the outcome after both threads update the total should actually be 10. This is a data race and why synchronization is important to correctness. We need to ensure that the update to the shared variable is done one at a time. Here’s a simple example of what this might look like using OpenMP:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9835772e4222f32f94a9ba0a31a18fa/href">https://medium.com/media/a9835772e4222f32f94a9ba0a31a18fa/href</a></iframe><p>There are three distinct OpenMP compiler directives at work in this example.</p><ul><li><em>omp parallel sections </em>— tells the compiler to run each section within the following block of code in parallel (aka each section on its thread). The sections pragma also waits until each individual section in the block is completed.</li><li><em>omp section</em> — tells the compiler the following block of code is a complete section that can be run on a thread.</li><li><em>omp critical</em> — tells the compiler to allow only one thread to execute the following block of code, which is just the one-line addition to the total.</li></ul><p>To compile the code, I used the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html">Intel® oneAPI DPC++/C++ Compiler</a>, which supports OpenMP, using the following commands:</p><pre>&gt; icx count_sections_omp.cpp -o serial.exe<br>&gt; icx -fopenmp count_sections_omp.cpp -o parallel.exe</pre><p>The first command compiles without OpenMP enabled, while the second command tells the compiler to use the OpenMP pragmas. My test system, in this case, is my HP Envy 16&quot; laptop powered by an Intel® Core™ i7–12700H processor with 32GB of RAM. Running the two executables looks like this:</p><pre>&gt;serial.exe<br>Total=18<br>Elapsed time in milliseconds: 1570 ms<br>&gt;parallel.exe<br>Total=18<br>Elapsed time in milliseconds: 520 ms</pre><p>You can see the difference in runtime between the parallelized code and the code running on only one CPU.</p><p>Just for fun, I removed the #pragma omp critical directives from my code and ran it a few times. After a few tries, I got this output:</p><pre>&gt;parallel.exe<br>Total=14<br>Elapsed time in milliseconds: 520 ms</pre><p>In this case, you can see that the value from the first section (with a value of 4) was somehow missed since each thread did not add to the total in a serialized fashion.</p><h4>Resource sharing synchronization</h4><p>There are quite a few synchronization constructs that protect access to resources, and I will not be able to give code examples for all of them. So to allow you to dive in a little more, I’ll list a few and what they are generally used for:</p><ul><li>critical section — allows only one thread to run code protected by the critical section at once.</li><li>lock/mutex — protects a code section by asking each thread to explicitly request access via a lock before running some code. This is different from a critical section as there are cases where multiple threads may access a shared resource simultaneously (e.g., a reader/writer paradigm to be discussed below).</li><li>semaphores — given a predefined number N; this allows only N users to run their code simultaneously.</li></ul><p>Note that synchronization, if used inappropriately, can result in incorrect results and issues where threads fail to make progress or hang.</p><h3>The Reader/Writer Paradigm</h3><p>One of the parallel programming paradigms often used is that of the reader/writer. This synchronization is used when there are two types of users accessing some shared values in memory:</p><ul><li>reader — needs to know the shared value</li><li>writer — needs to update a shared value</li></ul><p>If you think about it, multiple readers can look at a value simultaneously, as they will always see the same value as the rest. However, when a writer needs to update the value, it must prevent others from reading or writing it. This ensures the value is consistent across all readers and writers in the program.</p><p>To make this more concrete, let’s look at an example of what this looks like in SYCL and how the usage of the reader/writer affects the behavior and performance of your program.</p><h4>Reader/Writer SYCL example</h4><p>Let’s look at how SYCL uses reader/writer synchronization to control access to an array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd6558e161385183b71b49d429e4a177/href">https://medium.com/media/dd6558e161385183b71b49d429e4a177/href</a></iframe><p>You can see the read and write functions are basically the same. Some key things to understand:</p><ul><li>line 18 — Read() creates a sycl::access::mode::read accessor</li><li>line 34 — Write() creates a sycl::access::mode::write accessor</li><li>lines 16 and 32 — submit to the queue of the compute device of choice. This is asynchronous, so the code returns before the task is completed</li><li>lines 25 and 41 — put a single task into the queue to be executed</li></ul><p>Also, to make the test more understandable, I set the doWork() function to run for about one second on my particular machine by turning the WORK_ITERS variable. If you test this yourself, you may want to try adjusting that to make the test faster or slower.</p><p>Now that we have our core read and write functions, let’s look at how the read versus write access mode affects a program:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbede24a8dd47e05ba8a65f2e63bfb83/href">https://medium.com/media/fbede24a8dd47e05ba8a65f2e63bfb83/href</a></iframe><p>For this program, the lines of interest are 25–41, and each loop iterates NUM_ACCOUNTS (8) times. Considering how reader/writer synchronization works, the time to run this should be:</p><ul><li>lines 25–28: perform eight reads of our buffer (one second, happen in parallel)</li><li>lines 31–34: perform eight writes of our buffer (eight seconds, runs in order)</li><li>lines 37–40: perform eight writes of our buffer (one second, happen in parallel)</li></ul><p>Note that line 41 causes the program to wait for all the asynchronous operations in the queue to complete before proceeding.</p><p>Once again, I used the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html">Intel DPC++ Compiler</a> to compile my code and run it:</p><pre>&gt;icx -fsycl read_write_sycl.cpp<br>&gt;read_write_sycl.exe<br>Running on device: 12th Gen Intel(R) Core(TM) i7-12700H<br>Pass<br>Elapsed time in milliseconds: 11105 ms</pre><p>Our elapsed runtime is close to our expected value of 10 seconds.</p><h4>Reader/Writer versus critical section</h4><p>To understand the value of the reader/writer, imagine if, instead of the reader/writer construct, we used a locking mechanism where both a read and write are treated as needing exclusive access.</p><p>To simulate this, I updated line 18 in my Read() as follows to use a write lock (single access at a time):</p><pre>auto acc = buf.get_access&lt;sycl::access::mode::read&gt;(h);<br>auto acc = buf.get_access&lt;sycl::access::mode::write&gt;(h);</pre><p>Recompiling my code and rerunning it, I get the following output:</p><pre>&gt;read_write_sycl.exe<br>Running on device: 12th Gen Intel(R) Core(TM) i7–12700H<br>Pass<br>Elapsed time in milliseconds: 24035 ms</pre><p>Comparing how the code should run versus the reader/writer code the breakdown is as follows:</p><ul><li>lines 25–28: perform eight reads of our buffer (eight seconds, runs in order)</li><li>lines 31–34: perform eight writes of our buffer (eight seconds, runs in order)</li><li>lines 37–40: perform eight writes of our buffer (eight seconds, runs in order)</li></ul><p>This would suggest a reader/writer is always better, but that is not true. A reader/writer lock is a more complicated synchronization construct with more runtime overhead, so keep that in mind as you choose what synchronization to use.</p><p>If you’re interested in SYCL and how it helps you protect data with synchronization constructs, you can check out this <a href="https://www.intel.com/content/www/us/en/events/on365/sycl-basics.html">introduction to SYCL basics video</a>.</p><h3>Conclusion</h3><p>Accelerator and parallel programming can give us faster applications and programs when used correctly. But as with most things in life, benefits do not always come for free. In this case, as we look to run our programs on ever faster and more diverse compute hardware, we must also learn and understand APIs that help us face the challenges accelerator and parallel computing present.</p><p>This post just scratches the surface of synchronization and the pitfalls of accelerator programming. Next time I’ll talk about why having a basic understanding of your target accelerator architecture may matter to you as you program for performance.</p><pre><strong>Want to Connect?</strong></pre><pre>If you want to see what random tech news I’m reading, you can <a href="https://twitter.com/tonymongkolsmai">follow me</a> on Twitter. Also, check out <a href="https://connectedsocialmedia.com/category/code-together/">Code Together</a>, an Intel podcast for developers that I host where we talk tech.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=809573b3b86a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/synchronization-letting-accelerator-parallel-developers-run-free-809573b3b86a">Synchronized Code — Unlocking the Power of Accelerator and Parallel Programs</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming Intel Arc Xe Matrix Extensions (XMX) with oneAPI]]></title>
            <link>https://medium.com/data-science/utilizing-intel-arc-xe-matrix-extensions-xmx-using-oneapi-bd39479c9555?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd39479c9555</guid>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[oneapi]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 14 Oct 2022 13:12:45 GMT</pubDate>
            <atom:updated>2022-10-17T18:06:21.680Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using the joint_matrix API to drive the latest Intel acceleration technologies</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQZ4BCauXfCJV-EHrITx2w.png" /><figcaption>Image courtesy of the author</figcaption></figure><h3>Introduction</h3><p>With the release of the <a href="https://www.intel.com/content/www/us/en/products/details/discrete-gpus/arc.html">Intel® Arc™ Graphics</a> desktop GPU, developers have some new hardware accelerator options to play with. As an Intel software architect and performance enthusiast, the first thing I always think of is how I can use new hardware to solve my problem faster. With Arc, the first thing I wanted to try was the Intel Xᵉ Matrix Extensions (XMX) hardware and its dedicated matrix engines.</p><h4>Why does this matter?</h4><p><a href="https://www.tensorflow.org/guide/tensor">Tensor</a> operations are at the heart of deep learning workloads. One of the fundamental acceleration capabilities of Intel XMX is dedicated hardware to perform matrix operations, which higher-level tensor operations decompose into. For most AI end users, Tensorflow and PyTorch will be the level in the software at which we use this hardware. However, another class of users/developers like myself are also looking at this and thinking, how can I program this new hardware directly and use it for some other purpose?</p><h3>oneAPI joint_matrix</h3><p>As with most hardware, there are a few ways to program for XMX accelerators. You can write GPU assembly or use GPU intrinsics. For you brave folks, I would refer you to the <a href="https://www.intel.com/content/www/us/en/develop/documentation/oneapi-gpu-optimization-guide/top.html">oneAPI GPU optimization guide</a> as a starting point. I wanted to try something simpler. Fortunately for us, there is an experimental <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview.html">oneAPI</a> extension, <a href="https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_matrix.asciidoc">joint_matrix</a>, that allows us to program the hardware using a higher-level API.</p><p>In addition to supporting Intel hardware, the joint_matrix C++ API allows us to perform matrix operations on a variety of hardware. From the <a href="https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_matrix.asciidoc#introduction">joint_matrix introduction</a>:</p><blockquote>This interface is intended to unify different tensor hardware: Intel AMX in CPUs, Habana Gaudi and Goya tensor and gemm cores, Nvidia TPUs, IBM Power MMA. All these hardware provide low-level intrinsics or assembly to access and perform matrix operations. The goal is to provide a unified interface that is portable but also benefits from the maximum performance these different hardware can offer.</blockquote><h3>The Fun Part: Testing the Intel Arc A750</h3><p>I have a brand new Intel Arc A750 card I just put into my personal Intel Alder Lake Core i9–12900KF Alienware R13 system. I also happen to be using Windows, so the instructions below may be slightly different if you are using Linux or WSL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrZQLm5uGoNP4JL1lqucWg.png" /><figcaption>Image courtesy of the author</figcaption></figure><h4>Breaking down a joint_matrix Matrix Multiply Example</h4><p>My goal is to just exercise the hardware with some simple matrix operations. I am starting with <a href="https://github.com/intel/llvm-test-suite/blob/intel/SYCL/Matrix/joint_matrix_bfloat16.cpp">an example from the Intel llvm-test-suite</a> that runs a hardware-accelerated matrix multiply using bfloat16 and ensures the output is the same as using a simple CPU matrix multiply.</p><p>I modified the test a little bit to output which accelerator hardware the matrix multiply is running on. Here’s the snippet of code used to perform the joint_matrix enabled matrix multiply:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f43210f8b8ac556ca28a1d911bd7044/href">https://medium.com/media/3f43210f8b8ac556ca28a1d911bd7044/href</a></iframe><p>Here are some high-level things to note in the code:</p><ul><li>Lines 1–11: The big_matrix class allows us to represent an arbitrary-sized matrix.</li><li>Lines 23–27: The device selector shows us which accelerator the algorithm is running on</li></ul><p>Since a large matrix will not always fit into the hardware, the matrix multiply operation is performed by decomposing the two matrices to be multiplied into subgroups and then accumulating the result of multiplying these subgroups into the proper parts of the output matrix. The operations are the same as when we do a naive matrix multiply, just in a slightly different order since we don’t iterate over the entire column space before moving to the next row.</p><p>The core breakdown of how the matrix multiply is happening above is as follows:</p><ul><li>Line 36: the parallel_for is splitting the work based on the 2-dimensional nd_range — this is how we are walking over the matrix space.</li><li>Lines 49–56: sub_a, sub_b, sub_c are initialized. Since the hardware cannot hold the whole matrix in memory, the algorithm is loading parts of the matrix into the hardware accelerator + registers using the joint_matrix API. sub_a and sub_b are the fragments of the matrices being multiplied, and sub_c is our target output matrix</li><li>Line 58: use the joint_matrix_fill API to not load the values from memory but instead directly initialize the register to a value. In this case, the value I initialized the register to is 0.</li><li>Line 64–71: load the parts of the matrix to multiply and accumulate into our output matrix</li><li>Lines 72: perform a matrix multiply and add using sub_a and sub_b as inputs and sub_c as the target using the XMX accelerator</li><li>Lines 74–77: store the in-progress output values for this part of the matrix computation back to memory</li></ul><p>For reference, here is my complete <a href="https://gist.github.com/tonym97/783c8ba9cc29b67370648d9883f8de00">joint_matrix_bfloat16_modified.cpp</a></p><h4>Testing the Accelerator Matrix Multiply</h4><p>Since this is using an experimental extension to oneAPI, this requires the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html">Intel® oneAPI DPC++/C++ Compiler</a>. I am using the latest version from the <a href="https://intel.com/content/www/us/en/developer/articles/news/oneapi-2022-3-available.html">Intel® oneAPI Base Toolkit 2022.3</a> release.</p><p>This functionality has been enabled since the 2022.1 release, but some of the namespaces were updated. For example, the following namespace was updated from the former to the latter:</p><pre>sycl::ext::intel::experimental::bfloat16<br>sycl::ext::oneapi::experimental::bfloat16</pre><p>To compile this example, run the following commands after installing the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit.html">Intel® oneAPI Base Toolkit</a> and following the <a href="https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html">environment configuration steps</a>:</p><pre>&gt; icx /EHsc /fsycl joint_matrix_bfloat16_modified.cpp</pre><p>After compiling the code, we simply run the executable:</p><pre>&gt; joint_matrix_bfloat16_modified.exe<br>Running on device: Intel(R) Arc(TM) A750 Graphics<br>Elapsed time in milliseconds (accelerated): 142 ms<br>Elapsed time in milliseconds (reference): 2118 ms<br>passed</pre><p>We can see that the matrix multiply was performed in 142 milliseconds using the Intel Arc GPU, and the non-accelerated version ran in 2118 milliseconds on the CPU. Note that if you try to run the accelerated version on hardware that does have support matrix operations, the current behavior as defined by the API is to report a failure due to a lack of supported matrix accelerator hardware. This prevents a user from unknowingly using a slower, fallback matrix implementation instead of the hardware-accelerated version.</p><h3>Enabling Multiple Accelerators</h3><p>The joint_matrix API is not just designed for portability in the abstract. The latest Intel DPC++ compiler has hardware support for Intel XMX, Intel® Advanced Matrix Extensions (AMX) and NVIDIA Tensor Cores. For those unfamiliar, AMX is the new x86 instruction set for matrix multiplication acceleration that utilizes hardware built into the upcoming 4th Gen Intel Xeon Scalable processors. If you are interested in Tensor Cores, there is an example you can compile and run <a href="https://github.com/intel/llvm-test-suite/blob/intel/SYCL/Matrix/joint_matrix_tensorcore.cpp">here</a>. It does require the open source <a href="https://intel.github.io/llvm-docs/GetStartedGuide.html">Intel DPC++ Compiler built with NVIDIA backend support</a>, as well as installing NVIDIA CUDA, so I will save that for a separate post.</p><p>For more details on what other functionality the joint_matrix API enables, see the API documentation:</p><p><a href="https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_matrix.asciidoc">llvm/sycl_ext_oneapi_matrix.asciidoc at sycl · intel/llvm</a></p><h3>Conclusion</h3><p>New hardware capabilities mean new programming abstractions. These abstractions may exist at many levels. While joint_matrix is a way to directly program the hardware, in future posts I will talk about how the Intel implementation of oneAPI libraries and popular AI/ML frameworks such as TensorFlow and PyTorch will take advantage of matrix accelerators like XMX and AMX.</p><p>If you have made it this far, you probably want fine-grain control of the hardware just like I do, which is why an API like joint_matrix is exciting. The joint_matrix API is available and ready to help you take advantage of some of the new matrix hardware available. I encourage you to download the toolchain, give the API a try, and provide feedback to help shape this exciting cross-vendor, matrix API.</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He has worked on several software developer tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><p><em>Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd39479c9555" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/utilizing-intel-arc-xe-matrix-extensions-xmx-using-oneapi-bd39479c9555">Programming Intel Arc Xe Matrix Extensions (XMX) with oneAPI</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Accelerator and Parallel Programming]]></title>
            <link>https://medium.com/better-programming/an-accelerated-and-parallel-programming-introduction-2f91420fb4f0?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f91420fb4f0</guid>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[oneapi]]></category>
            <category><![CDATA[c-plus-plus-language]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 17:58:59 GMT</pubDate>
            <atom:updated>2022-10-19T21:47:46.492Z</atom:updated>
            <content:encoded><![CDATA[<h4>Accelerators are continuing to grow in importance and usage, what does this mean for developers?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GJdQxXxIrkgxIH_B" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Computers are a means to an end. They allow us to have faster solutions to complex problems, provide the ability to store and retrieve information across the globe, provide the backbone for remarkable technologies like robotics and self-driving cars (sort of) and AI, and hopefully uplift the lives of everyone on the planet. As the problems to solve have become more complex, computer architecture, programming languages, and programming models have continued to evolve. This has led to the growth of hardware accelerators and domain-specific programming models.</p><p>Professor David Patterson from UC Berkeley (the author of all the computer architecture books I had in college) has <a href="https://hipporeads.com/uc-berkeleys-david-a-patterson-sees-the-future-after-moores-law/">talked extensively about domain-specific architectures</a> and accelerators. Today, when we talk about a hardware accelerator, we are often talking about a GPU. However, there are myriad different types of accelerators that have arisen to solve various problems — including deep learning and AI — which utilize hardware specifically designed to perform large-scale matrix operations, the heart of DL workloads.</p><p>In addition, there are hardware acceleration technologies built into traditional CPUs like Intel® Advanced Vector Extensions (AVX) and Intel® Advanced Matrix Extensions (AMX).</p><p>With the rise of new accelerators, there is always the challenge of how to program for that accelerator. Most accelerators currently available are based on parallel execution and hence some form of parallel programming.</p><p>This is the first in a series of articles where we will talk about parallel programming and various ways to enable it on modern accelerators.</p><h3>Parallelism Overview</h3><p>Parallel programming is how we write code to express parallelism in any code/algorithm to get it to run on an accelerator or multiple CPUs. But what is parallelism?</p><p>Parallelism is when parts of a program can run at the same time as another part of the program. Typically, we break this down into two categories: task parallelism and data parallelism.</p><h4>Task Parallelism</h4><p>Task parallelism is when multiple functions can be independently performed at the same time. An example would be preparing for a party. One person may get balloons, another person may get ice cream, and a third person may get the cake. While the party won’t be complete without all three things, three different people can do what they need to do independently of everyone else as long as they are done before the party and meet in the right place.</p><p>If we map this to a computer program, each person is analogous to some compute hardware (CPU/GPU/FPGA), and picking up the various items are the tasks to be run.</p><h4>Data Parallelism</h4><p>Data parallelism is when the same function can be performed independently on several pieces of identical data. Imagine the person in our example above goes to get ice cream, but four other people also want to get ice cream. Potentially, all five people can get ice cream from the same store freezer at the same time.</p><p>In this example, we again have the analogy of people to compute hardware, each one tasked with getting ice cream. The ice cream is our (delicious) analogy for data.</p><p>These examples are simplistic but hopefully instructive. There are more subtle types of parallelism, especially in the area of computer architecture, but these simple analogies may help you understand how to think about parallelism when doing parallel programming.</p><h3>Available Resources, Available Parallelism, and Contention</h3><p>Some important things to consider with parallelism are available resources and the available parallelism in a given solution space.</p><ul><li>We may be limited by the number of resources to complete a task — If I only have three people, I can only do three tasks at a time.</li><li>We may be limited by the available tasks — If I only need balloons and cake for my party, a third person to perform a task doesn’t help me.</li><li>We may be limited by the available data — If I have five people wanting to get ice cream, but only three containers of ice cream are left in the store freezer, two people will have nothing to do.</li></ul><p>Another separate issue to consider is contention. Resources are generally limited and often our attempts to parallelize a problem run into issues with resource access.</p><p>Let’s imagine we go to the store to get our ice cream and there are 100 containers of ice cream in the freezer, but only three people can stand in front of the freezer at once. That means that even if 100 people are there to get ice cream, getting ice cream still has, at most, a parallelism of three because of the limited access to the freezer.</p><p>This analogy applies to various pieces of computer hardware. One example: Think of the freezer access to be similar to a memory bus. If it is not wide enough to allow all the data to flow to the accelerator fast enough, your accelerator is stuck waiting for access to the data to do what it needs to do.</p><h3>A Simple Code Example</h3><p>To make this slightly more concrete, let’s show some code for the data parallel shopping problem above. We start by creating a shopper class. The job of this class is to perform the work of shopping. In this case, I’m using a naive matrix-multiply to be the cost of shopping.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1598b9fc538e38dc50e1e4b60ad65a05/href">https://medium.com/media/1598b9fc538e38dc50e1e4b60ad65a05/href</a></iframe><h4>Parallelism with <a href="https://www.openmp.org/">OpenMP®</a></h4><p>Now that I have defined the act of shopping, let’s look at how to make this code run in parallel using OpenMP, a portable solution that allows programmers to add parallelism to their programs. Pragma directives are added to existing code to tell the compiler how to run parts of the code in parallel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/810772e4814f62a079d8cf85536004e9/href">https://medium.com/media/810772e4814f62a079d8cf85536004e9/href</a></iframe><p>This simple code consists of four simple pieces:</p><ol><li>Line 18: Create 65536 shoppers</li><li>Line 21: Call the Shop function</li><li>Line 10–12: Ask each shopper to go shopping</li><li>Line 9: a pragma to tell the compiler when using OpenMP to run iterations of this loop in parallel</li></ol><p>The rest of it is just timers so we can see the benefits of running the code in parallel.</p><p>The nice thing about the OpenMP code is you can tell the compiler to use/not use OpenMP, which then results in a serial program.</p><p>For this article I’m using an HP Envy* laptop, which has an Intel® Core™ i7–12700H processor with 32GB of memory and an integrated Intel® Iris® Xe GPU. The system is running Ubuntu* 22.04, a 6.0 kernel, and the Intel® oneAPI DPC++/C++ Compiler.</p><p>First, I enabled the Intel compiler environment with this command:</p><pre>&gt; /opt/intel/oneapi/setvars.sh</pre><p>The following commands compile the code:</p><pre>&gt; icx -lstdc++ grocery-omp.cpp -o serial-test<br>&gt; icx -lstdc++ -fiopenmp grocery-omp.cpp -o omp-test</pre><p>The last command includes -fiopenmp flag to tell the compiler to enable parallelism using OpenMP. Running the executables, I get this output on my system:</p><pre>&gt; ./serial-test<br>Elapsed time in milliseconds: 27361 ms<br>&gt; ./omp-test<br>Elapsed time in milliseconds: 4002 ms</pre><p>The OpenMP run utilizes several of my CPU cores to do the work simultaneously, which results in a 6x–7x speed up in the OpenMP run.</p><h4>Parallelism with oneAPI/SYCL</h4><p>OpenMP is a fantastic way to enable parallelism through a directive approach. C++ with SYCL, part of the <a href="https://www.oneapi.io/">oneAPI</a> specification, allows us to express parallelism using an explicit approach.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bae5ab32f72908c55a3a8dec6fcc2ac7/href">https://medium.com/media/bae5ab32f72908c55a3a8dec6fcc2ac7/href</a></iframe><p>The SYCL code is larger than the previous code base for this example. However, we have the same core code:</p><ol><li>Line 31: Create 65536 shoppers</li><li>Line 46: Call the Shop function</li><li>Line 25: Ask each shopper to go shopping</li></ol><p>Unlike the OpenMP example where we use directives, SYCL allows users to explicitly define the parallel behavior of their program via code and C++ constructs. This provides runtime flexibility which is unavailable in OpenMP.</p><p>Depending on your use case, one paradigm may make more sense than another. In this case, we have a way to take a single binary and run it in multiple ways using Intel’s oneAPI SYCL runtime and using the SYCL_DEVICE_FILTER environment variable:</p><pre>&gt; SYCL_DEVICE_FILTER=host:host:0 ./sycl-test<br>Running on device: SYCL host device<br>Elapsed time in milliseconds: 27201 ms<br>&gt; SYCL_DEVICE_FILTER=opencl:cpu:1 ./sycl-test<br>Running on device: 12th Gen Intel(R) Core(TM) i7-12700H<br>Elapsed time in milliseconds: 4197 ms<br>&gt; SYCL_DEVICE_FILTER=opencl:gpu:3 ./sycl-test<br>Running on device: Intel(R) Graphics [0x46a6]<br>Elapsed time in milliseconds: 3988 ms</pre><p>The values for SYCL_DEVICE_FILTER come from running the sycl-ls command which comes as part of the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit.html">Intel® oneAPI Base Toolkit</a>.</p><p>The cool thing about the oneAPI C++ with SYCL implementation is that the binary can direct the work to multiple devices.</p><h3>Conclusion</h3><p>Understanding parallelism and writing parallel code is a complicated problem. This primer describes a simple example of how parallelism can be enabled using OpenMP and C++ with SYCL. There are lots of other considerations when creating a parallel program, such as how multiple compute resources share memory and variables and how to balance work properly across multiple resources.</p><p>I will address those in future articles. But for now, I encourage you to try grabbing the simple example above and see how it works on your systems.</p><p>Thanks for reading!</p><pre><strong>Want to Connect?</strong></pre><pre>If you want to see what random tech news I’m reading, you can <a href="https://twitter.com/tonymongkolsmai">follow me</a> on Twitter.</pre><p><em>Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f91420fb4f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/an-accelerated-and-parallel-programming-introduction-2f91420fb4f0">An Introduction to Accelerator and Parallel Programming</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[oneAPI — What is it?]]></title>
            <link>https://medium.com/@tonymongkolsmai/oneapi-what-is-it-b0f0c60c5775?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0f0c60c5775</guid>
            <category><![CDATA[oneapi]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[intel]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 09 Sep 2022 15:19:48 GMT</pubDate>
            <atom:updated>2022-09-09T15:19:48.013Z</atom:updated>
            <content:encoded><![CDATA[<h3>oneAPI — What is it?</h3><p>Demystifying oneAPI for Developers</p><h3>Introduction</h3><p>As an Intel Technical Evangelist, one of the most common questions I get is, “What is oneAPI?” I hope many of you have heard about oneAPI, but what it is, and, most importantly, why it matters to developers, may not be obvious. If you have those types of questions, let’s clear those up.</p><h3>What is oneAPI?</h3><h4>The Specification</h4><p>oneAPI is a specification that is open and standards-based, supporting multiple architecture types including, but not limited to, GPU, CPU, and FPGA. The spec has both direct programming and API-based programming paradigms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*vKY3a8c03lcFPlNz41h-zA.png" /><figcaption>Image Courtesy of Intel</figcaption></figure><p>The direct programming model, <em>C++ with SYCL</em>* (pronounced “sickle”), comes from <a href="https://www.khronos.org/">The Khronos Group</a>. This organization provides open software standards for a variety of use cases including well-known standards OpenGL, WebGL, OpenCL™, and more. The direct programming model provides a flexible, modern C++ language that allows developers to write parallel algorithms and integrate them into existing C++ codebases. Compilers can then take this expressed parallelism and target CPUs, GPUs, FPGAs, and other hardware.</p><p>The specification defines a set of library interfaces that are commonly used in a variety of workflows. For example, the oneAPI Math Kernel Library (oneMKL) specification is an open, stable API that enables users to leverage common, parallelizable, mathematical operations. The oneAPI Deep Neural Network Library (oneDNN) API specification exposes the basic building blocks used in deep-learning applications. As you can see below, the spec has a variety of library interfaces for several industry-standard workloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Apryhg9tpi8L0mbaVvNOoA.png" /><figcaption>Image courtesy of oneapi.io</figcaption></figure><p>Another important aspect of oneAPI is that it can coexist with other compute-based open specifications like OpenMP. This interoperability is important for developers taking advantage of existing parallelism who are looking to migrate into a more flexible, accelerator-based approach.</p><h3>The Implementation</h3><p>While having an open specification sounds great, in practice developers need strong implementations built on top of specifications. Fortunately, a variety of efforts have stepped up to meet that need.</p><p>There are several compilers that work with <em>C++ with SYCL</em> including implementations from Codeplay, Huawei, Intel, and Heidelberg University. These implementations can take <em>C++ with SYCL</em> code and target a variety of backends including CPUs and AMD/Intel/NVIDIA GPUs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmS3ENf5WosYpHFWHe5L4w.png" /><figcaption>Image courtesy of khronos.org</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjWVyA83Cfrs0rHo3hzY3g.png" /><figcaption>Image courtesy of khronos.org</figcaption></figure><p>Many of the API-based library specifications have <a href="https://github.com/oneapi-src">open source implementations</a> that support x86 CPUs and Intel GPUs. Intel provides implementations of the specification that use both CPU and GPU hardware. Some of the library API specifications, particularly the oneDNN library, were implemented by Fujitsu/RIKEN to enable ARM CPU platforms. The oneMKL library has had portions of the specification implemented by Codeplay to support the oneMKL Basic Linear Algebra Subprograms (BLAS) library on NVIDIA GPUs.</p><h3>Supporting oneAPI Developers</h3><h4>The oneAPI Community</h4><p>As with many open source initiatives, an important aspect of oneAPI is community participation, and there are industry players like Codeplay (an Intel subsidiary) and Fujitsu/RIKEN who are leveraging the specification to enable different architectures. In addition to industry users, the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/training/academic-program/centers-of-excellence.html">oneAPI Centers of Excellence program</a> partners with various universities and labs to deliver open source solutions enabled by oneAPI. Here are a few examples:</p><ul><li><a href="https://www.urz.uni-heidelberg.de/en">Heidelberg University Computing Center (URZ)</a>, led by Askel Alpay and Professor Dr. Vincent Heuveline, implemented hipSYCL to support a variety of CPUs and GPUs including AMD and NVIDIA hardware using SYCL code.</li><li>GROMACS research and development team at<a href="https://newsroom.intel.com/articles/swedish-e-science-research-center-announced-intels-first-oneapi-center-excellence-focuses-on-accelerating-gromacs"> Stockholm University and KTH Royal Institute of Technology</a>, directed by biophysics professor Erik Lindahl, updated the GROMACS implementation to take advantage of oneAPI.</li><li><a href="https://www.ks.uiuc.edu/">Theoretical and Computational Biophysics Group</a>, led by Professor David Hardy, at the <a href="https://illinois.edu/">University of Illinois at Urbana-Champaign (UIUC)</a> is migrating NAMD, a popular simulation of biomolecular systems particularly tuned for simulation of very large, cell-scale molecular systems, to oneAPI and SYCL.</li></ul><p>Outside of Centers of Excellence, oneAPI and SYCL are being used for other <a href="https://www.linkedin.com/pulse/global-oneapi-ecosystem-continues-gain-momentum-alison-richards/">important projects</a> around the world. <a href="https://www.oneapi.io/community/sycl-helping-to-accelerate-simulation-for-cern-researchers/">CERN uses them</a> to advance research around the Large Hadron Collider. Several groups are doing the same for <a href="https://www.oneapi.io/community/implementing-oneapi-in-healthcare-technology/">healthcare research</a>, including work to battle the COVID-19 pandemic. And animation studios are using the <a href="https://software.intel.com/en-us/oneapi/render-kit">Intel® oneAPI Rendering Toolkit</a> for <a href="https://www.oneapi.io/community/hollywood-co-stars-oneapi-and-open-source-technology/">ray tracing and rendering</a> in their motion pictures.</p><h4>oneAPI Support and Tools</h4><p>For developers, good documentation, samples and tools are critical. <a href="https://github.com/oneapi-src/SYCLomatic">SYCLomatic</a> is an open source tool that supports efforts to migrate code from CUDA to SYCL. The <a href="https://github.com/oneapi-src/oneAPI-samples">oneAPI samples repository</a> is filled with examples of how to access and take advantage of SYCL and oneAPI libraries.</p><p>Intel also develops a variety of toolkits that provide Intel-optimized implementations of the specification, as well as tools that may be useful to developers using oneAPI. For example, the Intel® oneAPI Base Toolkit includes Intel® VTuneᵀᴹ Profiler and Intel® Advisor to support performance optimization and the Intel® Distribution for GDB* to support debugging.</p><h3><strong>Takeaway: Hardware and Vendor Choice</strong></h3><p>oneAPI is an open source specification that aims to simplify the life of developers looking to create accelerator-based applications and who want to support a variety of hardware architectures and hardware vendors. As a major supporter of this effort, Intel has provided implementations of the specification and tooling to support developers writing oneAPI applications. However, this is not a unilateral effort. The implementation of this specification is supported by various software and hardware companies and this number will grow over time.</p><p><em>If you want to see what random tech news I’m reading, you can </em><a href="https://twitter.com/tonymongkolsmai"><em>follow me</em></a><em> on Twitter.</em></p><p><em>Tony is a Software Architect and Technical Evangelist at Intel. He has worked on several software developer tools and most recently led the software engineering team that built the data center platform which enabled Habana’s scalable MLPerf solution.</em></p><p><em>Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0f0c60c5775" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WSL Extreme Usages]]></title>
            <link>https://medium.com/better-programming/wsl-extreme-usages-bdbb9ec218e7?source=rss-9bf3c09af6c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdbb9ec218e7</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[wsl]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[TonyM]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 16:04:54 GMT</pubDate>
            <atom:updated>2022-08-05T16:04:54.692Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using GUIs, USB connections, and Kubernetes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X3GRi1gzUgkJiAvj" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>As you may know from my previous posts, I tend to use a lot of development environments and play with quite a few different technologies. I write code on Linux, Windows, and Mac in various languages, mostly C/C++ with SYCL, Golang, Python, JavaScript, and Java. I also use technologies like <a href="https://kubernetes.io/">Kubernetes</a> and dabble with AI technologies like <a href="https://www.tensorflow.org/">TensorFlow</a>, <a href="https://pytorch.org/">PyTorch</a>, and <a href="https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/overview.html">Intel Distribution of OpenVINO</a>.</p><p>I’m always interested in simplifying cross-platform development because the one thing any of us never have enough of is time. In this post, I will outline some of my quick experiences with the Windows Subsystem for Linux (WSL). The short of it is it mostly works great, sometimes we can use workarounds to make it work reasonably well, and sometimes we may need to boot into Linux.</p><p>Before we go too far, I would recommend if you are using WSL on Windows that you get the latest version from the Microsoft Store, as it did fix some issues for me related to CMake usage and some other weird behavior. Just search WSL and install the Windows Subsystem for Linux Preview below.</p><p>I found it odd it wasn’t at the top, but if you scroll down a bit, you’ll find it. Quick tip, I had to recreate my WSL environment for the changes to work for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5L1Vg8YNhPFvlfkAXk9bBA.png" /></figure><p>Assuming you haven’t set up a WSL environment after this, you can follow any WSL setup tutorial (some links to those below). For reference, the systems I’m using for this post:</p><ul><li>HP Envy 16 laptop with Intel Alder Lake Core i7-12700H, 32GB DDR4, Intel Arc a370m GPU, Windows 11 Pro</li><li>Alienware R13 with Intel Alder Lake Core i9–12900KF, 64GB DD5, NVIDIA GeForce 3080Ti GPU, Windows 11 Pro</li></ul><h3>What Just works?</h3><h4>The Basics</h4><p>If you are just writing command line code, scripts, or using something like a Jupyter notebook it works great. My C++, Python, and Golang codes compile and run just like they would be on Linux. Conda, Tensorflow, and PyTorch all install and work.</p><p>If you want to use some simple tools, here are some links that might help you get started:</p><p><a href="https://betterprogramming.pub/docker-wsl-and-oneapi-a-quick-how-to-guide-d7db3363b303">Setting up WSL, VSCode, and Intel oneAPI Base Toolkit</a></p><p><a href="https://medium.com/@ferarias/docker-in-windows-11-using-wsl2-8e30faddc32c">Setting up Docker</a></p><p><a href="https://towardsdatascience.com/configuring-jupyter-notebook-in-windows-subsystem-linux-wsl2-c757893e9d69">Setting up a Jupyter Notebook</a></p><p><a href="https://betterprogramming.pub/intel-arc-gpus-and-oneapi-do-they-sycl-9b3ba7c888b8">GPGPU programming on an Intel Arc GPU</a></p><h4>Kubernetes (for small systems)</h4><p>I’ve used K3s and MicroK8s in the past, but I was not confident this would work right out of the box. I was extremely pleased that installing K3s on a WSL using 20.04 Ubuntu was as simple as it is on Linux.</p><ol><li>make sure systemd is configured in WSL</li><li>Install K3s from <a href="https://k3s.io/">https://k3s.io/</a> and runningsudo k3s server</li><li>Install kubectl usingsudo apt get kubectl</li><li>make sure the kubeconfig/etc/rancher/k3s/k3s.yamlis usable by kubectl</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*wH8hfM6SCDh4CfBI27an8A.png" /><figcaption>Working K3s in less than 10 minutes</figcaption></figure><p>This is a small subset of what developers need, and I won’t be able to cover everything that works well, but for most things, WSL is overwhelmingly easy to use.</p><h3>What Works With Help?</h3><h4>GUIs</h4><p>WSL2 is a huge step forward over the original WSL since it added support for GUIs. For some things I tested, it just worked out of the box. For example, creating a simple OpenGL window and rendering a simple scene works great. The only issue I ran into was that the highest OpenGL version supported by the WSL DirectX layer is 3.3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*gNoNDsjERzojK-rfMuw49Q.png" /><figcaption>WSL supported OpenGL version</figcaption></figure><p>My second test was to see if our Intel tools with a GUI would work. When I tried to run the Intel VTune Profiler GUI, I ran into this issue:</p><pre>tonym@HPEnvy:~$ vtune-gui<br>vtune-gui: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory</pre><p>After installing some libraries, I realized the reason for the issue was that the application was expecting GTK+ to be installed on the system. The following commands allowed me to run the Intel VTune Profiler GUI within WSL:</p><pre>&gt; sudo apt install libnss3-dev<br>&gt; sudo apt install libatk1.0–0<br>&gt; sudo apt install libatk-bridge2.0–0<br>&gt; sudo apt-get install libgtk-3-dev</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gXerH46nsJL62argRuzjLw.png" /><figcaption>Intel VTune Profiler GUI running!</figcaption></figure><p>The great thing about doing this via WSL is now I can use the GUI to target my Linux application on my WSL file system and run my workload.</p><p>To be fair, this last issue is not a limitation of WSL. Unfortunately, it is a very common problem you may run into where Linux GUI developers assume certain platform libraries exist for their applications.</p><h3>USB Device Connections</h3><p>When I went to do some testing using a USB device, the simple workflow of hooking up my device to the machine didn’t work initially. Of course, this makes a lot of sense as this requires mapping the connection through the virtual machine layer.</p><p>Fortunately, there is a way to enable a USB-connected device using the USB/IP open source project. Microsoft has documented <a href="https://docs.microsoft.com/en-us/windows/wsl/connect-usb">the requirements and how to set up this library for WSL</a>, which allowed me to interface with devices. Nice to have easy solutions to common problems!</p><h3>VPN</h3><p>If you require a corporate VPN for work, it can be very tricky to connect your WSL instance to the internet while using the VPN. There are a few workarounds, but the official, unofficial workaround can be found here.</p><p><a href="https://randombytes.substack.com/p/bridged-networking-under-wsl">Bridged Networking under WSL</a></p><h3>What Didn’t Work?</h3><h4>K3s with GPU support</h4><p>Fortunately for me, there is only one thing I tried that did not work, and it is possible I just don’t know how to set it up correctly. The culprit is running Kubernetes with GPU support. I did find some <a href="https://dev.to/mweibel/add-nvidia-gpu-support-to-k3s-with-containerd-4j17">resources</a> that suggested you might be able to make it run, but I was not able to get it working.</p><p>WSL and Docker (or other container runtimes) work great out of the box. The only use case I have for this is really niche; if you want to run a GPU-enabled container workflow but want to do it via K3s instead of another container runtime. This probably does not make sense unless you are doing some Kubernetes development or trying to leverage some Kubernetes deployment.</p><p>As far as I understand, WSL uses its DirectX Linux driver to interface with the underlying GPUs, and that might be able to be exposed to Kubernetes. I didn’t find an easy way to do it. Unfortunately, my use case was even narrower; I was messing with implementing a particular Kubernetes device plugin.</p><p>At the end of the day, I ended up just firing up Linux on the systems when I needed to do this.</p><h3>Conclusion</h3><p>WSL works great for about 95% of what I do, and although I have Linux installed on all my systems, I very rarely have to boot into native Linux. This saves me a significant amount of time when doing cross-platform development, which is great so I don’t have to waste half my day staring at my BIOS boot screen.</p><p>It also has some extra benefits like letting me run some of my cross-platform enabled tools, like Python, on the OS I’d prefer. It seems like a minor thing, but I like typingls instead of dir for some reason. All-in-all, I consider WSL a huge win for my productivity, and I’m guessing if you’re reading this, you probably agree (or you want to get to a point where you agree 😊).</p><pre><strong>Want to Connect?</strong></pre><pre>If you want to see what random tech news I’m reading, you can <a href="https://twitter.com/tonymongkolsmai">visit me on Twitter</a>.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdbb9ec218e7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/wsl-extreme-usages-bdbb9ec218e7">WSL Extreme Usages</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>