Migrate add layer to tensors

This commit is contained in:
2025-11-22 00:12:20 +01:00
parent aeb1739c46
commit 4c8b2ef537
7 changed files with 56 additions and 101 deletions

View File

@@ -1,49 +1,24 @@
#ifndef CUDANET_ADD_LAYER_H
#define CUDANET_ADD_LAYER_H
#pragma once
#include "shape.hpp"
#include "tensor.hpp"
namespace CUDANet::Layers {
class Add {
public:
/**
* @brief Create a new Add layer
*
* @param inputSize Size of the input arrays
*/
Add(int inputSize);
Add(CUDANet::Shape a_shape, CUDANet::Shape b_shape, CUDANet::Backend* backend);
/**
* @brief Destroy the Add layer
*
*/
~Add();
/**
* @brief Adds first input to second input
*
* @param d_inputA Device pointer to the first input
* @param d_inputB Device pointer to the second input
*
*/
float* forward(const float* inputA, const float* inputB);
CUDANet::Tensor&
forward(CUDANet::Tensor& input_a, CUDANet::Tensor& input_b);
private:
int inputSize;
CUDANet::Shape out_shape;
CUDANet::Tensor output;
float* output;
float* forwardCPU(const float* inputA, const float* inputB);
#ifdef USE_CUDA
float* d_output;
int gridSize;
float* forwardCUDA(const float* d_inputA, const float* d_inputB);
void initCUDA();
void delCUDA();
#endif
CUDANet::Backend *backend;
};
} // namespace CUDANet::Layers
#endif // CUDANET_ADD_LAYER_H