
{"id":1408,"date":"2025-10-22T12:10:26","date_gmt":"2025-10-22T09:10:26","guid":{"rendered":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/?page_id=1408"},"modified":"2025-12-15T16:22:41","modified_gmt":"2025-12-15T14:22:41","slug":"ompi-on-the-raspberry-pi-4-5-boards","status":"publish","type":"page","link":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/software\/ompi\/documentation\/ompi-on-the-raspberry-pi-4-5-boards\/","title":{"rendered":"OMPi on the Raspberry Pi 4\/5 boards"},"content":{"rendered":"<p>Starting from version 3.5.0, OMPi officially supports the Raspberry Pi 4 and 5 boards, with their VideoCore VI and VII GPUs, respectively, through\u00a0the Vulkan module. Setting up the compiler to work for these boards is not much different from <a href=\"https:\/\/paragroup.cse.uoi.gr\/wpsite\/software\/ompi\/documentation\/ompi-ppg-basic-installation-usage\/\" target=\"_blank\">deploying to any other system<\/a>.<\/p>\n<h2>Minimum requirements<\/h2>\n<ul>\n<li>Meson <strong>0.58.0<\/strong> &#8212; <em>needed for building OMPi<\/em><\/li>\n<li>Raspberry Pi OS\u00a0&#8212; <em>needed for supporting OpenMP on the CPU<\/em><\/li>\n<li>Vulkan\u00a0&#8212; <em>additionally needed for OpenMP offloading to the VideoCore GPU<\/em><\/li>\n<\/ul>\n<h2>Installation<\/h2>\n<p>Set up OMPi\u00a0as follows:<\/p>\n<pre>meson setup build --prefix=\u2039install-dir\u203a<\/pre>\n<p>Then OMPi can be compiled and installed as usual:<\/p>\n<pre>cd build\/\r\nmeson compile\r\nmeson install<\/pre>\n<p>Note that the user does not need to provide any additional flags; the OpenMP <code>vulkan<\/code>\u00a0module is installed by default.<\/p>\n<h2>Usage<\/h2>\n<h3>Compilation<\/h3>\n<p>Compiling OpenMP applications with OMPi on a\u00a0Raspberry Pi\u00a0board is a quite straightforward process. Simply run:<\/p>\n<pre>ompicc --devs=vulkan app.c # or --devs=all<\/pre>\n<p>The compiler will produce the main application executable (a.out) and several kernel executables, specifically one for each OpenMP target construct\u00a0existing\u00a0in the\u00a0application.<\/p>\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-anchor=\"multiple-jobs\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Advanced usage: Multiple compilation jobs<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<p>When an\u00a0application contains several target regions, the user can additionally generate N parallel jobs\u00a0to handle the compilation of the kernels, by using the <code>-jN<\/code> device option, as follows:<\/p>\n<pre>ompicc --devs=vulkan <strong>--devopt -jN<\/strong> app.c<\/pre>\n<\/div><\/div>\n<h3>Testing the Vulkan module<\/h3>\n<p>The correct installation of OMPi along with its <code>vulkan<\/code>\u00a0module,\u00a0can be verified by running:<\/p>\n<pre>ompiconf --devvinfo<\/pre>\n<p>On a Raspberry Pi 5, this command must print out the following information, assuming that <code>vulkan<\/code>\u00a0is the only module installed:<\/p>\n<pre>1 configured device module(s): vulkan\r\n\r\nMODULE [vulkan]:\r\n------\r\nOMPi Vulkan device module.\r\nAvailable devices : 1\r\n\r\ndevice id &lt; 0 &gt; { \r\n Name: VideoCore VII\r\n API version: XYZ - Driver version: XYZ\r\n Vendor ID: 5549\r\n Maximum workgroup sizes: (2147483647, 65535, 65535)\r\n Maximum invocations: 1024\r\n <span class=\"mord\">4194304<\/span><span class=\"mord text\"><span class=\"mord\">\u00a0<\/span><\/span>Kbytes of memory\r\n}\r\n------<\/pre>\n<p>The programmer can moreover verify that the module is working properly by compiling the following sample application and running it:<\/p>\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-anchor=\"sample-app\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Source code: Sample application utilizing the GPU<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<pre><strong>#include<\/strong> &lt;stdio.h&gt;\r\n<strong>#include<\/strong> &lt;omp.h&gt;\r\n<strong>\r\nint<\/strong> main(<strong>void<\/strong>)\r\n{\r\n    \/* \r\n     * Expected result (assuming that the GPU device ID is 0):\r\n     * Running on the VideoCore GPU.\r\n     *\/\r\n    <strong>int<\/strong> is_initial_device = 1;\r\n<strong><span class=\"cp\">    #pragma omp target map(tofrom:is_initial_device) device(0)<\/span><\/strong>\r\n    <span class=\"p\">{<\/span>\r\n        <span class=\"k\">is_initial_device<\/span><span class=\"k\"> =<\/span> <span class=\"n\">omp_is_initial_device<\/span><span class=\"p\">();<\/span>\r\n    <span class=\"p\">}\r\n\r\n<\/span><span class=\"p\"><strong>    printf<\/strong>(\"Running on the %s.\\n\", (<\/span><span class=\"p\">is_initial_device == 0) ? \r\n                                   \"VideoCore GPU\" : \"CPU\");\r\n\r\n<\/span><span class=\"p\"><strong>    return<\/strong> 0; \r\n} <\/span><\/pre>\n<\/div><\/div>\n<h3>Mini-tutorial: Writing OpenMP applications which exploit the GPU<\/h3>\n<p>Targeting the VideoCore GPU of a Raspberry Pi 4\/5\u00a0board is\u00a0made possible by using the OpenMP <em>target<\/em>-related constructs. With these constructs, the programmer indirectly launches a Vulkan grid, that consists of multiple Vulkan workgroups\u00a0containing multiple Vulkan invocations. Below you can find information about the syntax and usage of the most popular constructs. For detailed information, please consult the official OpenMP specifications.<\/p>\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-anchor=\"target-parallel\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Construct: #pragma omp target parallel<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<pre>#pragma omp target parallel\r\n    &lt;structured-block&gt;<\/pre>\n<p>This construct launches a Vulkan workgroup consisting of multiple threads. The default number of launched invocations is 128, but can be alternatively specified using the <code>num_threads(N)<\/code> clause.<\/p>\n<\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-anchor=\"target-teams\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Construct: #pragma omp target teams<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<pre>#pragma omp target teams\r\n    &lt;structured-block&gt;<\/pre>\n<p>This construct\u00a0launches multiple Vulkan workgroups consisting of one invocation. The default number of launched workgroups is 1, but\u00a0can be alternatively specified\u00a0using the <code>num_teams(N)<\/code> clause.<\/p>\n<\/div><\/div>\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-anchor=\"target-teams-dist-par-for\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Construct: #pragma omp target teams distribute parallel for<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">\n<pre>#pragma omp target teams distribute parallel for\r\n    &lt;for-loops&gt;<\/pre>\n<p>This construct is a combination of the previous constructs and launches multiple Vulkan workgroups consisting of multiple invocations and additionally distributes the iterations of a loop across the launched workgroups\u00a0and invocations.<\/p>\n<\/div><\/div>\n<h3>\u00a0<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Starting from version 3.5.0, OMPi officially supports the Raspberry Pi 4 and 5 boards, with their VideoCore VI and VII GPUs, respectively, through\u00a0the Vulkan module. Setting up the compiler to work for these boards is not much different from deploying to any other system. Minimum requirements Meson 0.58.0 &#8212; needed for building OMPi Raspberry Pi [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":120,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1408","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/pages\/1408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/comments?post=1408"}],"version-history":[{"count":10,"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/pages\/1408\/revisions"}],"predecessor-version":[{"id":1435,"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/pages\/1408\/revisions\/1435"}],"up":[{"embeddable":true,"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/pages\/120"}],"wp:attachment":[{"href":"https:\/\/paragroup.cse.uoi.gr\/wpsite\/wp-json\/wp\/v2\/media?parent=1408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}