mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-12-23 14:54:28 +00:00
38 lines
908 B
Plaintext
38 lines
908 B
Plaintext
#include "cuda_helper.cuh"
|
|
#include "max_pooling.hpp"
|
|
#include "pooling.cuh"
|
|
|
|
using namespace CUDANet::Layers;
|
|
|
|
void MaxPooling2d::initCUDA() {
|
|
d_output = nullptr;
|
|
CUDA_CHECK(cudaMalloc(
|
|
(void**)&d_output,
|
|
sizeof(float) * outputSize.first * outputSize.second * nChannels
|
|
));
|
|
}
|
|
|
|
void MaxPooling2d::delCUDA() {
|
|
cudaFree(d_output);
|
|
}
|
|
|
|
|
|
float* MaxPooling2d::forwardCUDA(const float* d_input) {
|
|
dim3 block(8, 8, 8);
|
|
dim3 grid(
|
|
(outputSize.first + block.x - 1) / block.x,
|
|
(outputSize.second + block.y - 1) / block.y,
|
|
(nChannels + block.z - 1) / block.z
|
|
);
|
|
|
|
Kernels::max_pooling<<<grid, block>>>(
|
|
d_input, d_output, inputSize, outputSize, nChannels, poolingSize,
|
|
stride, padding
|
|
);
|
|
CUDA_CHECK(cudaGetLastError());
|
|
|
|
activation->activate(d_output);
|
|
CUDA_CHECK(cudaDeviceSynchronize());
|
|
|
|
return d_output;
|
|
} |