Add Kernels namespace

This commit is contained in:
2024-03-11 21:04:23 +01:00
parent e0178e2d5c
commit d2ab78fbc7
18 changed files with 188 additions and 186 deletions

View File

@@ -1,19 +1,14 @@
#ifndef ACTIVATIONS_H
#define ACTIVATIONS_H
__global__ void
sigmoid_kernel(const float* __restrict__ src, float* __restrict__ dst, int len);
namespace Kernels {
__global__ void
relu_kernel(const float* __restrict__ src, float* __restrict__ dst, int len);
sigmoid(const float* __restrict__ src, float* __restrict__ dst, int len);
__global__ void
linear_kernel(const float* __restrict__ src, float* __restrict__ dst, int len);
relu(const float* __restrict__ src, float* __restrict__ dst, int len);
enum Activation {
SIGMOID,
RELU,
LINEAR
};
} // namespace Kernels
#endif // ACTIVATIONS_H

View File

@@ -1,7 +1,18 @@
#ifndef CONVOLUTION_H
#define CONVOLUTION_H
__global__ void convolution_kernel(
namespace Kernels {
__global__ void padding(
const float* d_input,
float* d_padded,
int w,
int h,
int n,
int p
);
__global__ void convolution(
const float* d_input,
const float* d_kernel,
float* d_output,
@@ -13,4 +24,6 @@ __global__ void convolution_kernel(
int outputSize
);
} // namespace Kernels
#endif // CONVOLUTION_H

View File

@@ -1,7 +1,9 @@
#ifndef MATRIX_MATH_H
#define MATRIX_MATH_H
#ifndef MATMUL_H
#define MATMUL_H
__global__ void mat_vec_mul_kernel(
namespace Kernels {
__global__ void mat_vec_mul(
const float* d_matrix,
const float* d_vector,
float* d_output,
@@ -9,11 +11,13 @@ __global__ void mat_vec_mul_kernel(
int h
);
__global__ void vec_vec_add_kernel(
__global__ void vec_vec_add(
const float* d_vector1,
const float* d_vector2,
float* d_output,
int w
);
#endif // MATRIX_MATH_H
} // namespace Kernels
#endif // MATMUL_H

View File

@@ -1,18 +0,0 @@
#ifndef PADDING_H
#define PADDING_H
__global__ void pad_matrix_kernel(
const float* d_input,
float* d_padded,
int w,
int h,
int n,
int p
);
enum Padding {
SAME,
VALID
};
#endif // PADDING_H

View File

@@ -5,7 +5,7 @@
#include <vector>
#include "activations.cuh"
#include "padding.cuh"
#include "convolution.cuh"
#include "ilayer.cuh"
namespace Layers {
@@ -13,13 +13,13 @@ namespace Layers {
class Conv2d : public ILayer {
public:
Conv2d(
int inputSize,
int inputChannels,
int kernelSize,
int stride,
Padding padding,
int numFilters,
Activation activation
int inputSize,
int inputChannels,
int kernelSize,
int stride,
Layers::Padding padding,
int numFilters,
Layers::Activation activation
);
~Conv2d();
@@ -52,7 +52,7 @@ class Conv2d : public ILayer {
float* d_padded;
// Kernels
Activation activation;
Layers::Activation activation;
void initializeWeights();
void initializeBiases();

View File

@@ -14,7 +14,7 @@ class Dense : public ILayer {
Dense(
int inputSize,
int outputSize,
Activation activation
Layers::Activation activation
);
~Dense();
@@ -32,7 +32,7 @@ class Dense : public ILayer {
std::vector<float> weights;
std::vector<float> biases;
Activation activation;
Layers::Activation activation;
void initializeWeights();
void initializeBiases();

View File

@@ -6,6 +6,17 @@
namespace Layers {
enum Activation {
SIGMOID,
RELU,
NONE
};
enum Padding {
SAME,
VALID
};
class ILayer {
public:
virtual ~ILayer() {}
@@ -29,7 +40,7 @@ class ILayer {
std::vector<float> weights;
std::vector<float> biases;
Activation activation;
Layers::Activation activation;
};
} // namespace Layers