Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <cuda_runtime.h>
#include "kernel.h"
#include "kernel.cu"
#include "dev_array.h"
#include <math.h>
#include<stdio.h>
#include<cuda.h>
__global__ void arradd(int *x,int *y, int *z)
{
int id=blockIdx.x * blockDim.x+threadIdx.x;
/* blockIdx.x gives the respective block id which starts from 0 */
/* threadIdx.x gives the respective thread id which starts from 0 */
/* blockDim.x gives the dimension of block i.e. number of threads in one block */
z[id]=x[id]+y[id];
}
@Bhavya031
Bhavya031 / matix.c
Created September 11, 2023 04:36
cuda matix multiplication
#include <stdio.h>
#include <cuda.h>
#define N 3 // Matrix size (3x3)
__global__ void matrixMultiply(int *a, int *b, int *c)
{
int row = blockIdx.y * blockDim.y + threadIdx.y;
int col = blockIdx.x * blockDim.x + threadIdx.x;
@Bhavya031
Bhavya031 / matix.c
Created September 11, 2023 04:34
cuda matrix multiplication
#include <stdio.h>
// Matrix dimensions
#define N 4
#define M 4
#define P 4
// CUDA kernel for matrix multiplication
__global__ void matrixMul(int *a, int *b, int *c) {
int row = blockIdx.y * blockDim.y + threadIdx.y;
/*
* Copyright (c) 2018 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*