Intel oneAPI Toolkit
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]:
- 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
- This is the most important component of Intel OneAPI
- Download the installer here : https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html?operatingsystem=window&distributions=online&version=2023.2.0
- Launch it (you need admin rights)
- Select the recommended installation:
- If you did not install Visual Studio prior to that, you will get following error:
- If you did install it, you will see following window:
- Just continue by clicking on the [right arrow] and proceed with the installation:
- Optional: After the installation, [click on Get Started Guide]:
Intel HPC Toolkit
- This toolkit complements the Intel oneAPI Base Toolkit and adds:
- Intel Fortran Compiler
- Intel Fortran Compiler Classic
- Intel Inspector
- Intel MPI Library
- Intel Trace Analyzer and Collector
- You need it for Fortran development and MPI related projects
- Download the installer here : https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html?operatingsystem=window&distributions=onlinei
- (Click on [Continue without signing up])
- Launch the installer, accept the terms and conditions and select [Recommended Installation]
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] :
- This will just open a cmd prompt pointing at the right folder (in our case oneAPI):
- In the prompt, type setvars.bat and hit [Enter] to configure the system variables:
- In the same command window, type oneapi-cli.exe, next window will pop-up:
- Select Create a project
- Choose the language you prefer, and click Enter:
- Select the sample app you want to build, let’s try to select "vector-add":
- Then specify the location and press [Enter]:
- Again, press [Enter] to create the project
- Then select [View Readme and Quit]
- 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:
- Then create a and enter a build directory:
- 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
- If you are using the Visual Studio Command Prompt you probably don't have it included as a component in your Visual Studio install
- 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
- To run the program: in the prompt, just type:
vector-add-buffers.exe
==> 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 make Visual Studio automatically run the setvars.bat script, you need to set the environment variable so called "SETVARS_CONFIG" to blank (i.e. one white space)
- (More details here: https://www.intel.com/content/www/us/en/docs/oneapi/programming-guide/2023-0/automate-the-setvars-bat-script-with-microsoft.html )
- 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
- 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 :
- Go to [Build] and click on [Rebuild All]
- If your Solution Explorer displays an empty build folder, just click on the small icon [Show All Files], then the built files will appear
- Then, go to the run scroll list and select vector-add-buffer.exe
- Finally, click on the [run] button (green triangle)
- This is the output you should get:
==> 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]
- 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:
- 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:
- Then Click on the [Start] button and below window will pop up:
- (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.
- If you get the following error message when you run the program :
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
- 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]:
- You can do the same with intel Fortran Classic compiler (ifort):
==> YOU HAVE SUCCESSFULLY BUILT AND RUN THE FORTRAN HELLO WORLD PROGRAM VIA COMMAND LINE <==
- We will now build a more complex sample, that we will fetch directly from the Intel GitHub repository: https://github.com/oneapi-src/oneAPI-samples/tree/master/DirectProgramming/Fortran
Run Intel Fortran Sample via Visual Studio Code
- For this task we will focus on the DenseLinearAlgebra/optimize-integral sample.
Install Visual Studio Code
- Download the VSCode installer and run it : https://code.visualstudio.com/download
Install Intel oneAPI extensions for VS Code
- Open Visual Studio Code
- Go to extension tab of VS Code, and type intel oneapi
- Then Select Extension Pack for Intel® oneAPI Toolkits and click on [install]
Fetch the Intel Fortran Sample
- Via Chrome or Edge, go to the sample directory you want to test, in our case, go to : https://github.com/oneapi-src/oneAPI-samples/tree/master/DirectProgramming/Fortran/DenseLinearAlgebra/optimize-integral
- Then, click on the 3 dots and finally click on [Copy permalink]
- In your web browser, open a new page : https://download-directory.github.io/
- (This is a small utility that allows you to download just a sub directory of a GitHub repository, when you don't want the entire project)
- Past the permalink that you just copied from GitHub, to the unique field of this website and hit [Enter]:
- 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:
- 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 :
- Then, if prompted, choose the setvar.bat file :
- 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:
- (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
- 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:
==> 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:
- We can see that the ifort compiled executable took more time to complete its task compared with the ifx compiled executable.