{"id":805,"date":"2010-10-08T09:49:09","date_gmt":"2010-10-08T13:49:09","guid":{"rendered":"https:\/\/www.bu.edu\/pasi\/?page_id=805"},"modified":"2010-10-08T10:35:29","modified_gmt":"2010-10-08T14:35:29","slug":"gpu-programming-with-pyopencl-and-pycuda","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/pasi\/courses\/gpu-programming-with-pyopencl-and-pycuda\/","title":{"rendered":"Easy, Effective, Efficient: GPU programming with PyOpenCL and PyCUDA"},"content":{"rendered":"<h3>by Andreas Kl\u00f6ckner<\/h3>\n<p><strong>Courant Institute of Mathematics, New York University<\/strong><\/p>\n<h3>Why this course?<\/h3>\n<p>High-level scripting languages are in many ways polar opposites to\u00a0GPUs. GPUs are highly parallel, subject to hardware subtleties, designed for maximum throughput, and they offer a tremendous advantage in the performance achievable for a significant number of\u00a0computational problems.<\/p>\n<p>On the other hand, scripting languages such as\u00a0Python favor ease of use over computational speed and do not generally\u00a0emphasize parallelism. <a href=\"http:\/\/mathema.tician.de\/software\/pyopencl\" target=\"_blank\">PyOpenCL<\/a> and <a href=\"http:\/\/mathema.tician.de\/software\/pycuda\" target=\"_blank\">PyCUDA<\/a> are two packages that\u00a0attempt to join the two together. This course aims to show you that by\u00a0combining these opposites, a programming environment is created that\u00a0is greater than just the sum of its two parts.<\/p>\n<figure id=\"attachment812\" aria-describedby=\"caption-attachment812\" style=\"width: 290px\" class=\"wp-caption alignright\"><a href=\"\/pasi\/files\/2010\/10\/f117-arrows2.png\"><img loading=\"lazy\" class=\"size-full wp-image-812  \" title=\"f117-arrows2\" src=\"\/pasi\/files\/2010\/10\/f117-arrows2.png\" alt=\"PyCUDA was used in electromagnetics simulations of a full aircraft.\" width=\"280\" height=\"233\" \/><\/a><figcaption id=\"caption-attachment812\" class=\"wp-caption-text\">An electromagnetics scattering problem solved on a GPU using a discontinuous Galerkin methods driven from Python.<\/figcaption><\/figure>\n<p>PyOpenCL (and also PyCUDA) can be used in a large number of roles, for\u00a0example as a prototyping and exploration tool, as an optimization\u00a0helper, as a bridge to the GPU for existing legacy codes, or, perhaps\u00a0most excitingly, to support an unconventional <em>hybrid way of\u00a0writing high-performance codes<\/em>, in which a high-level controller\u00a0generates and supervises the execution of low-level (but\u00a0high-performance) computation tasks to be carried out on varied GPU or GPU-based computational infrastructure.<\/p>\n<p>You will learn about each\u00a0of these roles and how to best make use of what PyOpenCL and PyCUDA\u00a0have to offer. In doing so, you will also gain familiarity with the\u00a0OpenCL computation interface.<\/p>\n<h3>About the course<\/h3>\n<p>This course will build upon the knowledge you gain at PASI. \u00a0In\u00a0particular, we will use your familiarity with CUDA to learn about OpenCL, and your experience with Python and Numpy to make the\u00a0connection to PyOpenCL and PyCUDA.<\/p>\n<p>The class will take place in three sessions, with material partitioned\u00a0roughly partitioned as follows:<\/p>\n<ul>\n<li><em>Lecture 1<\/em>:\n<ul>\n<li>Introduction to OpenCL based on CUDA knowledge;<\/li>\n<li>the OpenCL Universe: CL on CPUs and various GPUs;<\/li>\n<li>PyOpenCL: OpenCL Scripting Mechanics for GPU and multi-core.<\/li>\n<\/ul>\n<\/li>\n<li><em>Lecture 2<\/em>:\n<ul>\n<li>Motivation for hybrid codes: GPUs and Scripting;<\/li>\n<li>GPU arrays, custom element-wise and reductive operations;<\/li>\n<li>run-time code generation: the How and Why;<\/li>\n<li>advanced code generation: templating;<\/li>\n<li>Heuristics and search patterns for automated tuning, performance measurement<\/li>\n<\/ul>\n<\/li>\n<li><em>Lecture 3<\/em>:\n<ul>\n<li>PyOpenCL and mpi4py;<\/li>\n<li>a look at PyCUDA;<\/li>\n<li>PyCUDA and existing (C-based) CUDA libraries.<\/li>\n<li>An example: Gas dynamics and EM on complex geometries.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Depending on time and demand, a lab class in the use of PyOpenCL\u00a0may be offered.<\/p>\n<figure id=\"attachment810\" aria-describedby=\"caption-attachment810\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><a href=\"\/pasi\/files\/2010\/10\/pycuda-workflow2.png\"><img loading=\"lazy\" class=\"size-full wp-image-810 \" title=\"pycuda-workflow2\" src=\"\/pasi\/files\/2010\/10\/pycuda-workflow2.png\" alt=\"pycuda-workflow2\" width=\"500\" height=\"203\" \/><\/a><figcaption id=\"caption-attachment810\" class=\"wp-caption-text\">Workflow of PyCUDA program compilation. PyCUDA maintains a scripting-like &quot;edit-run-repeat&quot; style of working for the user. The compilation and caching operations in the gray box are performed without user involvement.<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>by Andreas Kl\u00f6ckner Courant Institute of Mathematics, New York University Why this course? High-level scripting languages are in many ways polar opposites to\u00a0GPUs. GPUs are highly parallel, subject to hardware subtleties, designed for maximum throughput, and they offer a tremendous advantage in the performance achievable for a significant number of\u00a0computational problems. On the other hand, [&hellip;]<\/p>\n","protected":false},"author":3344,"featured_media":0,"parent":321,"menu_order":5,"comment_status":"closed","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/pages\/805"}],"collection":[{"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/users\/3344"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/comments?post=805"}],"version-history":[{"count":15,"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/pages\/805\/revisions"}],"predecessor-version":[{"id":822,"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/pages\/805\/revisions\/822"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/pages\/321"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/pasi\/wp-json\/wp\/v2\/media?parent=805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}