-
Notifications
You must be signed in to change notification settings - Fork 5
Layers #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Layers #54
Changes from all commits
ac67f77
5f36230
4867937
fb57554
f2afeea
82f0dc4
2f1141a
fdfe528
116cf4a
55a9ee8
b3e62d4
f65be87
7e9a389
f2547da
a89b0ba
9dcf39d
fbf472e
ad52dd0
2fc6832
0efcb04
4d68495
2c2d708
7d84878
d07c3d8
96b403c
7be04f0
aaa5d80
0ca0331
ff1a8f8
abd51c9
e901675
f379e51
b185542
5ae7ad8
e1350f0
3155cd8
9de22dc
d64ad06
7bba704
9ee9fe3
5009b33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,30 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| set(CMAKE_CXX_STANDARD 11) | ||
|
|
||
| project(cpp_template) | ||
|
|
||
| include(cmake/configure.cmake) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why |
||
| set(ProjectName "itlab") | ||
| project(${ProjectName}) | ||
|
|
||
| include_directories(include) | ||
|
|
||
| enable_testing() | ||
|
|
||
| add_subdirectory(3rdparty) | ||
| add_subdirectory(app) | ||
| add_subdirectory(include) | ||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| googletest | ||
| GIT_REPOSITORY https://github.com/google/googletest.git | ||
| GIT_TAG v1.14.0 | ||
| ) | ||
| FetchContent_MakeAvailable(googletest) | ||
|
|
||
|
|
||
| #add_subdirectory(3rdparty/googletest) | ||
|
Comment on lines
+11
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have googletest integrated, why do we need this? Please, revert |
||
| add_subdirectory(src) | ||
| add_subdirectory(test) | ||
|
|
||
| # REPORT | ||
| message( STATUS "") | ||
| message( STATUS "General configuration for ${PROJECT_NAME}") | ||
| message( STATUS "======================================") | ||
| message( STATUS "") | ||
| message( STATUS " Configuration: ${CMAKE_BUILD_TYPE}") | ||
| message( STATUS "") | ||
|
Comment on lines
+23
to
+30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #ifndef GRAPH_H | ||
| #define GRAPH_H | ||
|
|
||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "./layer/layer.h" | ||
| #include "./tensor/tensor.h" | ||
|
|
||
| class Network { | ||
| private: | ||
| std::unordered_map<int, Layer*> layers_; | ||
| Tensor<double> inputTensor_; | ||
| Tensor<double>* outputTensor_; | ||
| int start_ = -1; | ||
| int end_ = -1; | ||
| bool bfs_helper(int start, int vert, bool flag, | ||
| std::vector<int>* v_ord) const; | ||
|
|
||
| public: | ||
| Network(); | ||
|
|
||
| bool addLayer(Layer& lay, const std::vector<int>& inputs = {}, | ||
| const std::vector<int>& outputs = {}); | ||
| void addEdge(Layer& layPrev, Layer& layNext); | ||
| void removeEdge(Layer& layPrev, Layer& layNext); | ||
| void removeLayer(Layer& lay); | ||
| int getLayers() const; | ||
| int getEdges() const; | ||
| bool isEmpty() const; | ||
| bool hasPath(Layer& layPrev, Layer& layNext) const; | ||
| std::vector<int> inference(int start) const; | ||
| void setInput(Layer& lay, Tensor<double>& vec); | ||
| void setOutput(Layer& lay, Tensor<double>& vec); | ||
| void run(); | ||
| std::vector<std::string> getLayersTypeVector() const; | ||
| ~Network(); | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef CONCATENATE_LAYER_H | ||
| #define CONCATENATE_LAYER_H | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| class ConcatenateLayerMock : public Layer { | ||
| private: | ||
| std::vector<Shape> input_shapes_config_; | ||
| Shape output_shape_computed_; | ||
| unsigned int concatenation_axis_; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| explicit ConcatenateLayerMock(int id); | ||
|
|
||
| void configure(const std::vector<Shape>& inputs_shapes, unsigned int axis, | ||
| Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #ifndef CONV_LAYER_H | ||
| #define CONV_LAYER_H | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| struct ConvPadStrideInfo { | ||
| unsigned int stride_x{1}; | ||
| unsigned int stride_y{1}; | ||
| unsigned int pad_x{0}; | ||
| unsigned int pad_y{0}; | ||
|
|
||
| ConvPadStrideInfo(unsigned int sx = 1, unsigned int sy = 1, | ||
| unsigned int px = 0, unsigned int py = 0) | ||
| : stride_x(sx), stride_y(sy), pad_x(px), pad_y(py) {} | ||
| }; | ||
|
|
||
| class ConvolutionLayerMock : public Layer { | ||
| private: | ||
| ConvPadStrideInfo conv_info_; | ||
| Shape input_shape_config_; | ||
| Shape weights_shape_config_; | ||
| Shape biases_shape_config_; | ||
| Shape output_shape_computed_; | ||
| bool has_biases_ = false; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| explicit ConvolutionLayerMock(int id); | ||
|
|
||
| void configure(const Shape& input_s, const Shape& weights_s, | ||
| const Shape* biases_s, Shape& output_s_ref, | ||
| const ConvPadStrideInfo& info); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #ifndef ELEMENTWISE_LAYER_H | ||
| #define ELEMENTWISE_LAYER_H | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| enum class ElementwiseOp : std::uint8_t { | ||
| kAdd, | ||
| kSub, | ||
| kMul, | ||
| kDiv, | ||
| kMax, | ||
| kMin, | ||
| kSquaredDiff | ||
| }; | ||
|
|
||
| class ElementwiseLayerMock : public Layer { | ||
| private: | ||
| ElementwiseOp op_type_; | ||
| Shape common_shape_; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| ElementwiseLayerMock(int id, ElementwiseOp op); | ||
|
|
||
| void configure(const Shape& input1_shape, const Shape& input2_shape, | ||
| Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #ifndef MATMUL_LAYER_H | ||
| #define MATMUL_LAYER_H | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| struct MatMulInfo { | ||
| bool transpose_x{false}; | ||
| bool transpose_y{false}; | ||
| }; | ||
|
|
||
| class MatMulLayerMock : public Layer { | ||
| private: | ||
| MatMulInfo matmul_info_; | ||
| Shape input_x_shape_; | ||
| Shape input_y_shape_; | ||
| Shape output_shape_; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| MatMulLayerMock(int id, const MatMulInfo& info); | ||
|
|
||
| void configure(const Shape& input_x_shape, const Shape& input_y_shape, | ||
| Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input_x, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #ifndef POOLING_LAYER_H | ||
| #define POOLING_LAYER_H | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| enum class PoolingType : std::uint8_t { kMax, kAvg, kL2 }; | ||
|
|
||
| struct PoolingLayerInfo { | ||
| PoolingType pool_type{PoolingType::kMax}; | ||
| int pool_size_x{2}; | ||
| int pool_size_y{2}; | ||
| int stride_x{1}; | ||
| int stride_y{1}; | ||
| int pad_x{0}; | ||
| int pad_y{0}; | ||
| bool exclude_padding{true}; | ||
| }; | ||
|
|
||
| class PoolingLayerMock : public Layer { | ||
| private: | ||
| PoolingLayerInfo pool_info_; | ||
| Shape input_shape_; | ||
| Shape output_shape_; | ||
| size_t h_in_idx_ = 0; | ||
| size_t w_in_idx_ = 0; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| PoolingLayerMock(int id, const PoolingLayerInfo& info); | ||
|
|
||
| void configure(const Shape& input_shape, Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #ifndef RESHAPE_LAYER_H | ||
| #define RESHAPE_LAYER_H | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| class ReshapeLayerMock : public Layer { | ||
| private: | ||
| Shape input_shape_config_; | ||
| Shape target_output_shape_config_; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| explicit ReshapeLayerMock(int id); | ||
|
|
||
| void configure(const Shape& input_shape, const Shape& target_output_shape, | ||
| Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #ifndef SLICE_LAYER_H | ||
| #define SLICE_LAYER_H | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "layer/layer.h" | ||
| #include "tensor/tensor.h" | ||
|
|
||
| class SliceLayerMock : public Layer { | ||
| private: | ||
| Shape input_shape_config_; | ||
| Shape output_shape_computed_; | ||
| std::vector<int> slice_starts_; | ||
| std::vector<int> slice_sizes_; | ||
| bool configured_ = false; | ||
|
|
||
| public: | ||
| explicit SliceLayerMock(int id); | ||
|
|
||
| void configure(const Shape& input_shape, const std::vector<int>& starts, | ||
| const std::vector<int>& sizes, Shape& output_shape_ref); | ||
|
|
||
| void exec(const Tensor<double>& input, Tensor<double>& output) override; | ||
|
|
||
| Shape get_output_shape() override; | ||
|
|
||
| std::string get_type_name() const override; | ||
| }; | ||
|
|
||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++11 is too low. If you need to specify the standard then it should be at least 17.