Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bl33h/productoftwovectors
This code utilizes CUDA for parallel vector multiplication on a GPU, demonstrating GPU's acceleration capabilities.
https://github.com/bl33h/productoftwovectors
cuda gpu kernel paralelism parallel-programming product vector
Last synced: 20 days ago
JSON representation
This code utilizes CUDA for parallel vector multiplication on a GPU, demonstrating GPU's acceleration capabilities.
- Host: GitHub
- URL: https://github.com/bl33h/productoftwovectors
- Owner: bl33h
- Created: 2022-10-13T13:17:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-17T21:54:27.000Z (over 1 year ago)
- Last Synced: 2024-11-20T20:35:25.364Z (3 months ago)
- Topics: cuda, gpu, kernel, paralelism, parallel-programming, product, vector
- Language: C++
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# productOfTwoVectors
This code leverages CUDA to perform parallel element-wise multiplication of two vectors using a GPU. It allocates memory for the input and output vectors, initializes the input vectors, and transfers the data to the GPU. The CUDA kernel function executes the multiplication in parallel and displays intermediate results. Finally, the code copies the result back to the host, verifies it, frees the memory, and terminates. It showcases how CUDA harnesses GPU parallelism to accelerate vector operations effectively.
![]()
Files •
Features •
How To Use## Files
- src: the file that implements de solution.
## Features
The main features of the application include:
- Parallel Processing: It utilizes CUDA to execute the `productOfTwoVectors` kernel function in parallel on a GPU. This allows for efficient processing of the element-wise vector multiplication by utilizing multiple threads.
- Memory Management: The code demonstrates proper memory allocation and deallocation for both host and device memory. It uses `cudaMalloc()` to allocate memory on the GPU and `free()` to free the memory on the host.
- Data Transfer: The code utilizes `cudaMemcpy()` to transfer data between the host and the device. It copies the input vectors from the host memory to the device memory and copies the result vector from the device memory back to the host memory.
- Error Handling: The code checks for errors after each CUDA operation and prints error messages if any occur. It ensures proper error handling and termination of the program in case of failures.
- Verification: After the computation, the code verifies the correctness of the result vector by comparing it with the sum of the individual elements. It checks for any discrepancies and displays an error message if the verification fails.
- Intermediate Result Display: The code prints intermediate results during the execution of the `productOfTwoVectors` kernel function. It displays the multiplication of each pair of elements from the input vectors, providing insight into the parallel computation process.## How To Use
To clone and run this application, you'll need [Git](https://git-scm.com) and a [C++ compiler](https://www.fdi.ucm.es/profesor/luis/fp/devtools/mingw.html) installed on your computer. From your command line:```bash
# Clone this repository
$ git clone https://github.com/bl33h/productOfTwoVectors# Open the folder
$ cd src# Run the app
$ g++ productOfTwoVectors.cpp -o productOfTwoVectors
$ ./productOfTwoVectors
```Alternatively, you can run the code using Google Colab:
1. [Open Google Colab](https://colab.research.google.com) in your web browser.
2. Click on "File" in the top menu, then select "Open notebook".
3. In the "GitHub" tab, enter the repository URL: https://github.com/bl33h/productOfTwoVectors
4. Choose the desired notebook file and click "Open".
5. Follow the instructions within the Colab notebook to execute the code.Note: Running the code in Google Colab requires an internet connection and a Google account. It provides a convenient online environment for executing code without the need for local setup or dependencies.