mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 01:34:22 +00:00
Migrate input layer
This commit is contained in:
@@ -1,31 +1,22 @@
|
||||
#include "cuda_helper.cuh"
|
||||
#include "input.cuh"
|
||||
#include "input.hpp"
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
Input::Input(int inputSize) : inputSize(inputSize) {
|
||||
void Input::initCUDA() {
|
||||
d_output = nullptr;
|
||||
CUDA_CHECK(cudaMalloc((void**)&d_output, sizeof(float) * inputSize));
|
||||
}
|
||||
|
||||
Input::~Input() {
|
||||
void Input::delCUDA() {
|
||||
cudaFree(d_output);
|
||||
}
|
||||
|
||||
float* Input::forward(const float* input) {
|
||||
float* Input::forwardCUDA(const float* input) {
|
||||
CUDA_CHECK(cudaMemcpy(
|
||||
d_output, input, sizeof(float) * inputSize, cudaMemcpyHostToDevice
|
||||
));
|
||||
CUDA_CHECK(cudaDeviceSynchronize());
|
||||
|
||||
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 <vector>
|
||||
|
||||
#include "input.cuh"
|
||||
#include "input.hpp"
|
||||
#include "layer.hpp"
|
||||
#include "batch_norm.cuh"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user