https://github.com/marcramonmoreno/cuda_vector_addition
https://github.com/marcramonmoreno/cuda_vector_addition
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/marcramonmoreno/cuda_vector_addition
- Owner: MarcRamonMoreno
- Created: 2024-05-29T10:28:13.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-26T11:19:59.000Z (11 months ago)
- Last Synced: 2025-02-12T17:59:42.269Z (4 months ago)
- Language: Cuda
- Size: 10.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Certainly! Here's a sample `README.md` file for your repository:
# Vector Addition with CUDA
This repository contains a simple CUDA program that performs vector addition. The program reads two vectors from binary files, adds them element-wise using a CUDA kernel, and outputs the result.
## Requirements
To run this program, you need the following:
- CUDA Toolkit installed (version 10.2 or higher recommended)
- A CUDA-capable GPU
- GCC or another compatible compiler for compiling the host code## File Structure
- `main.cu`: The main program file that sets up and executes the CUDA kernel.
- `kernel.cu`: Contains the CUDA kernel for vector addition.
- `kernel.h`: Header file for the CUDA kernel.
- `file.h`: Header file for file I/O functions.
- `Makefile`: Makefile for compiling the program.
- `input1.dat`: Sample binary input file for the first vector (needs to be provided).
- `input2.dat`: Sample binary input file for the second vector (needs to be provided).
- `output.dat`: Output binary file containing the result vector.## Usage
1. **Compile the Program:**
Use the provided Makefile to compile the program:
```sh
make
```2. **Prepare Input Files:**
Ensure you have two binary input files (`input1.dat` and `input2.dat`). The files should be formatted as follows:
- The first 4 bytes (unsigned int) indicate the number of elements in the vector.
- The subsequent bytes represent the vector elements (floats).3. **Run the Program:**
Execute the compiled program with the input files:
```sh
./vecAdd input1.dat input2.dat
```4. **Check the Output:**
The program will print the first 10 values of the resulting vector to the console and write the entire result to `output.dat`.
## Example
Here is an example of how to create an input file in Python:
```python
import struct# Example data
vector_size = 1024
data = [float(i) for i in range(vector_size)]# Write to binary file
with open('input1.dat', 'wb') as f:
f.write(struct.pack('I', vector_size)) # Write the size
for value in data:
f.write(struct.pack('f', value)) # Write the values# Repeat for input2.dat with different or same data
```## Notes
- Make sure your input files are correctly formatted as binary files.
- Ensure your environment has access to a CUDA-capable GPU.
- You can modify the `Makefile` to match your system's CUDA installation path if needed.## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
```Feel free to adjust the paths and filenames as per your repository structure and specific requirements.