Skip to content

Commit 61679a3

Browse files
authored
adding Jupyter Notebooks for cuda to sycl migration learning path (#1439)
1 parent f37db70 commit 61679a3

File tree

158 files changed

+62243
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+62243
-0
lines changed

DirectProgramming/C++SYCL/Jupyter/cuda-to-sycl-migration-training/00_SYCL_Migration_Introduction/00_SYCL_Migration_Introduction.ipynb

+281
Large diffs are not rendered by default.

DirectProgramming/C++SYCL/Jupyter/cuda-to-sycl-migration-training/01_SYCL_Migration_Simple_VectorAdd/01_SYCL_Migration_Simple_VectorAdd.ipynb

+490
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Copyright Intel Corporation
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Title
2+
CUDA_To_SYCL_Migration - Module 1: Simple VectorAdd
3+
4+
## Requirements
5+
| Optimized for | Description
6+
|:--- |:---
7+
| OS | Linux* Ubuntu 18.04, 20 Windows* 10
8+
| Hardware | Skylake with GEN9 or newer
9+
| Software | Intel® oneAPI DPC++ Compiler, Jupyter Notebooks, Intel Devcloud
10+
11+
## Purpose
12+
The hands-on exercises in this notebook show how to implement migrate CUDA source to SYCL source using SYCLomatic Tool
13+
14+
## License
15+
Code samples are licensed under the MIT license. See [License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.
16+
17+
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)
18+
19+
## Install Directions
20+
21+
The Jupyter notebooks are tested and can be run on Intel Devcloud.
22+
Below are the steps to access these Jupyter notebooks on Intel Devcloud
23+
1. Register on [Intel Devcloud](https://devcloud.intel.com/oneapi)
24+
2. Go to the "Terminal" in the Intel Devcloud
25+
3. Type in the below command to download the oneAPI-essentials series notebooks into your Devcloud account
26+
/data/oneapi_workshop/get_jupyter_notebooks.sh
27+
4. Navigate to CUDA_To_SYCL_Migration folder and open the Welcome.ipynb
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//==============================================================
2+
// Copyright © Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
7+
#include <cuda.h>
8+
#include <iostream>
9+
#include <vector>
10+
#define N 16
11+
12+
//# kernel code to perform VectorAdd on GPU
13+
__global__ void VectorAddKernel(float* A, float* B, float* C)
14+
{
15+
C[threadIdx.x] = A[threadIdx.x] + B[threadIdx.x];
16+
}
17+
18+
int main()
19+
{
20+
//# Initialize vectors on host
21+
float A[N] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
22+
float B[N] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
23+
float C[N] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
24+
25+
//# Allocate memory on device
26+
float *d_A, *d_B, *d_C;
27+
cudaMalloc(&d_A, N*sizeof(float));
28+
cudaMalloc(&d_B, N*sizeof(float));
29+
cudaMalloc(&d_C, N*sizeof(float));
30+
31+
//# copy vector data from host to device
32+
cudaMemcpy(d_A, A, N*sizeof(float), cudaMemcpyHostToDevice);
33+
cudaMemcpy(d_B, B, N*sizeof(float), cudaMemcpyHostToDevice);
34+
35+
//# sumbit task to compute VectorAdd on device
36+
VectorAddKernel<<<1, N>>>(d_A, d_B, d_C);
37+
38+
//# copy result of vector data from device to host
39+
cudaMemcpy(C, d_C, N*sizeof(float), cudaMemcpyDeviceToHost);
40+
41+
//# print result on host
42+
for (int i = 0; i < N; i++) std::cout<< C[i] << " ";
43+
std::cout << "\n";
44+
45+
//# free allocation on device
46+
cudaFree(d_A);
47+
cudaFree(d_B);
48+
cudaFree(d_C);
49+
return 0;
50+
}

0 commit comments

Comments
 (0)