mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 01:34:22 +00:00
Add matrix math kernels
This commit is contained in:
19
include/kernels/matrix_math.cuh
Normal file
19
include/kernels/matrix_math.cuh
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef MATRIX_MATH_H
|
||||
#define MATRIX_MATH_H
|
||||
|
||||
__global__ void mat_vec_mul_kernel(
|
||||
const float* d_matrix,
|
||||
const float* d_vector,
|
||||
float* d_output,
|
||||
int w,
|
||||
int h
|
||||
);
|
||||
|
||||
__global__ void vec_vec_add_kernel(
|
||||
const float* d_vector1,
|
||||
const float* d_vector2,
|
||||
float* d_output,
|
||||
int w
|
||||
);
|
||||
|
||||
#endif // MATRIX_MATH_H
|
||||
34
src/kernels/matrix_math.cu
Normal file
34
src/kernels/matrix_math.cu
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "matrix_math.cuh"
|
||||
|
||||
__global__ void mat_vec_mul_kernel(
|
||||
const float* d_matrix,
|
||||
const float* d_vector,
|
||||
float* d_output,
|
||||
int w,
|
||||
int h
|
||||
) {
|
||||
|
||||
int tid = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
if (tid >= w * h) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < w; i++) {
|
||||
d_output[tid] += d_matrix[tid * w + i] * d_vector[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__global__ void vec_vec_add_kernel(
|
||||
const float* d_vector1,
|
||||
const float* d_vector2,
|
||||
float* d_output,
|
||||
int w
|
||||
) {
|
||||
int tid = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
if (tid >= w) {
|
||||
return;
|
||||
}
|
||||
d_output[tid] = d_vector1[tid] + d_vector2[tid];
|
||||
}
|
||||
Reference in New Issue
Block a user