mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Migrate input layer
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
#include "concat.hpp"
|
#include "concat.hpp"
|
||||||
#include "conv2d.cuh"
|
#include "conv2d.cuh"
|
||||||
#include "dense.hpp"
|
#include "dense.hpp"
|
||||||
#include "input.cuh"
|
#include "input.hpp"
|
||||||
#include "layer.hpp"
|
#include "layer.hpp"
|
||||||
#include "max_pooling.hpp"
|
#include "max_pooling.hpp"
|
||||||
#include "output.cuh"
|
#include "output.cuh"
|
||||||
|
|||||||
@@ -49,7 +49,16 @@ class Input : public SequentialLayer {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int inputSize;
|
int inputSize;
|
||||||
|
|
||||||
|
float* forwardCPU(const float* input);
|
||||||
|
|
||||||
|
#ifdef USE_CUDA
|
||||||
float* d_output;
|
float* d_output;
|
||||||
|
|
||||||
|
float* forwardCUDA(const float* input);
|
||||||
|
void initCUDA();
|
||||||
|
void delCUDA();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CUDANet::Layers
|
} // namespace CUDANet::Layers
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "input.cuh"
|
#include "input.hpp"
|
||||||
#include "layer.hpp"
|
#include "layer.hpp"
|
||||||
#include "module.hpp"
|
#include "module.hpp"
|
||||||
#include "output.cuh"
|
#include "output.cuh"
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
#include "cuda_helper.cuh"
|
#include "cuda_helper.cuh"
|
||||||
#include "input.cuh"
|
#include "input.hpp"
|
||||||
|
|
||||||
using namespace CUDANet::Layers;
|
using namespace CUDANet::Layers;
|
||||||
|
|
||||||
Input::Input(int inputSize) : inputSize(inputSize) {
|
void Input::initCUDA() {
|
||||||
d_output = nullptr;
|
d_output = nullptr;
|
||||||
CUDA_CHECK(cudaMalloc((void**)&d_output, sizeof(float) * inputSize));
|
CUDA_CHECK(cudaMalloc((void**)&d_output, sizeof(float) * inputSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::~Input() {
|
void Input::delCUDA() {
|
||||||
cudaFree(d_output);
|
cudaFree(d_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
float* Input::forward(const float* input) {
|
float* Input::forwardCUDA(const float* input) {
|
||||||
CUDA_CHECK(cudaMemcpy(
|
CUDA_CHECK(cudaMemcpy(
|
||||||
d_output, input, sizeof(float) * inputSize, cudaMemcpyHostToDevice
|
d_output, input, sizeof(float) * inputSize, cudaMemcpyHostToDevice
|
||||||
));
|
));
|
||||||
@@ -20,12 +20,3 @@ float* Input::forward(const float* input) {
|
|||||||
|
|
||||||
return d_output;
|
return d_output;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Input::getOutputSize() {
|
|
||||||
return inputSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Input::getInputSize() {
|
|
||||||
return inputSize;
|
|
||||||
}
|
|
||||||
37
src/layers/input.cpp
Normal file
37
src/layers/input.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "input.hpp"
|
||||||
|
|
||||||
|
using namespace CUDANet::Layers;
|
||||||
|
|
||||||
|
Input::Input(int inputSize) : inputSize(inputSize) {
|
||||||
|
#ifdef USE_CUDA
|
||||||
|
initCUDA();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Input::~Input() {
|
||||||
|
#ifdef USE_CUDA
|
||||||
|
delCUDA();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
float* Input::forwardCPU(const float* input) {
|
||||||
|
throw std::logic_error("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
float* Input::forward(const float* input) {
|
||||||
|
#ifdef USE_CUDA
|
||||||
|
return forwardCUDA(input);
|
||||||
|
#else
|
||||||
|
return forwardCPU(input);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int Input::getOutputSize() {
|
||||||
|
return inputSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Input::getInputSize() {
|
||||||
|
return inputSize;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "input.cuh"
|
#include "input.hpp"
|
||||||
#include "layer.hpp"
|
#include "layer.hpp"
|
||||||
#include "batch_norm.cuh"
|
#include "batch_norm.cuh"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <cuda_runtime_api.h>
|
#include <cuda_runtime_api.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "input.cuh"
|
#include "input.hpp"
|
||||||
|
|
||||||
TEST(InputLayerTest, InputForward) {
|
TEST(InputLayerTest, InputForward) {
|
||||||
std::vector<float> input = {0.573f, 0.619f, 0.732f, 0.055f, 0.243f, 0.316f};
|
std::vector<float> input = {0.573f, 0.619f, 0.732f, 0.055f, 0.243f, 0.316f};
|
||||||
|
|||||||
Reference in New Issue
Block a user