Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ class Graph {
weights_.push_back(layers_[i]->get_weights());
#endif
inten_ = *outten_;
if (layers_[i]->ewops.countlayers > 0) {
for (unsigned int j = 0; j < layers_[i]->ewops.countlayers; j++) {
layers_[i]->ewops.layers[j]->run(inten_, *outten_);
}
inten_ = *outten_;
}
#ifdef ENABLE_STATISTIC_TIME
auto end = std::chrono::high_resolution_clock::now();
auto elapsed =
Expand Down
8 changes: 8 additions & 0 deletions include/layers/Layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ enum LayerType : uint8_t {

enum ImplType : uint8_t { kDefault, kTBB, kSTL };

class Layer;

struct EWoperations {

@aobolensk aobolensk Aug 7, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, PostOps would be better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

std::vector<Layer*> layers;
unsigned int countlayers = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned int countlayers = 0;
unsigned int count = 0;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

};

class Layer {
public:
Layer() = default;
virtual ~Layer() = default;
EWoperations ewops;
int getID() const { return id_; }
void setID(int id) { id_ = id; }
LayerType getName() const { return type_; }
Expand Down
66 changes: 66 additions & 0 deletions test/inference/test_inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,69 @@ TEST(bfs, check_end_to_end) {
std::vector<float> res(3, 21);
ASSERT_EQ(tmp, res);
}
TEST(bfs, check_struct_layer) {
Graph graph(5);
Shape sh1({1, 5, 5, 3});
std::vector<int> vec;
vec.reserve(75);
for (int i = 0; i < 75; ++i) {
vec.push_back(3);
}
Tensor input = make_tensor(vec, sh1);
Tensor output = make_tensor(vec, sh1);
InputLayer a1(kNhwc, kNchw, 1, 2);
a1.setName(kInput);
std::vector<int> kernelvec = {1, 1, 1, 1, 1, 1, 1, 1, 1};
Shape sh2({3, 3});
Tensor kernel = make_tensor(kernelvec, sh2);
ConvolutionalLayer a2(1, 0, 1, kernel);
ConvolutionalLayer a3(1, 0, 1, kernel);

// EWLayer a4("linear", 2.0F, 3.0F);
// a2.ewops.layers.push_back(&a4);
// a2.ewops.countlayers++;

a2.setName(kConvolution);
a3.setName(kConvolution);
graph.setInput(a1, input);
graph.makeConnection(a1, a2);
graph.makeConnection(a2, a3);
graph.setOutput(a3, output);
graph.inference();
std::vector<int> tmp = *output.as<int>();
std::vector<int> res = {81, 81, 81};
ASSERT_EQ(tmp, res);
}
TEST(bfs, check_struct_layer_added) {
Graph graph(5);
Shape sh1({1, 5, 5, 3});
std::vector<int> vec;
vec.reserve(75);
for (int i = 0; i < 75; ++i) {
vec.push_back(3);
}
Tensor input = make_tensor(vec, sh1);
Tensor output = make_tensor(vec, sh1);
InputLayer a1(kNhwc, kNchw, 1, 2);
a1.setName(kInput);
std::vector<int> kernelvec = {1, 1, 1, 1, 1, 1, 1, 1, 1};
Shape sh2({3, 3});
Tensor kernel = make_tensor(kernelvec, sh2);
ConvolutionalLayer a2(1, 0, 1, kernel);
ConvolutionalLayer a3(1, 0, 1, kernel);

EWLayer a4("linear", 2.0F, 3.0F);
a2.ewops.layers.push_back(&a4);
a2.ewops.countlayers++;

a2.setName(kConvolution);
a3.setName(kConvolution);
graph.setInput(a1, input);
graph.makeConnection(a1, a2);
graph.makeConnection(a2, a3);
graph.setOutput(a3, output);
graph.inference();
std::vector<int> tmp = *output.as<int>();
std::vector<int> res = {189, 189, 189};
ASSERT_EQ(tmp, res);
}
Loading