mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-12-22 22:34:22 +00:00
Restructure cuda backend
This commit is contained in:
44
src/layers/add.cpp
Normal file
44
src/layers/add.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "add.hpp"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
using namespace CUDANet::Layers;
|
||||
|
||||
|
||||
Add::Add(int inputSize)
|
||||
: inputSize(inputSize) {
|
||||
|
||||
output = new float[inputSize];
|
||||
|
||||
#ifdef USE_CUDA
|
||||
initCUDA();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
Add::~Add() {
|
||||
#ifdef USE_CUDA
|
||||
delCUDA();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
float* Add::forward(const float* inputA, const float* inputB) {
|
||||
|
||||
#ifdef USE_CUDA
|
||||
return forwardCUDA(inputA, inputB);
|
||||
#else
|
||||
return forwardCPU(inputA, inputB);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
float* Add::forwardCPU(const float* inputA, const float* inputB) {
|
||||
for (size_t i = 0; i < inputSize; i++)
|
||||
{
|
||||
output[i] = inputA[i] + inputB[i];
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user