Initialize conv2d layer

This commit is contained in:
2024-03-04 22:16:03 +01:00
parent f37320594a
commit cfc5c46d5e
5 changed files with 148 additions and 32 deletions

View File

@@ -1,31 +0,0 @@
#ifndef CONV_LAYER_H
#define CONV_LAYER_H
#include <cublas_v2.h>
namespace Layers {
class Conv {
public:
Conv(
int inputSize,
int outputSize,
int kernelSize,
cublasHandle_t cublasHandle
);
~Conv();
void forward(const float* input, float* output);
private:
int inputSize;
int outputSize;
int kernelSize;
cublasHandle_t cublasHandle;
float* d_weights;
float* d_biases;
};
} // namespace Layers
#endif // CONV_LAYER_H

60
include/layers/conv2d.cuh Normal file
View File

@@ -0,0 +1,60 @@
#ifndef CONV_LAYER_H
#define CONV_LAYER_H
#include <cublas_v2.h>
#include <string>
#include <vector>
#include "activations.cuh"
namespace Layers {
class Conv2d {
public:
Conv2d(
int inputSize,
int inputChannels,
int kernelSize,
int stride,
std::string padding,
int numFilters,
Activation activation,
cublasHandle_t cublasHandle
);
~Conv2d();
void forward(const float* d_input, float* d_output);
private:
// Inputs
int inputSize;
int inputChannels;
// Kernel
int kernelSize;
int stride;
int paddingSize;
int numFilters;
// Outputs
int outputSize;
// Kernels
std::vector<float> kernels;
// Cuda
cublasHandle_t cublasHandle;
float* d_kernels;
float* d_padded;
// Kernels
Activation activation;
void initializeKernels();
void toCuda();
};
} // namespace Layers
#endif // CONV_LAYER_H

View File

@@ -21,7 +21,7 @@ class Dense : public ILayer {
);
~Dense();
void forward(const float* input, float* output);
void forward(const float* d_input, float* d_output);
void setWeights(const std::vector<std::vector<float>>& weights);
void setBiases(const std::vector<float>& biases);