From 6dca8ccd3cc7d205abd5e938521cabf4c0beadb0 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Mon, 20 May 2024 16:23:58 +0200 Subject: [PATCH] Unify 2d layer naming --- examples/alexnet/alexnet.cpp | 6 +++--- examples/inception_v3/inception_v3.cpp | 2 +- include/layers/avg_pooling.cuh | 6 +++--- include/layers/batch_norm.cuh | 6 +++--- include/layers/max_pooling.cuh | 6 +++--- src/layers/avg_pooling.cu | 10 +++++----- src/layers/batch_norm.cu | 24 ++++++++++++------------ src/layers/max_pooling.cu | 10 +++++----- test/layers/test_avg_pooling.cu | 2 +- test/layers/test_batch_norm.cu | 4 ++-- test/layers/test_max_pooling.cu | 2 +- test/model/test_model.cu | 4 ++-- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/examples/alexnet/alexnet.cpp b/examples/alexnet/alexnet.cpp index 9edfdb2..fd61c79 100644 --- a/examples/alexnet/alexnet.cpp +++ b/examples/alexnet/alexnet.cpp @@ -45,7 +45,7 @@ CUDANet::Model *createModel( CUDANet::Layers::ActivationType::RELU ); model->addLayer("features.0", conv1); // Match pytorch naming - CUDANet::Layers::MaxPooling2D *pool1 = new CUDANet::Layers::MaxPooling2D( + CUDANet::Layers::MaxPooling2d *pool1 = new CUDANet::Layers::MaxPooling2d( 56, 64, 3, 2, CUDANet::Layers::ActivationType::NONE ); model->addLayer("pool1", pool1); @@ -55,7 +55,7 @@ CUDANet::Model *createModel( 27, 64, 5, 1, 192, 2, CUDANet::Layers::ActivationType::RELU ); model->addLayer("features.3", conv2); - CUDANet::Layers::MaxPooling2D *pool2 = new CUDANet::Layers::MaxPooling2D( + CUDANet::Layers::MaxPooling2d *pool2 = new CUDANet::Layers::MaxPooling2d( 27, 192, 3, 2, CUDANet::Layers::ActivationType::NONE ); model->addLayer("pool2", pool2); @@ -77,7 +77,7 @@ CUDANet::Model *createModel( 13, 256, 3, 1, 256, 1, CUDANet::Layers::ActivationType::RELU ); model->addLayer("features.10", conv5); - CUDANet::Layers::MaxPooling2D *pool5 = new CUDANet::Layers::MaxPooling2D( + CUDANet::Layers::MaxPooling2d *pool5 = new CUDANet::Layers::MaxPooling2d( 13, 256, 3, 2, CUDANet::Layers::ActivationType::NONE ); model->addLayer("pool5", pool5); diff --git a/examples/inception_v3/inception_v3.cpp b/examples/inception_v3/inception_v3.cpp index 5c1715b..6a60911 100644 --- a/examples/inception_v3/inception_v3.cpp +++ b/examples/inception_v3/inception_v3.cpp @@ -30,7 +30,7 @@ class BasicConv2d : public CUDANet::Module { int batchNormSize = conv->getOutputSize(); - CUDANet::Layers::BatchNorm2D *batchNorm = new CUDANet::Layers::BatchNorm2D( + CUDANet::Layers::BatchNorm2d *batchNorm = new CUDANet::Layers::BatchNorm2d( batchNormSize, outputChannels, 1e-3f, CUDANet::Layers::ActivationType::RELU ); diff --git a/include/layers/avg_pooling.cuh b/include/layers/avg_pooling.cuh index 7815158..60070ae 100644 --- a/include/layers/avg_pooling.cuh +++ b/include/layers/avg_pooling.cuh @@ -6,16 +6,16 @@ namespace CUDANet::Layers { -class AvgPooling2D : public SequentialLayer { +class AvgPooling2d : public SequentialLayer { public: - AvgPooling2D( + AvgPooling2d( dim2d inputSize, int nChannels, dim2d poolingSize, dim2d stride, ActivationType activationType ); - ~AvgPooling2D(); + ~AvgPooling2d(); float* forward(const float* d_input); diff --git a/include/layers/batch_norm.cuh b/include/layers/batch_norm.cuh index c423c34..eb1cd19 100644 --- a/include/layers/batch_norm.cuh +++ b/include/layers/batch_norm.cuh @@ -8,11 +8,11 @@ namespace CUDANet::Layers { -class BatchNorm2D : public WeightedLayer { +class BatchNorm2d : public WeightedLayer { public: - BatchNorm2D(dim2d inputSize, int inputChannels, float epsilon, ActivationType activationType); + BatchNorm2d(dim2d inputSize, int inputChannels, float epsilon, ActivationType activationType); - ~BatchNorm2D(); + ~BatchNorm2d(); /** * @brief Compute the forward pass of the batchnorm layer diff --git a/include/layers/max_pooling.cuh b/include/layers/max_pooling.cuh index 0715a80..e2aaa81 100644 --- a/include/layers/max_pooling.cuh +++ b/include/layers/max_pooling.cuh @@ -6,16 +6,16 @@ namespace CUDANet::Layers { -class MaxPooling2D : public SequentialLayer { +class MaxPooling2d : public SequentialLayer { public: - MaxPooling2D( + MaxPooling2d( dim2d inputSize, int nChannels, dim2d poolingSize, dim2d stride, ActivationType activationType ); - ~MaxPooling2D(); + ~MaxPooling2d(); float* forward(const float* d_input); diff --git a/src/layers/avg_pooling.cu b/src/layers/avg_pooling.cu index c5c9bba..898fd66 100644 --- a/src/layers/avg_pooling.cu +++ b/src/layers/avg_pooling.cu @@ -4,7 +4,7 @@ using namespace CUDANet::Layers; -AvgPooling2D::AvgPooling2D( +AvgPooling2d::AvgPooling2d( dim2d inputSize, int nChannels, dim2d poolingSize, @@ -31,12 +31,12 @@ AvgPooling2D::AvgPooling2D( )); } -AvgPooling2D::~AvgPooling2D() { +AvgPooling2d::~AvgPooling2d() { cudaFree(d_output); delete activation; } -float* AvgPooling2D::forward(const float* d_input) { +float* AvgPooling2d::forward(const float* d_input) { dim3 block(8, 8, 8); dim3 grid( (outputSize.first + block.x - 1) / block.x, @@ -55,10 +55,10 @@ float* AvgPooling2D::forward(const float* d_input) { return d_output; } -int AvgPooling2D::getOutputSize() { +int AvgPooling2d::getOutputSize() { return outputSize.first * outputSize.second * nChannels; } -int AvgPooling2D::getInputSize() { +int AvgPooling2d::getInputSize() { return inputSize.first * inputSize.second * nChannels; } \ No newline at end of file diff --git a/src/layers/batch_norm.cu b/src/layers/batch_norm.cu index bfbd7b6..774778c 100644 --- a/src/layers/batch_norm.cu +++ b/src/layers/batch_norm.cu @@ -9,7 +9,7 @@ using namespace CUDANet::Layers; -BatchNorm2D::BatchNorm2D( +BatchNorm2d::BatchNorm2d( dim2d inputSize, int inputChannels, float epsilon, @@ -72,7 +72,7 @@ BatchNorm2D::BatchNorm2D( (inputSize.first * inputSize.second + BLOCK_SIZE - 1) / BLOCK_SIZE; } -BatchNorm2D::~BatchNorm2D() { +BatchNorm2d::~BatchNorm2d() { cudaFree(d_output); cudaFree(d_mean); cudaFree(d_mean_sub); @@ -83,33 +83,33 @@ BatchNorm2D::~BatchNorm2D() { cudaFree(d_epsilon); } -void BatchNorm2D::initializeWeights() { +void BatchNorm2d::initializeWeights() { std::fill(weights.begin(), weights.end(), 1.0f); } -void BatchNorm2D::initializeBiases() { +void BatchNorm2d::initializeBiases() { std::fill(biases.begin(), biases.end(), 0.0f); } -void BatchNorm2D::setWeights(const float *weights_input) { +void BatchNorm2d::setWeights(const float *weights_input) { std::copy(weights_input, weights_input + weights.size(), weights.begin()); toCuda(); } -std::vector BatchNorm2D::getWeights() { +std::vector BatchNorm2d::getWeights() { return weights; } -void BatchNorm2D::setBiases(const float *biases_input) { +void BatchNorm2d::setBiases(const float *biases_input) { std::copy(biases_input, biases_input + biases.size(), biases.begin()); toCuda(); } -std::vector BatchNorm2D::getBiases() { +std::vector BatchNorm2d::getBiases() { return biases; } -void BatchNorm2D::toCuda() { +void BatchNorm2d::toCuda() { CUDA_CHECK(cudaMemcpy( d_weights, weights.data(), sizeof(float) * inputChannels, cudaMemcpyHostToDevice @@ -120,15 +120,15 @@ void BatchNorm2D::toCuda() { )); } -int BatchNorm2D::getInputSize() { +int BatchNorm2d::getInputSize() { return inputSize.first * inputSize.second * inputChannels; } -int BatchNorm2D::getOutputSize() { +int BatchNorm2d::getOutputSize() { return inputSize.first * inputSize.second * inputChannels; } -float *BatchNorm2D::forward(const float *d_input) { +float *BatchNorm2d::forward(const float *d_input) { // Compute per-channel batch normalization for (int i = 0; i < inputChannels; i++) { // Compute mean diff --git a/src/layers/max_pooling.cu b/src/layers/max_pooling.cu index ee43f7d..fd48227 100644 --- a/src/layers/max_pooling.cu +++ b/src/layers/max_pooling.cu @@ -4,7 +4,7 @@ using namespace CUDANet::Layers; -MaxPooling2D::MaxPooling2D( +MaxPooling2d::MaxPooling2d( dim2d inputSize, int nChannels, dim2d poolingSize, @@ -29,12 +29,12 @@ MaxPooling2D::MaxPooling2D( )); } -MaxPooling2D::~MaxPooling2D() { +MaxPooling2d::~MaxPooling2d() { cudaFree(d_output); delete activation; } -float* MaxPooling2D::forward(const float* d_input) { +float* MaxPooling2d::forward(const float* d_input) { dim3 block(8, 8, 8); dim3 grid( (outputSize.first + block.x - 1) / block.x, @@ -53,10 +53,10 @@ float* MaxPooling2D::forward(const float* d_input) { return d_output; } -int MaxPooling2D::getOutputSize() { +int MaxPooling2d::getOutputSize() { return outputSize.first * outputSize.second * nChannels; } -int MaxPooling2D::getInputSize() { +int MaxPooling2d::getInputSize() { return inputSize.first * inputSize.second * nChannels; } \ No newline at end of file diff --git a/test/layers/test_avg_pooling.cu b/test/layers/test_avg_pooling.cu index 0ec6b8c..cd6a90b 100644 --- a/test/layers/test_avg_pooling.cu +++ b/test/layers/test_avg_pooling.cu @@ -28,7 +28,7 @@ TEST(AvgPoolingLayerTest, AvgPoolForwardTest) { // clang-format on }; - CUDANet::Layers::AvgPooling2D avgPoolingLayer( + CUDANet::Layers::AvgPooling2d avgPoolingLayer( inputSize, nChannels, poolingSize, stride, CUDANet::Layers::ActivationType::NONE ); diff --git a/test/layers/test_batch_norm.cu b/test/layers/test_batch_norm.cu index e04b1f2..25db618 100644 --- a/test/layers/test_batch_norm.cu +++ b/test/layers/test_batch_norm.cu @@ -12,7 +12,7 @@ TEST(BatchNormLayerTest, BatchNormSmallForwardTest) { cudaError_t cudaStatus; - CUDANet::Layers::BatchNorm2D batchNorm( + CUDANet::Layers::BatchNorm2d batchNorm( inputSize, nChannels, 1e-5f, CUDANet::Layers::ActivationType::NONE ); @@ -69,7 +69,7 @@ TEST(BatchNormLayerTest, BatchNormSmallForwardTest) { -0.0269f, 0.26878f, 0.81411f, 0.09022f, 0.9126f, 0.71485f, -0.08184f, -0.19131f}; - // std::cout << "BatchNorm2D: " << std::endl; + // std::cout << "BatchNorm2d: " << std::endl; for (int i = 0; i < output.size(); i++) { EXPECT_NEAR(output[i], expected[i], 1e-5); // std::cout << output[i] << " "; diff --git a/test/layers/test_max_pooling.cu b/test/layers/test_max_pooling.cu index 552b1dd..cff5210 100644 --- a/test/layers/test_max_pooling.cu +++ b/test/layers/test_max_pooling.cu @@ -28,7 +28,7 @@ TEST(MaxPoolingLayerTest, MaxPoolForwardTest) { // clang-format on }; - CUDANet::Layers::MaxPooling2D maxPoolingLayer( + CUDANet::Layers::MaxPooling2d maxPoolingLayer( inputSize, nChannels, poolingSize, stride, CUDANet::Layers::ActivationType::NONE ); diff --git a/test/model/test_model.cu b/test/model/test_model.cu index 6c8a94c..571cfe4 100644 --- a/test/model/test_model.cu +++ b/test/model/test_model.cu @@ -42,8 +42,8 @@ class ModelTest : public ::testing::Test { inputSize.first - kernelSize.first + 1, inputSize.second - kernelSize.second + 1 }; - CUDANet::Layers::MaxPooling2D *maxpool2d = - new CUDANet::Layers::MaxPooling2D( + CUDANet::Layers::MaxPooling2d *maxpool2d = + new CUDANet::Layers::MaxPooling2d( poolingInput, numFilters, poolingSize, poolingStride, CUDANet::Layers::ActivationType::RELU );