mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-12-23 14:54:28 +00:00
Migrate max pooling
This commit is contained in:
67
src/layers/max_pooling.cpp
Normal file
67
src/layers/max_pooling.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "max_pooling.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
MaxPooling2d::MaxPooling2d(
|
||||
shape2d inputSize,
|
||||
int nChannels,
|
||||
shape2d poolingSize,
|
||||
shape2d stride,
|
||||
shape2d padding,
|
||||
ActivationType activationType
|
||||
)
|
||||
: inputSize(inputSize),
|
||||
nChannels(nChannels),
|
||||
poolingSize(poolingSize),
|
||||
stride(stride),
|
||||
padding(padding) {
|
||||
outputSize = {
|
||||
(inputSize.first + 2 * padding.first - poolingSize.first) /
|
||||
stride.first +
|
||||
1,
|
||||
(inputSize.second + 2 * padding.second - poolingSize.second) /
|
||||
stride.second +
|
||||
1
|
||||
};
|
||||
|
||||
activation = new Activation(
|
||||
activationType, outputSize.first * outputSize.second * nChannels
|
||||
);
|
||||
|
||||
#ifdef USE_CUDA
|
||||
initCUDA();
|
||||
#endif
|
||||
}
|
||||
|
||||
MaxPooling2d::~MaxPooling2d() {
|
||||
#ifdef USE_CUDA
|
||||
delCUDA();
|
||||
#endif
|
||||
delete activation;
|
||||
}
|
||||
|
||||
float* MaxPooling2d::forwardCPU(const float* input) {
|
||||
throw std::logic_error("Not implemented");
|
||||
}
|
||||
|
||||
float* MaxPooling2d::forward(const float* input) {
|
||||
#ifdef USE_CUDA
|
||||
return forwardCUDA(input);
|
||||
#else
|
||||
return forwardCPU(input);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int MaxPooling2d::getOutputSize() {
|
||||
return outputSize.first * outputSize.second * nChannels;
|
||||
}
|
||||
|
||||
int MaxPooling2d::getInputSize() {
|
||||
return inputSize.first * inputSize.second * nChannels;
|
||||
}
|
||||
|
||||
shape2d MaxPooling2d::getOutputDims() {
|
||||
return outputSize;
|
||||
}
|
||||
Reference in New Issue
Block a user