mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-12-23 06:44:24 +00:00
WIP Migrate AvgPool2d
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
namespace CUDANet {
|
||||
|
||||
/**
|
||||
* @brief Basic Sequential Layer
|
||||
* @brief Basic Layer
|
||||
*
|
||||
*/
|
||||
class Layer {
|
||||
|
||||
55
include/layers/avg_pool.hpp
Normal file
55
include/layers/avg_pool.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class AvgPool2d : public Layer {
|
||||
public:
|
||||
AvgPool2d(
|
||||
CUDANet::Shape input_shape,
|
||||
CUDANet::Shape pool_shape,
|
||||
CUDANet::Shape stride_shape,
|
||||
CUDANet::Shape padding_shape,
|
||||
CUDANet::Backend *backend
|
||||
);
|
||||
|
||||
~AvgPool2d();
|
||||
|
||||
CUDANet::Tensor& forward(CUDANet::Tensor& input) override;
|
||||
|
||||
CUDANet::Shape input_shape() override;
|
||||
|
||||
CUDANet::Shape output_shape() override;
|
||||
|
||||
size_t input_size() override;
|
||||
|
||||
size_t output_size() override;
|
||||
|
||||
void set_weights(void* input) override;
|
||||
|
||||
CUDANet::Tensor& get_weights() override;
|
||||
|
||||
void set_biases(void* input) override;
|
||||
|
||||
CUDANet::Tensor& get_biases() override;
|
||||
|
||||
protected:
|
||||
CUDANet::Shape in_shape;
|
||||
|
||||
CUDANet::Shape pool_shape;
|
||||
CUDANet::Shape stride_shape;
|
||||
CUDANet::Shape padding_shape;
|
||||
|
||||
CUDANet::Shape out_shape;
|
||||
CUDANet::Tensor output;
|
||||
|
||||
CUDANet::Backend *backend;
|
||||
};
|
||||
|
||||
class AdaptiveAvgPool2d : public AvgPool2d {
|
||||
public:
|
||||
AdaptiveAvgPool2d(CUDANet::Shape input_shape, CUDANet::Shape output_shape, CUDANet::Backend *backend);
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
@@ -1,78 +0,0 @@
|
||||
#ifndef CUDANET_AVG_POOLING_H
|
||||
#define CUDANET_AVG_POOLING_H
|
||||
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
class AvgPooling2d : public Layer, public TwoDLayer {
|
||||
public:
|
||||
AvgPooling2d(
|
||||
shape2d inputSize,
|
||||
int nChannels,
|
||||
shape2d poolingSize,
|
||||
shape2d stride,
|
||||
shape2d padding,
|
||||
ActivationType activationType
|
||||
);
|
||||
~AvgPooling2d();
|
||||
|
||||
float* forward(const float* input);
|
||||
|
||||
/**
|
||||
* @brief Get output size
|
||||
*
|
||||
* @return int output size
|
||||
*/
|
||||
int get_output_size();
|
||||
|
||||
/**
|
||||
* @brief Get input size
|
||||
*
|
||||
* @return int input size
|
||||
*/
|
||||
int getInputSize();
|
||||
|
||||
shape2d getOutputDims();
|
||||
|
||||
protected:
|
||||
shape2d inputSize;
|
||||
int nChannels;
|
||||
shape2d poolingSize;
|
||||
shape2d stride;
|
||||
shape2d padding;
|
||||
|
||||
shape2d outputSize;
|
||||
|
||||
Activation* activation;
|
||||
|
||||
float* forwardCPU(const float* input);
|
||||
|
||||
#ifdef USE_CUDA
|
||||
float* d_output;
|
||||
float* forwardCUDA(const float* d_input);
|
||||
|
||||
void initCUDA();
|
||||
void delCUDA();
|
||||
#endif
|
||||
};
|
||||
|
||||
class AdaptiveAvgPooling2d : public AvgPooling2d {
|
||||
public:
|
||||
AdaptiveAvgPooling2d(
|
||||
shape2d inputShape,
|
||||
int nChannels,
|
||||
shape2d outputShape,
|
||||
ActivationType activationType
|
||||
);
|
||||
|
||||
private:
|
||||
#ifdef USE_CUDA
|
||||
void initCUDA();
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
|
||||
#endif // CUDANET_AVG_POOLING_H
|
||||
Reference in New Issue
Block a user