mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Migrate output layer
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "input.hpp"
|
||||
#include "layer.hpp"
|
||||
#include "max_pooling.hpp"
|
||||
#include "output.cuh"
|
||||
#include "output.hpp"
|
||||
|
||||
// Models
|
||||
#include "model.hpp"
|
||||
|
||||
@@ -46,6 +46,12 @@ class Output : public SequentialLayer {
|
||||
private:
|
||||
int inputSize;
|
||||
float* h_output;
|
||||
|
||||
float* forwardCPU(const float* input);
|
||||
|
||||
#ifdef USE_CUDA
|
||||
float* forwardCUDA(const float* input);
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "input.hpp"
|
||||
#include "layer.hpp"
|
||||
#include "module.hpp"
|
||||
#include "output.cuh"
|
||||
#include "output.hpp"
|
||||
|
||||
namespace CUDANet {
|
||||
|
||||
|
||||
14
src/backends/cuda/layers/output.cu
Normal file
14
src/backends/cuda/layers/output.cu
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "output.hpp"
|
||||
|
||||
#include "cuda_helper.cuh"
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
float* Output::forwardCUDA(const float* input) {
|
||||
CUDA_CHECK(cudaMemcpy(
|
||||
h_output, input, sizeof(float) * inputSize, cudaMemcpyDeviceToHost
|
||||
));
|
||||
CUDA_CHECK(cudaDeviceSynchronize());
|
||||
|
||||
return h_output;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "output.cuh"
|
||||
|
||||
#include "cuda_helper.cuh"
|
||||
#include "output.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
@@ -13,13 +12,16 @@ Output::~Output() {
|
||||
free(h_output);
|
||||
}
|
||||
|
||||
float* Output::forward(const float* input) {
|
||||
CUDA_CHECK(cudaMemcpy(
|
||||
h_output, input, sizeof(float) * inputSize, cudaMemcpyDeviceToHost
|
||||
));
|
||||
CUDA_CHECK(cudaDeviceSynchronize());
|
||||
float* Output::forwardCPU(const float* input) {
|
||||
throw std::logic_error("Not implemented");
|
||||
}
|
||||
|
||||
return h_output;
|
||||
float* Output::forward(const float* input) {
|
||||
#ifdef USE_CUDA
|
||||
return forwardCUDA(input);
|
||||
#else
|
||||
return forwardCPU(input);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Output::getOutputSize() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "output.cuh"
|
||||
#include "output.hpp"
|
||||
|
||||
TEST(OutputLayerTest, OutputForward) {
|
||||
cudaError_t cudaStatus;
|
||||
|
||||
Reference in New Issue
Block a user