Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 115 additions & 90 deletions DirectProgramming/DPC++/StructuredGrids/iso3dfd_dpcpp/README.md
Original file line number Diff line number Diff line change
@@ -1,136 +1,161 @@
# `ISO3DFD` Sample
ISO3DFD refers to three-dimensional finite-difference wave propagation in isotropic media. The `ISO3DFD` sample is a three-dimensional stencil to simulate a wave propagating in a 3D isotropic medium. The sample code shows common challenges when targeting SYCL* devices (GPU/CPU) in complex applications.

The ISO3DFD sample refers to Three-Dimensional Finite-Difference Wave Propagation in Isotropic Media. It is a three-dimensional stencil to simulate a wave propagating in a 3D isotropic medium. It shows some of the more common challenges when targeting SYCL* devices (GPU/CPU) in more complex applications.

For comprehensive information in using oneAPI programming, see the [Intel® oneAPI Programming Guide](https://software.intel.com/en-us/oneapi-programming-guide), and use search or the table of contents to find relevant information.


| Property | Description
|:--- |:---
| What you will learn | How to offload the computation to GPU using Intel® oneAPI DPC++/C++ Compiler
| Time to complete | 15 minutes
| Area | Description
|:--- |:---
| What you will learn | How to offload complex computations to a GPU
| Time to complete | 15 minutes

## Purpose
ISO3DFD is a finite difference stencil kernel for solving the 3D acoustic isotropic wave equation, which can be used as a proxy for propagating a seismic wave. In this sample, kernels are implemented as 16th order in space, with symmetric coefficients, and 2nd order in time scheme without boundary conditions. The sample can explicitly run on the GPU and/or CPU to propagate a seismic wave, which is a compute intensive task.
The `ISO3DFD` sample is a finite difference stencil kernel for solving the 3D acoustic isotropic wave equation. The solution can be used as a proxy for propagating a seismic wave.

The code will first attempt to execute on an available GPU and fallback to the system's CPU if a compatible GPU is not detected. By default, the output will print the device name where SYCL*-compliant code ran along with the grid computation metrics, flops and effective throughput. For validating results, a serial version of the application will be run on CPU, and results will be compared to the SYCL*-compliant version.
In this sample, kernels are implemented as 16th order in space, with symmetric coefficients, and 2nd order in time scheme without boundary conditions. The sample code can explicitly run on a GPU or CPU, or on both, to propagate a seismic wave. The calculations are compute intensive.

| iso3dfd sample | Performance data
|:--- |:---
| Scalar baseline -O2 | 1.0
| SYCL* | 2x speedup

> **Note**: You can find more information about this sample at [Explore SYCL* with Samples from Intel](https://www.intel.com/content/www/us/en/develop/documentation/explore-dpcpp-samples-from-intel/top.html#top_STEP4_ISO3DFD).
> **Note**: You can find information about this sample at [Explore SYCL* with Samples from Intel](https://www.intel.com/content/www/us/en/develop/documentation/explore-dpcpp-samples-from-intel/top.html#top_STEP4_ISO3DFD).

## Prerequisites
| Optimized for | Description
|:--- |:---
| OS | Ubuntu* 18.04 <br>Windows* 10
| Hardware | Skylake with GEN9 or newer
| Software | Intel&reg; oneAPI DPC++/C++ Compiler
| Optimized for | Description
|:--- |:---
| OS | Ubuntu* 18.04 <br> Windows* 10
| Hardware | Skylake with GEN9 or newer
| Software | Intel® oneAPI DPC++/C++ Compiler

## Key Implementation Details
The basic SYCL* implementation explained in the code includes the use of the following :
- SYCL* local buffers and accessors (declare local memory buffers and accessors to be accessed and managed by each workgroup)
The basic SYCL* implementation explained in the code includes:
- SYCL local buffers and accessors (declare local memory buffers and accessors to be accessed and managed by each workgroup)
- Code for Shared Local Memory (SLM) optimizations
- SYCL* kernels (including parallel_for function and nd-range<3> objects)
- SYCL* queues (including custom device selector and exception handlers)
- SYCL kernels (including parallel_for function and nd-range<3> objects)
- SYCL queues (including custom device selector and exception handlers)

The code attempts to run on a compatible GPU first. If a compatible GPU is not found, then the program runs on the CPU.

For validating results, a serial version of the application will be run on CPU, and results will be compared to the SYCL version. In some cases, the code will use a field programmable array (FPGA) emulator to run the SYCL variant.

The program output includes the device name that ran the code along with the grid computation metrics, flops, and effective throughput.

| `ISO3DFD` Sample | Performance data
|:--- |:---
| Scalar baseline -O2 | 1.0
| SYCL | 2x speedup

## Set Environment Variables
When working with the command-line interface (CLI), you should configure the oneAPI toolkits using environment variables. Set up your CLI environment by sourcing the `setvars` script every time you open a new terminal window. This practice ensures that your compiler, libraries, and tools are ready for development.

## Build the `ISO3DFD` Program for CPU and GPU
> **Note**: If you have not already done so, set up your CLI
> environment by sourcing the `setvars` script located in
> the root of your oneAPI installation.
> environment by sourcing the `setvars` script in the root of your oneAPI installation.
>
> Linux:
> Linux*:
> - For system wide installations: `. /opt/intel/oneapi/setvars.sh`
> - For private installations: `. ~/intel/oneapi/setvars.sh`
> - For private installations: ` . ~/intel/oneapi/setvars.sh`
> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'`
>
> Windows:
> Windows*:
> - `C:\Program Files(x86)\Intel\oneAPI\setvars.bat`
> - Windows PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'`
>
>For more information on environment variables, see Use the setvars Script for [Linux or macOS](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html), or [Windows](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).
> For more information on configuring environment variables, see [Use the setvars Script with Linux* or macOS*](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html) or [Use the setvars Script with Windows*](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).

### Include Files
The include folder is located at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your development system.
The include folder is at `%ONEAPI_ROOT%\dev-utilities\latest\include` on your development system. You might need to use some of the resources from this location to build the sample.

### Use Visual Studio Code* (Optional)
>**Note**: You can get the common resources from the [oneAPI-samples](https://github.com/oneapi-src/oneAPI-samples/tree/master/common) GitHub repository.

You can use Visual Studio Code (VS Code) extensions to set your environment, create launch configurations, and browse and download samples.
### Use Visual Studio Code* (VS Code) (Optional)
You can use Visual Studio Code* (VS Code) extensions to set your environment,
create launch configurations, and browse and download samples.

The basic steps to build and run a sample using VS Code include:
- Download a sample using the extension **Code Sample Browser for Intel&reg; oneAPI Toolkits**.
- Configure the oneAPI environment with the extension **Environment Configurator for Intel&reg; oneAPI Toolkits**.
- Open a Terminal in VS Code (**Terminal>New Terminal**).
- Run the sample in the VS Code terminal using the instructions below.
1. Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**.
2. Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**.
3. Open a terminal in VS Code (**Terminal > New Terminal**).
4. Run the sample in the VS Code terminal using the instructions below.

To learn more about the extensions and how to configure the oneAPI environment, see
[Using Visual Studio Code with Intel&reg; oneAPI Toolkits User Guide](https://software.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).
To learn more about the extensions and how to configure the oneAPI environment, see the
[Using Visual Studio Code with Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).

### On Linux*
Perform the following steps:
1. Build the program using the following `cmake` commands.
1. Change to the sample directory.
2. Build the program.
```
$ mkdir build
$ cd build
$ cmake ..
$ make -j
mkdir build
cd build
cmake ..
make
```
By default, executable builds for a kernel with direct global memory usage. You can build the kernel with shared local memory (SLM) buffers.
```
cmake -DSHARED_KERNEL=1 ..
make
```
By default, executable is build with kernel with direct global memory usage. You can build the kernel with shared local memory (SLM) buffers with the following:
```
cmake -DSHARED_KERNEL=1 ..
make -j
```
2. Run the program :
```
make run
```
> **Note**: for selecting CPU as a SYCL device, use `make run_cpu`.

If an error occurs, you can get more details by running `make` with
the `VERBOSE=1` argument:
```
make VERBOSE=1
```
### On Windows*
**Using Visual Studio***

#### Troubleshooting
If you receive an error message, troubleshoot the problem using the Diagnostics Utility for Intel&reg; oneAPI Toolkits, which provides system checks to find missing
dependencies and permissions errors. See [Diagnostics Utility for Intel&reg; oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html).
Build the program using **Visual Studio 2017** or newer.
1. Change to the sample directory.
2. Right-click on the solution file and open the solution in the IDE.
3. Right-click on the project in **Solution Explorer** and select **Rebuild**.
4. From the top menu, select **Debug** > **Start without Debugging**. (This runs the program.)

### On Windows* Using Visual Studio* Version 2017 or Newer
- Build the program using VS2017 or VS2019
- Right-click on the solution file and open using either VS2017 or VS2019 IDE.
- Right-click on the project in Solution Explorer and select Rebuild.
- From the top menu, select Debug -> Start without Debugging.
**Using MSBuild**
1. Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native Tools Command Prompt for VS2019" or whatever is appropriate for your Visual Studio* version.
2. Change to the sample directory.
3. Run the following command: `MSBuild iso3dfd_dpcpp.sln /t:Rebuild /p:Configuration="Release"`

- Build the program using MSBuild
- Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native Tools Command Prompt for VS2019"
- Run the following command: `MSBuild iso3dfd_dpcpp.sln /t:Rebuild /p:Configuration="Release"`
#### Troubleshooting
If you receive an error message, troubleshoot the problem using the **Diagnostics Utility for Intel® oneAPI Toolkits**. The diagnostic utility provides configuration and system checks to help find missing dependencies, permissions errors, and other issues. See the [Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html) for more information on using the utility.

## Run the `ISO3DFD` Program
### Configurable Application Parameters
You can specify input parameters for the program. Different devices and variants require different inputs.

Usage: `iso3dfd.exe n1 n2 n3 b1 b2 b3 iterations [omp|sycl] [gpu|cpu]`

|Parameter | Description
|:--- |:---
|`n1 n2 n3` | Grid sizes for the stencil.
|`b1 b2 b3` | (OMP) Cache block sizes for cpu openmp version.
|`b1 b2` | (SYCL) Thread block sizes in X and Y dimensions for SYCL version.
|`b3` | (SYCL) Size of slice of work in Z dimension for SYCL version.
|`iterations` | Number of timesteps.
|`omp\|sycl` | (Optional) Run the OpenMP or the SYCL variant. Default to both for validation.
|`gpu\|cpu` | (Optional) Device for the SYCL version; default to GPU if available. If a GPU is not available, the program runs on the CPU.

### On Linux
1. Run the program.
```
make run
```
Alternatively, you can select CPU as a SYCL device by using `make run_cpu`.

### On Windows
1. Change to the output directory.
2. Specify the input values, and run the program.
```
iso3dfd_dpcpp.exe 256 256 256 32 8 64 10 gpu
```

### Run Samples in Intel&reg; DevCloud
If running a sample in the Intel&reg; DevCloud, you must specify the compute node (CPU, GPU, FPGA) and whether to run in batch or interactive mode. For more information, see the Intel&reg; oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/).
### Build and Run the `ISO3DFD` Sample in Intel® DevCloud (Optional)
When running a sample in the Intel® DevCloud, you must specify the compute node (CPU, GPU, FPGA) and whether to run in batch or interactive mode. You can specify a GPU node using a single line script.

```
qsub -I -l nodes=1:gpu:ppn=2 -d .
```

## Run the Sample
1. Run the sample.
```
make run
```
### Application Parameters
You can modify the ISO3DFD parameters from the command line with configurable application parameters:
- `-I` (upper case I) requests an interactive session.
- `-l nodes=1:gpu:ppn=2` (lower case L) assigns one full GPU node.
- `-d .` makes the current folder as the working directory for the task.

Usage: `src/iso3dfd.exe n1 n2 n3 b1 b2 b3 Iterations [omp|sycl] [gpu|cpu]`
For more information on how to specify compute nodes read, [Launch and manage jobs](https://devcloud.intel.com/oneapi/documentation/job-submission/) in the Intel® DevCloud for oneAPI Documentation.

- `n1 n2 n3`: Grid sizes for the stencil.
- `b1 b2 b3`: cache block sizes for cpu openmp version.
OR
- `b1 b2`: Thread block sizes in X and Y dimensions for SYCL version.
- and `b3`: size of slice of work in Z dimension for SYCL version.
- `Iterations`: Number of timesteps.
- `[omp|sycl]`: (Optional) Run the OpenMP or the SYCL variant. Default uses both for validation.
- `[gpu|cpu]`: (Optional) Device to run the SYCL version. Default uses the GPU if available. if GPU is not available then fallback to CPU.
For more information on using Intel® DevCloud, see the Intel® oneAPI Base Toolkit [Get Started Guide](https://devcloud.intel.com/oneapi/get_started/).

### Example of Output
## Example Output
```
Grid Sizes: 256 256 256
Memory Usage: 230 MB
Expand Down Expand Up @@ -165,9 +190,9 @@ bytes : 3.36952 GBytes/s
Final wavefields from SYCL device and CPU are equivalent: Success
--------------------------------------
```
## License

## License
Code samples are licensed under the MIT license. See
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.

Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt).
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt).