Skip to content

adding Jupyter Notebooks for cuda to sycl migration learning path #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright Intel Corporation

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Title
CUDA_To_SYCL_Migration - Module 1: Simple VectorAdd

## Requirements
| Optimized for | Description
|:--- |:---
| OS | Linux* Ubuntu 18.04, 20 Windows* 10
| Hardware | Skylake with GEN9 or newer
| Software | Intel® oneAPI DPC++ Compiler, Jupyter Notebooks, Intel Devcloud

## Purpose
The hands-on exercises in this notebook show how to implement migrate CUDA source to SYCL source using SYCLomatic Tool

## 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)

## Install Directions

The Jupyter notebooks are tested and can be run on Intel Devcloud.
Below are the steps to access these Jupyter notebooks on Intel Devcloud
1. Register on [Intel Devcloud](https://devcloud.intel.com/oneapi)
2. Go to the "Terminal" in the Intel Devcloud
3. Type in the below command to download the oneAPI-essentials series notebooks into your Devcloud account
/data/oneapi_workshop/get_jupyter_notebooks.sh
4. Navigate to CUDA_To_SYCL_Migration folder and open the Welcome.ipynb

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//==============================================================
// Copyright © Intel Corporation
//
// SPDX-License-Identifier: MIT
// =============================================================

#include <cuda.h>
#include <iostream>
#include <vector>
#define N 16

//# kernel code to perform VectorAdd on GPU
__global__ void VectorAddKernel(float* A, float* B, float* C)
{
C[threadIdx.x] = A[threadIdx.x] + B[threadIdx.x];
}

int main()
{
//# Initialize vectors on host
float A[N] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
float B[N] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
float C[N] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

//# Allocate memory on device
float *d_A, *d_B, *d_C;
cudaMalloc(&d_A, N*sizeof(float));
cudaMalloc(&d_B, N*sizeof(float));
cudaMalloc(&d_C, N*sizeof(float));

//# copy vector data from host to device
cudaMemcpy(d_A, A, N*sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(d_B, B, N*sizeof(float), cudaMemcpyHostToDevice);

//# sumbit task to compute VectorAdd on device
VectorAddKernel<<<1, N>>>(d_A, d_B, d_C);

//# copy result of vector data from device to host
cudaMemcpy(C, d_C, N*sizeof(float), cudaMemcpyDeviceToHost);

//# print result on host
for (int i = 0; i < N; i++) std::cout<< C[i] << " ";
std::cout << "\n";

//# free allocation on device
cudaFree(d_A);
cudaFree(d_B);
cudaFree(d_C);
return 0;
}
Loading