Cuda Add Mult
Cuda Add Mult
nvcc --version
-----------------------------------------------
!pip install git+https://github.com/andreinechaev/nvcc4jupyter.git
-----------------------------------------------
%load_ext nvcc_plugin
-----------------------------------------------
# VECTOR ADDITION
%%cu
#include <stdio.h>
int main()
{
int size = 100; // Size of the vectors
int* a, * b, * c; // Host vectors
int* dev_a, * dev_b, * dev_c; // Device vectors
// Print result
for (int i = 0; i < size; i++) {
printf("%d + %d = %d\n", a[i], b[i], c[i]);
}
return 0;
}
-----------------------------------------------
# MATRIX MULTIPLICATION
%%cu
#include <stdio.h>
int main() {
int rowsA = 10; // Rows of matrix A
int colsA = 10; // Columns of matrix A
int rowsB = colsA; // Rows of matrix B
int colsB = 10; // Columns of matrix B
// Print result
printf("Result:\n");
for (int i = 0; i < rowsA; i++) {
for (int j = 0; j < colsB; j++) {
printf("%d ", c[i * colsB + j]);
}
printf("\n");
}
return 0;
}