You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DirectProgramming/C++SYCL/MapReduce/guided_MonteCarloMultiGPU_SYCLMigration/02_sycl_migrated/CMakeLists.txt
Copy file name to clipboardExpand all lines: DirectProgramming/C++SYCL/MapReduce/guided_MonteCarloMultiGPU_SYCLMigration/README.md
+70-54Lines changed: 70 additions & 54 deletions
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,21 @@
2
2
3
3
The `MonteCarloMultiGPU` sample evaluates fair call price for a given set of European options using the Monte Carlo approach. MonteCarlo simulation is one of the most important algorithms in quantitative finance. This sample uses a single CPU Thread to control multiple GPUs.
4
4
5
-
| Property | Description
6
-
|:--- |:---
7
-
| What you will learn | Migrating MonteCarloMultiGPU from CUDA to SYCL
8
-
| Time to complete | 15 minutes
5
+
| Area | Description
6
+
|:--- |:---
7
+
| What you will learn | How to begin migrating CUDA to SYCL
8
+
| Time to complete | 15 minutes
9
+
| Category | Code Optimization
10
+
11
+
>**Note**: This sample is migrated from NVIDIA CUDA sample. See the [MonteCarloMultiGPU](https://github.com/NVIDIA/cuda-samples/tree/master/Samples/5_Domain_Specific/MonteCarloMultiGPU) sample in the NVIDIA/cuda-samples GitHub.
9
12
10
13
11
14
## Purpose
12
-
The Monte Carlo Method provides a way to compute expected values by generating random scenarios and then averaging them. The execution of these random scenarios can be parallelized very efficiently.
15
+
The MonteCarlo Method provides a way to compute expected values by generating random scenarios and then averaging them. The execution of these random scenarios can be parallelized very efficiently.
13
16
14
17
With the help of a GPU, we reduce and speed up the problem by parallelizing each path. That is, we can assign each path to a single thread, simulating thousands of them in parallel, with massive savings in computational power and time.
15
18
16
-
> **Note**: We use Intel® open-sources SYCLomatic tool which assists developers in porting CUDA code automatically to SYCL code. To finish the process, developers complete the rest of the coding manually and then tune to the desired level of performance for the target architecture. User's can also use SYCLomatic Tool which comes along with the Intel® oneAPI Base Toolkit.
19
+
> **Note**: The sample used the open-source SYCLomatic tool that assists developers in porting CUDA code to SYCL code. To finish the process, you must complete the rest of the coding manually and then tune to the desired level of performance for the target architecture. You can also use the Intel® DPC++ Compatibility Tool available to augment Base Toolkit.
17
20
18
21
This sample contains two versions in the following folders:
19
22
@@ -22,19 +25,42 @@ This sample contains two versions in the following folders:
22
25
| 01_dpct_output | Contains output of SYCLomatic Tool used to migrate SYCL-compliant code from CUDA code. This SYCL code has some unmigrated code that has to be manually fixed to get full functionality.
23
26
| 02_sycl_migrated | Contains manually migrated SYCL code from CUDA code.
This sample demonstrates the migration of the following prominent CUDA feature:
39
+
- Random Number Generator
40
+
41
+
Calls to cuRAND function APIs are being translated to equivalent Intel® oneAPI Math Kernel Library (oneMKL) function calls.
42
+
43
+
The `MonteCarloOneBlockPerOption()` kernel is the main computation kernel. It calculates the integral over all paths using a single thread block per option.
26
44
27
-
Refer [Workflow](https://www.intel.com/content/www/us/en/developer/tools/oneapi/training/cuda-sycl-migration-workflow.html#gs.s2njvh) for details.
45
+
The `rngSetupStates()` kernel initializes the random number generator states for each thread.
46
+
47
+
The `initMonteCarloGPU()` function allocates memory on the GPU, sets up the random number generator states, and initializes other variables.
48
+
49
+
The `closeMonteCarloGPU()` function computes statistics and deallocates memory on the GPU.
50
+
51
+
Finally, the `MonteCarloGPU()` function performs the main computations by copying data to the GPU, launching the computation kernel, and copying the results back to the host.
52
+
53
+
>**Note**: Refer to [Workflow for a CUDA* to SYCL* Migration](https://www.intel.com/content/www/us/en/developer/tools/oneapi/training/cuda-sycl-migration-workflow.html) for general information about the migration workflow.
28
54
29
55
### CUDA source code evaluation
30
56
31
57
Pricing of European Options can be done by applying the Black-Scholes formula and with MonteCarlo approach.
32
58
33
59
MonteCarlo Method first generates a random number based on a probability distribution. The random number then uses the additional inputs of volatility and time to expiration to generate a stock price. The generated stock price at the time of expiration is then used to calculate the value of the option. The model then calculates results over and over, each time using a different set of random values from the probability functions
34
60
35
-
The first stage of the computation is the generation of a normally distributed N(0, 1)number sequence, which comes down to uniformly distributed sequence generation.Once we’ve generated the desired number of samples, we use them to compute an expected value and confidence width for the underlying option.
61
+
The first stage of the computation is the generation of a normally distributed N(0, 1)number sequence, which comes down to uniformly distributed sequence generation.Once we’ve generated the desired number of samples, we use them to compute an expected value and confidence width for the underlying option.
36
62
37
-
The Black-Scholes model relies on fixed inputs (current stock price, strike price, time until expiration, volatility, risk free rates, and dividend yield).The model is based on geometric Brownian motion with constant drift and volatility.We can calculate the price of the European put and call options explicitly using the Black–Scholes formula.
63
+
The Black-Scholes model relies on fixed inputs (current stock price, strike price, time until expiration, volatility, risk free rates, and dividend yield).The model is based on geometric Brownian motion with constant drift and volatility.We can calculate the price of the European put and call options explicitly using the Black–Scholes formula.
38
64
39
65
The price of a call option C in terms of the Black–Scholes parameters is
40
66
@@ -50,65 +76,54 @@ where:
50
76
51
77
After repeatedly computing appropriate averages, the estimated price of options can be obtained, which is consistent with the analytical results from Black-Scholes model.
52
78
53
-
This sample is migrated from NVIDIA CUDA sample. See the [MonteCarloMultiGPU](https://github.com/NVIDIA/cuda-samples/tree/master/Samples/5_Domain_Specific/MonteCarloMultiGPU) sample in the NVIDIA/cuda-samples GitHub.
79
+
For information on how to use SYCLomatic, refer to the materials at *[Migrate from CUDA* to C++ with SYCL*](https://www.intel.com/content/www/us/en/developer/tools/oneapi/training/migrate-from-cuda-to-cpp-with-sycl.html)*.
54
80
81
+
## Set Environment Variables
55
82
56
-
## Prerequisites
57
-
| Property | Description
58
-
|:--- |:---
59
-
| OS | Ubuntu* 20.04
60
-
| Hardware | Intel® Gen9, Gen11 and Intel® Xeon(R) Gold 6128 CPU
61
-
| Software | SYCLomatic version 2023.1, Intel oneAPI Base Toolkit version 2023.1
83
+
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.
62
84
63
-
For more information on how to install SYCLomatic Tool, visit [Migrate from CUDA* to C++ with SYCL*](https://www.intel.com/content/www/us/en/developer/tools/oneapi/training/migrate-from-cuda-to-cpp-with-sycl.html#gs.v3584e).
85
+
## Migrate the Code Using SYCLomatic
64
86
65
-
## Key Implementation Details
66
-
67
-
This sample demonstrates the migration of the following prominent CUDA feature:
68
-
- Random Number Generator
69
-
70
-
Calls to cuRAND function APIs are being translates to equivalent Intel® oneAPI Math Kernel Library (oneMKL) function calls.
71
-
72
-
The `MonteCarloOneBlockPerOption()` kernel is the main computation kernel. It calculates the integral over all paths using a single thread block per option.
87
+
For this sample, the SYCLomatic tool automatically migrates 100% of the CUDA code to SYCL. Follow these steps to generate the SYCL code using the compatibility tool.
73
88
74
-
The `rngSetupStates()` kernel initializes the random number generator states for each thread.
75
-
76
-
The `initMonteCarloGPU()` function allocates memory on the GPU, sets up the random number generator states, and initializes other variables.
89
+
1. Clone the required GitHub repository to your local environment.
2. Change to the MonteCarloMultiGPU sample directory.
94
+
```
95
+
cd cuda-samples/Samples/5_Domain_Specific/MonteCarloMultiGPU/
96
+
```
97
+
3. Generate a compilation database with intercept-build.
98
+
```
99
+
intercept-build make
100
+
```
101
+
This step creates a JSON file named compile_commands.json with all the compiler invocations and stores the names of the input files and the compiler options.
77
102
78
-
The `closeMonteCarloGPU()` function computes statistics and deallocates memory on the GPU.
103
+
4. Pass the JSON file as input to the Intel® SYCLomatic Compatibility Tool. The result is written to a folder named dpct_output. The `--in-root` specifies path to the root of the source tree to be migrated. The `--use-custom-helper` option will make a copy of dpct header files/functions used in migrated code into the dpct_output folder as include folder.
79
104
80
-
Finally, the `MonteCarloGPU()` function performs the main computations by copying data to the GPU, launching the computation kernel, and copying the results back to the host.
## Build the `MonteCarloMultiGPU` Sample for CPU and GPU
109
+
## Build and Run the `MonteCarloMultiGPU` Sample
83
110
84
111
> **Note**: If you have not already done so, set up your CLI
85
-
> environment by sourcing the `setvars` script located in the root of your oneAPI installation.
112
+
> environment by sourcing the `setvars` script in the root of your oneAPI installation.
86
113
>
87
114
> Linux*:
88
115
> - For system wide installations: `. /opt/intel/oneapi/setvars.sh`
89
-
> - For private installations: `. ~/intel/oneapi/setvars.sh`
90
-
> - For non-POSIX shells, like csh, use the following command: `$ bash -c 'source <install-dir>/setvars.sh ; exec csh'`
116
+
> - For private installations: `. ~/intel/oneapi/setvars.sh`
117
+
> - For non-POSIX shells, like csh, use the following command: `bash -c 'source <install-dir>/setvars.sh ; exec csh'`
91
118
>
92
-
>For more information on 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 [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).
93
-
94
-
## Tool assisted migration – SYCLomatic
95
-
96
-
For this sample, the SYCLomatic Tool automatically migrates 100% of the CUDA code to SYCL. Follow these steps to generate the SYCL code using the compatibility tool:
> - Windows PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'`
122
+
>
123
+
> 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)*.
2. cd cuda-samples/Samples/5_Domain_Specific/MonteCarloMultiGPU/
100
-
3. Generate a compilation database with intercept-build
101
-
```
102
-
intercept-build make
103
-
```
104
-
4. The above step creates a JSON file named compile_commands.json with all the compiler invocations and stores the names of the input files and the compiler options.
105
-
5. Pass the JSON file as input to the Intel® SYCLomatic Compatibility Tool. The result is written to a folder named dpct_output. The --in-root specifies path to the root of the source tree to be migrated.
0 commit comments