mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Migrate Dense layer
This commit is contained in:
@@ -8,15 +8,15 @@
|
||||
#include "pooling.cuh"
|
||||
|
||||
// Layers
|
||||
#include "activation.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "add.cuh"
|
||||
#include "avg_pooling.cuh"
|
||||
#include "batch_norm.cuh"
|
||||
#include "concat.cuh"
|
||||
#include "conv2d.cuh"
|
||||
#include "dense.cuh"
|
||||
#include "dense.hpp"
|
||||
#include "input.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
#include "max_pooling.cuh"
|
||||
#include "output.cuh"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CUDANET_CONVOLUTION_H
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Kernels {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define CUDANET_POOLING_H
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Kernels {
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ class Activation {
|
||||
ActivationType activationType;
|
||||
int length;
|
||||
|
||||
void activateCPU(float* input);
|
||||
|
||||
#ifdef USE_CUDA
|
||||
int gridSize;
|
||||
|
||||
@@ -58,10 +60,7 @@ class Activation {
|
||||
|
||||
void initCUDA();
|
||||
void delCUDA();
|
||||
#else
|
||||
void activateCPU(float* input);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef CUDANET_AVG_POOLING_H
|
||||
#define CUDANET_AVG_POOLING_H
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "convolution.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
@@ -84,20 +84,11 @@ class Dense : public WeightedLayer {
|
||||
int inputSize;
|
||||
int outputSize;
|
||||
|
||||
float* d_output;
|
||||
|
||||
float* d_weights;
|
||||
float* d_biases;
|
||||
|
||||
std::vector<float> weights;
|
||||
std::vector<float> biases;
|
||||
|
||||
Layers::Activation* activation;
|
||||
|
||||
// Precompute kernel launch parameters
|
||||
int forwardGridSize;
|
||||
int biasGridSize;
|
||||
|
||||
/**
|
||||
* @brief Initialize the weights to zeros
|
||||
*
|
||||
@@ -110,11 +101,30 @@ class Dense : public WeightedLayer {
|
||||
*/
|
||||
void initializeBiases();
|
||||
|
||||
float* forwardCPU(const float* input);
|
||||
|
||||
#ifdef USE_CUDA
|
||||
float* d_output;
|
||||
|
||||
float* d_weights;
|
||||
float* d_biases;
|
||||
|
||||
// Precompute kernel launch parameters
|
||||
int forwardGridSize;
|
||||
int biasGridSize;
|
||||
|
||||
/**
|
||||
* @brief Copy the weights and biases to the device
|
||||
*
|
||||
*/
|
||||
void toCuda();
|
||||
|
||||
void initCUDA();
|
||||
void delCUDA();
|
||||
|
||||
float* forwardCUDA(const float* d_input);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CUDANET_INPUT_LAYER_H
|
||||
#define CUDANET_INPUT_LAYER_H
|
||||
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -111,10 +111,12 @@ class WeightedLayer : public SequentialLayer {
|
||||
*/
|
||||
virtual void initializeBiases() = 0;
|
||||
|
||||
#ifdef USE_CUDA
|
||||
/**
|
||||
* @brief Copy the weights and biases to the device
|
||||
*/
|
||||
virtual void toCuda() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef CUDANET_MAX_POOLING_H
|
||||
#define CUDANET_MAX_POOLING_H
|
||||
|
||||
#include "activation.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CUDANET_OUTPUT_LAYER_H
|
||||
#define CUDANET_OUTPUT_LAYER_H
|
||||
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "input.cuh"
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
#include "module.hpp"
|
||||
#include "output.cuh"
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "layer.cuh"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user