mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-12-22 22:34:22 +00:00
Migrate concat layer
This commit is contained in:
@@ -84,6 +84,12 @@ class Backend {
|
||||
CUDANet::Tensor& running_var,
|
||||
CUDANet::Tensor& epsilon
|
||||
) = 0;
|
||||
|
||||
virtual CUDANet::Tensor& concat(
|
||||
CUDANet::Tensor& input_a,
|
||||
CUDANet::Tensor& input_b,
|
||||
CUDANet::Tensor& output
|
||||
) = 0;
|
||||
};
|
||||
|
||||
} // namespace CUDANet
|
||||
@@ -80,6 +80,12 @@ class CUDA : public Backend {
|
||||
CUDANet::Tensor& running_var,
|
||||
CUDANet::Tensor& epsilon
|
||||
) override;
|
||||
|
||||
CUDANet::Tensor& concat(
|
||||
CUDANet::Tensor& input_a,
|
||||
CUDANet::Tensor& input_b,
|
||||
CUDANet::Tensor& output
|
||||
) override;
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Backend
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef CUDANET_CONCAT_LAYER_H
|
||||
#define CUDANET_CONCAT_LAYER_H
|
||||
#pragma once
|
||||
|
||||
#include "layer.hpp"
|
||||
|
||||
@@ -11,47 +10,24 @@ namespace CUDANet::Layers {
|
||||
*/
|
||||
class Concat {
|
||||
public:
|
||||
/**
|
||||
* @brief Create a new Concat layer
|
||||
*
|
||||
* @param inputASize Size of the first input
|
||||
* @param inputBSize Size of the second input
|
||||
*/
|
||||
Concat(const int inputASize, const int inputBSize);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Concat layer
|
||||
*
|
||||
*/
|
||||
Concat(const CUDANet::Shape a_shape, const CUDANet::Shape b_shape, CUDANet::Backend *backend);
|
||||
|
||||
~Concat();
|
||||
|
||||
/**
|
||||
* @brief Concatenates the two inputs
|
||||
*
|
||||
* @param d_input_A Device pointer to the first input
|
||||
* @param d_input_B Device pointer to the second input
|
||||
*
|
||||
* @return Device pointer to the output
|
||||
*/
|
||||
float* forward(const float* d_input_A, const float* d_input_B);
|
||||
CUDANet::Tensor& forward(CUDANet::Tensor& input_a, CUDANet::Tensor& input_b);
|
||||
|
||||
int getOutputSize();
|
||||
CUDANet::Shape output_shape();
|
||||
|
||||
private:
|
||||
int inputASize;
|
||||
int inputBSize;
|
||||
CUDANet::Shape a_shape;
|
||||
CUDANet::Shape b_shape;
|
||||
|
||||
float* forwardCPU(const float* input_A, const float* input_B);
|
||||
CUDANet::Shape out_shape;
|
||||
CUDANet::Tensor output;
|
||||
|
||||
#ifdef USE_CUDA
|
||||
float* d_output;
|
||||
float* forwardCUDA(const float* d_input_A, const float* d_input_B);
|
||||
|
||||
void initCUDA();
|
||||
void delCUDA();
|
||||
#endif
|
||||
CUDANet::Backend *backend;
|
||||
};
|
||||
|
||||
} // namespace CUDANet::Layers
|
||||
|
||||
#endif // CUDANET_CONCAT_LAYER_H
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "activation.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
namespace CUDANet::Layers {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "backend.hpp"
|
||||
#include "layer.hpp"
|
||||
|
||||
|
||||
@@ -21,6 +21,30 @@ class InvalidShapeException : public std::runtime_error {
|
||||
actual
|
||||
)
|
||||
) {}
|
||||
|
||||
InvalidShapeException(
|
||||
const std::string& message,
|
||||
const Shape& shape_a,
|
||||
const Shape& shape_b
|
||||
)
|
||||
: std::runtime_error(
|
||||
std::format(
|
||||
"{}. Shape A: [{}], Shape B: [{}]",
|
||||
message,
|
||||
format_shape(shape_a),
|
||||
format_shape(shape_b)
|
||||
)
|
||||
) {}
|
||||
|
||||
private:
|
||||
static std::string format_shape(const Shape& shape) {
|
||||
std::string result;
|
||||
for (size_t i = 0; i < shape.size(); ++i) {
|
||||
if (i > 0) result += ", ";
|
||||
result += std::to_string(shape[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace CUDANet
|
||||
|
||||
Reference in New Issue
Block a user