Intel oneAPI Toolkit

From TAMUQ Research Computing User Documentation Wiki
(Redirected from Intel oneAPI Toolkit)
Jump to navigation Jump to search

Overview

Recently (December 2020), Intel rebranded and repackaged its Parallel Studio XE product into: Intel oneAPI Base Toolkit + Intel oneAPI HPC Toolkit.
Both of these toolkits have been released by Intel following a Free Open Source Licensing model.
The combinations of them contains all the tools in Parallel Studio XE and more.
One significant addition is a Data Parallel C++ (DPC++) compiler designed to allow developers to reuse code across hardware targets (CPUs and accelerators such as GPUs and FPGAs).

==> In this tutorial, we will see how to install and use these toolkits on a Windows Desktop, by compiling and running several samples in both C++ and Fortran languages. <==

Install Visual Studio community 2019

  • Download the installer of VS Community 2019 16.11 (the latest version of 2022 is not 100% compatible with Intel OneAPI toolkit 2023.2), to do so:
    • Go to: https://visualstudio.microsoft.com/vs/older-downloads/
    • Click on [Download]
    • You will be prompted to log in or create a free Microsoft account, do it (this is necessary as you need a former version of Visual Studio)
    • Tip: you can sign-in to your Microsoft personal account, or use your TAMUQ Microsoft account, or create an account for free
  • Launch the downloaded installer and click on [continue]:

Pictur1.png

  • In Workloads tab, select the following packages:
    • Desktop development with C++
    • Optional: Python development
  • In Individual Components tab verify that following packages are ticked, otherwise, tick them:
    • Under Compilers->build tools and runtimes check MSVC v142 - VS 2019 C++ x64x/x86 build tools (Latest)
    • And also C++/CLI support for v142 build tools (Latest)
  • Click on [install]
  • Then you can skip the sign in process and choose a suitable environment (Dark, Blue...) for you when prompted
  • Finally click on [Start Visual Studio] just to check that it can start properly

==> If you can see the Visual Studio window popping up, you can close it & proceed with the Intel OneApi toolkit installation

Install Intel OneAPI Toolkits

Intel OneAPI Base Toolkit

Pictur7.png

  • If you did not install Visual Studio prior to that, you will get following error:

Pictur5.png

  • If you did install it, you will see following window:

Pictur6.png

  • Just continue by clicking on the [right arrow] and proceed with the installation:

Pictur7.png

  • Optional: After the installation, [click on Get Started Guide]:

https://www.intel.com/content/www/us/en/docs/oneapi-base-toolkit/get-started-guide-windows/2023-2/before-you-begin.html

Intel HPC Toolkit

Pictur8.png

Test your installation

  • "Vector Add" is a simple test app that will help verify that the tools are setup correctly and can access your system's GPU
  • We will build it and run it via 2 different methods: command line & Visual Studio IDE
  • But the result will be the same so you can choose the one you are more comfortable with

Command line (C++)

  • In your Windows file explorer, go to: C:\Program Files (x86)\Intel\oneAPI
  • Then, click in the address bar
  • The path is highlighted, simply type cmd and hit [Enter] :

Pictur10.png

  • This will just open a cmd prompt pointing at the right folder (in our case oneAPI):

Pictur11.png

  • In the prompt, type setvars.bat and hit [Enter] to configure the system variables:

Pictur12.png

  • In the same command window, type oneapi-cli.exe, next window will pop-up:

Pictur13.png

  • Select Create a project
  • Choose the language you prefer, and click Enter:

Pictur14.png

  • Select the sample app you want to build, let’s try to select "vector-add":

Pictur15.png

  • Then specify the location and press [Enter]:

Pictur16.png

  • Again, press [Enter] to create the project
  • Then select [View Readme and Quit]

Pictur17.png

  • The Readme file of this specific sample will be displayed in the prompt
  • It basically contains the detailed steps you need to undertake to build the app, I will give you the gist of it in the below steps, so you don’t need to read this Readme file
  • In the same prompt, go to the sample directory:

Pictur19.png

  • Then create a and enter a build directory:

Pictur20.png

  • Finally simply type:
cmake -G "NMake Makefiles" ..
  • If you get following message: 'nmake' is not recognized as an internal or external command:
    • If you are using the Visual Studio Command Prompt you probably don't have it included as a component in your Visual Studio install
      • Go to your Visual Studio Installer -> Modify -> Individual Components tab.
      • Under Compiler, build tools, and runtimes
        • check MSVC v142 - VS 2019 C++ x64x/x86 build tools (Latest)
        • and also C++/CLI support for v142 build tools (Latest)
    • Otherwise, in you are using cmd prompt, this might be an environment variable issue, make sur that you properly run the "setvars.bat" script before this step
  • Then come back to this prompt and type the command again:
cmake -G "NMake Makefiles" ..
  • This was for the configuration of the build, now for the actual build of the program for both CPU and GPU, type:
nmake cpu-gpu

Pictur21.png

  • To run the program: in the prompt, just type:
vector-add-buffers.exe

Pictur22.png

==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE C++ SAMPLE OF INTEL VIA COMMAND LINE <==

Visual Studio IDE (C++)

  • We will run the same program but this time through the Visual Studio IDE, up to you to choose your favorite approach
  • Set up the system variables:
  • To do so:
    • Press [Window+R]
    • Then type in the window text box sysdm.cpl and click O
    • System properties window appears, go to [Advanced] tab and click on [Environment Variables]
    • In the user-specific section click on [New] button
    • Then, in [Variable name] field enter: SETVARS_CONFIG
    • And in [Variable value] field, simply enter a “white space” and hit [Enter]
  • Now launch VS 2019 (it will automatically run the setvar.bat script)
  • Once Visual Studio start-up window pops up, click on "[continue without code]" (small blue line just below "Create a new project")
  • From the top menu, select: Extensions > Intel > Browse oneAPI Sample

Pictur28.png

  • Select the project you want to build, in our case "Vector Add" and click "[Ok]"
  • Select the Base_Vector_Add folder in the Solution Explorer :

Pictur30.png

  • Go to [Build] and click on [Rebuild All]

Pictur31.png

  • If your Solution Explorer displays an empty build folder, just click on the small icon [Show All Files], then the built files will appear

Pictur32.png

  • Then, go to the run scroll list and select vector-add-buffer.exe

Pictur33.png

  • Finally, click on the [run] button (green triangle)

Picture34.png

  • This is the output you should get:

Pictur35.png

==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE C++ SAMPLE OF INTEL VIA VISUAL STUDIO IDE <==

Visual Studio IDE (Fortran)

  • In the 1st example, we used a C++ based code, now we will do the same but with a Fortran based one
  • We will now use a simple Hello World example, but in the last section we will take a more complex sample provided by Intel
  • Open visual studio 2019 & Click on [Continue without code]
  • Then, as we did previouly, click on Extensions->Intel->Create New Intel oneAPI Project
  • In the first scroll down list, select [Fortran], then, right below, select [Main Program Code]

Pictur38.png

  • Then name your project and click on Create
  • Visual Studio will automatically create the project with some predefined files, one of them will be nameOfYourProject.f90
    • This is the main source file of your project, open it and add a "pause" after Hello World (to be able to read the text before the console closes) & save it:

Pictur40.png

  • You can choose to build your program in release or debug mode with a field om the left of the [start] button
  • Go to [Build] and click on [Build Solution] (or simply type Ctrl+Shift+B)
  • You should get the following output:

Pictur43.png

  • Then Click on the [Start] button and below window will pop up:

Pictur44.png

  • (The Orange bar shows that you are in a Debug Mode)
  • Press [Enter] to stop the program

==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE FORTRAN HELLO WORLD SAMPLE VIA VISUAL STUDIO IDE <==

  • Warning: Issue with libifcoremd.dll library:
    • If you get the following error message when you run the program :
      • "[…] code execution cannot proceed because libifcoreemd.dll was not found"
    • Then it is just a problem of Path variable that has not been properly set.
    • To fix it, modify your Path variable by adding the path to this library into it (as we did before):
      • Press [Windows + R], then write sysdm.cpl and click [OK]
      • Go to [Advanced tab] and click on [Environment Variables]
      • Select Path and click on [Edit]
      • Click on New and past the Path to the libifcoremd.dll library: C:\Program Files (x86)\Intel\oneAPI\compiler\2024.0\bin
        • (if this library sits in another folder, modify the path accordingly)
      • Click [OK]
      • The problem should have been fixed.


Command line (Fortran)

  • In the C++ Command line example, we used the oneapi-cli.exe to fetch the Intel Sample, unfortunately, it seems that Intel has not enabled yet the same approach for Fortran
  • Hence, we will now use a simple Hello World example (in the last section we will build a more complex sample)
  • In your file explorer, go to : C:\Program Files (x86)\Intel\oneAPI
  • As usual, click in the address bar, and when the path is highlighted, simply type type cmd and hit [Enter]
  • Type setvars.bat to configure the system variables (keep this prompt open)
  • In your workspace, create a file called hello.f90 and paste below lines into it:
program hello
implicit none
write(*,*) 'Hello world!'
pause

end program hello
  • Save it and close it
  • Go back to your open prompt, and within it, go to the folder where you placed hello.f90 file (with cd command)
  • Then enter the following command:
ifx hello.f90 -o hello2

Pictur54.png

  • ifx has compiled your hello.f90 file and created the proper hello2.exe file out of it
  • Run this executable simply by typing hello2 and hit [Enter]:

Pictur55.png

  • You can do the same with intel Fortran Classic compiler (ifort):

Pictur56.png Pictur57.png

==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE FORTRAN HELLO WORLD PROGRAM VIA COMMAND LINE <==

Run Intel Fortran Sample via Visual Studio Code

  • For this task we will focus on the DenseLinearAlgebra/optimize-integral sample.

Install Visual Studio Code

Install Intel oneAPI extensions for VS Code

  • Open Visual Studio Code
  • Go to extension tab of VS Code, and type intel oneapi

Pictur60.png

  • Then Select Extension Pack for Intel® oneAPI Toolkits and click on [install]

Fetch the Intel Fortran Sample

Pictur61.png

  • Now you can retrieve the zip of the directory in your download folder
  • Extract it and copy it into your workspace


Build and Run the Intel Sample via VS Code

  • In the file explorer, go to your workspace, where you copied the directory of Intel Sample folder.
  • Then, as usual, click on the address bar to highlight the path and type cmd:

Pictur62.png

  • In this prompt, to open VS Code with the right workspace, simply type
code .

(don't forget the space between code and .)

  • VS Code will open up automatically on your workspace
  • Click on default environment in one of the popup windows that opened on the bottom right corner :

Pictur63.png

  • Then, if prompted, choose the setvar.bat file :

Pictur64.png

  • This will set the environment variables needed by Intel OneApi (path to the compilers, librairies and so on)
  • Now, this is the environment you should have in front of you:

Pictur65.png

  • (Optional: If you want to have more details about the compilation, open the README.md file)
  • On the top of the screen, click on Terminal->New Terminal
  • An integrated Terminal has been opened on the bottom of VS Code window.
  • In this Terminal, run the build.bat script by typing:
./build.bat

Pictur67.png

  • This will build the int_sin.exe executable
  • To run it, simply type in the same integrated Terminal:
./run.bat
  • Then you will have the following output displayed in this terminal:

Pictur68.png
[...]
Pictur69.png

==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE FORTRAN INTEL SAMPLE PROGRAM VIA VS CODE <==

  • Optional: this was using the latest Fortran compiler from Intel, called "ifx", let’s try to compile the same example with the classic Intel Fortran compiler so called "ifort"
  • To do so, simply modify the build.bat as follows:
    • First line shall be commented and copied to the end
    • Then, in this copied line, replace "ifx" by "ifort"
    • Save the file
  • Again, just run the build.bat file to create the executable, and then run the run.bat file to launch it:

Pictur71.png

  • We can see that the ifort compiled executable took more time to complete its task compared with the ifx compiled executable.