Skip to content

Commit b35c658

Browse files
authored
[CI] Add build with enabled stats (#191)
1 parent 652a2d7 commit b35c658

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ jobs:
1717
build-linux:
1818
strategy:
1919
matrix:
20-
build_type: [DEBUG, RELEASE]
20+
include:
21+
- build_type: DEBUG
22+
- build_type: RELEASE
23+
stats: false
24+
- build_type: RELEASE
25+
stats: true
2126
runs-on: ubuntu-latest
2227
steps:
2328
- uses: actions/checkout@v4
@@ -34,7 +39,10 @@ jobs:
3439
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
3540
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
3641
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
37-
-DOPENCV_PATH=3rdparty/opencv/build
42+
-DOPENCV_PATH=3rdparty/opencv/build \
43+
${{ matrix.stats && '-DENABLE_STATISTIC_TENSORS=ON' || '' }} \
44+
${{ matrix.stats && '-DENABLE_STATISTIC_TIME=ON' || '' }} \
45+
${{ matrix.stats && '-DENABLE_STATISTIC_WEIGHTS=ON' || '' }}
3846
cmake --build build --parallel
3947
env:
4048
CTEST_OUTPUT_ON_FAILURE: 1
@@ -48,7 +56,7 @@ jobs:
4856
- name: Upload artifacts
4957
uses: actions/upload-artifact@v4
5058
with:
51-
name: mnist-${{ matrix.build_type }}
59+
name: mnist-${{ matrix.build_type }}${{ matrix.stats && '-stats' || '' }}
5260
path: |
5361
build/bin/ACC_MNIST*
5462
build/bin/opencv_libs/*
@@ -83,7 +91,7 @@ jobs:
8391
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
8492
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
8593
-DCMAKE_C_COMPILER=clang \
86-
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
94+
-DCMAKE_CXX_COMPILER=clang++
8795
cmake --build build --parallel
8896
- name: Test
8997
run: cmake --build build -t test

include/layers/ConcatLayer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class ConcatLayer : public Layer {
1818

1919
static std::string get_name() { return "ConcatLayer"; }
2020

21+
#ifdef ENABLE_STATISTIC_WEIGHTS
22+
Tensor get_weights() override { return Tensor(); }
23+
#endif
24+
2125
private:
2226
int64_t axis_;
2327

include/layers/DropOutLayer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class DropOutLayer : public Layer {
1414
DropOutLayer(double drop_rate) { drop_rate_ = drop_rate; }
1515
static std::string get_name() { return "DropOut layer"; }
1616
void run(const Tensor& input, Tensor& output) override;
17+
#ifdef ENABLE_STATISTIC_WEIGHTS
18+
Tensor get_weights() override { return Tensor(); }
19+
#endif
1720
};
1821

1922
} // namespace it_lab_ai

include/layers/FlattenLayer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class FlattenLayer : public Layer {
1717
FlattenLayer(const std::vector<size_t>& order) : order_(order) {}
1818
static std::string get_name() { return "Flatten layer"; }
1919
void run(const Tensor& input, Tensor& output) override;
20+
#ifdef ENABLE_STATISTIC_WEIGHTS
21+
Tensor get_weights() override { return Tensor(); }
22+
#endif
2023
};
2124

2225
template <typename ValueType>

include/layers/ReduceLayer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ReduceLayer : public Layer {
1919

2020
static std::string get_name() { return "ReduceLayer"; }
2121

22+
#ifdef ENABLE_STATISTIC_WEIGHTS
23+
Tensor get_weights() override { return Tensor(); }
24+
#endif
25+
2226
private:
2327
Operation op_;
2428
int64_t keepdims_;

test/inference/test_inference.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdexcept>
12
#include <vector>
23

34
#include "graph/graph.hpp"
@@ -42,41 +43,46 @@ TEST(bfs, check_result_vec) {
4243
std::vector<int> res = {81, 81, 81};
4344
#ifdef ENABLE_STATISTIC_TENSORS
4445
std::vector<Tensor> tensors = graph.getTensors();
45-
for (int i = 0; i < tensors.size(); i++) {
46+
for (size_t i = 0; i < tensors.size(); i++) {
4647
std::vector<int> ten = *tensors[i].as<int>();
47-
for (int j = 0; j < ten.size(); j++) {
48+
for (size_t j = 0; j < ten.size(); j++) {
4849
std::cout << ten[j] << ' ';
4950
}
5051
std::cout << '\n';
5152
}
5253
#endif
5354
#ifdef ENABLE_STATISTIC_TIME
5455
std::vector<std::string> times = graph.getTimeInfo();
55-
for (int j = 0; j < times.size(); j++) {
56+
for (size_t j = 0; j < times.size(); j++) {
5657
std::cout << times[j] << ' ';
5758
}
5859
std::cout << '\n';
5960
#endif
6061
#ifdef ENABLE_STATISTIC_WEIGHTS
6162
std::vector<Tensor> weights = graph.getWEIGHTS();
62-
for (int i = 0; i < weights.size(); i++) {
63+
for (size_t i = 0; i < weights.size(); i++) {
6364
switch (weights[i].get_type()) {
6465
case Type::kInt: {
6566
std::vector<int> ten = *weights[i].as<int>();
66-
for (int j = 0; j < ten.size(); j++) {
67+
for (size_t j = 0; j < ten.size(); j++) {
6768
std::cout << ten[j] << ' ';
6869
}
6970
std::cout << '\n';
7071
break;
7172
}
7273
case Type::kFloat: {
7374
std::vector<float> ten = *weights[i].as<float>();
74-
for (int j = 0; j < ten.size(); j++) {
75+
for (size_t j = 0; j < ten.size(); j++) {
7576
std::cout << ten[j] << ' ';
7677
}
7778
std::cout << '\n';
7879
break;
7980
}
81+
case Type::kUnknown:
82+
default: {
83+
throw std::runtime_error("Unknown tensor type encountered");
84+
break;
85+
}
8086
}
8187
}
8288
#endif
@@ -112,24 +118,29 @@ TEST(bfs, check_end_to_end) {
112118
graph.inference();
113119
#ifdef ENABLE_STATISTIC_WEIGHTS
114120
std::vector<Tensor> weights = graph.getWEIGHTS();
115-
for (int i = 0; i < weights.size(); i++) {
121+
for (size_t i = 0; i < weights.size(); i++) {
116122
switch (weights[i].get_type()) {
117123
case Type::kInt: {
118124
std::vector<int> ten = *weights[i].as<int>();
119-
for (int j = 0; j < ten.size(); j++) {
125+
for (size_t j = 0; j < ten.size(); j++) {
120126
std::cout << ten[j] << ' ';
121127
}
122128
std::cout << '\n';
123129
break;
124130
}
125131
case Type::kFloat: {
126132
std::vector<float> ten = *weights[i].as<float>();
127-
for (int j = 0; j < ten.size(); j++) {
133+
for (size_t j = 0; j < ten.size(); j++) {
128134
std::cout << ten[j] << ' ';
129135
}
130136
std::cout << '\n';
131137
break;
132138
}
139+
case Type::kUnknown:
140+
default: {
141+
throw std::runtime_error("Unknown tensor type encountered");
142+
break;
143+
}
133144
}
134145
}
135146
#endif

0 commit comments

Comments
 (0)