Skip to content

Commit 2fc8a7d

Browse files
authored
Merge branch 'main' into Semyon1104/Owner_Graph
2 parents 2847514 + 415a85f commit 2fc8a7d

8 files changed

Lines changed: 57 additions & 41 deletions

File tree

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Checks: >
2727
-bugprone-easily-swappable-parameters,
2828
-bugprone-implicit-widening-of-multiplication-result,
2929
-bugprone-unchecked-optional-access,
30-
-clang-analyzer-security.insecureAPI.rand,
3130
3231
WarningsAsErrors: "*"
3332

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ jobs:
1212
- name: Install prerequisites
1313
run: |
1414
sudo apt install clang libomp-dev
15-
- name: Download and extract TensorFlow
16-
run: |
17-
wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
18-
tar -xzvf libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz
19-
- name: Set TensorFlow environment variables
20-
run: |
21-
echo "TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
22-
echo "TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
23-
echo "export TensorFlow_INCLUDE_DIRS=${PWD}/include" >> $GITHUB_ENV
24-
echo "export TensorFlow_LIBRARIES=${PWD}/lib/libtensorflow.so" >> $GITHUB_ENV
25-
- name: Display TensorFlow environment variables
26-
run: |
27-
echo "TensorFlow_INCLUDE_DIRS: ${{ env.TensorFlow_INCLUDE_DIRS }}"
28-
echo "TensorFlow_LIBRARIES: ${{ env.TensorFlow_LIBRARIES }}"
2915
- name: Setup ccache
3016
uses: hendrikmuhs/ccache-action@v1.2
3117
with:
@@ -37,9 +23,7 @@ jobs:
3723
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
3824
-DCMAKE_C_COMPILER=clang \
3925
-DCMAKE_CXX_COMPILER=clang++ \
40-
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
41-
-DTensorFlow_INCLUDE_DIRS=$TensorFlow_INCLUDE_DIRS \
42-
-DTensorFlow_LIBRARIES=$TensorFlow_LIBRARIES
26+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4327
cmake --build build --parallel
4428
- name: Run clang-tidy
4529
run: |

app/Converters/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
--extra-index-url https://download.pytorch.org/whl/cpu
2+
13
tensorflow>=2.19.0
24
onnx>=1.15.0
5+
torch==2.2.1+cpu
6+
torchvision==0.17.1+cpu
37
ultralytics>=8.0.0
48
numpy>=1.21.0
59
protobuf>=3.20.0

test/benchmarking/test_accuracy.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ TEST(accuracy, bad_accuracy_test_L) {
3333
size_t n = 5000;
3434
double a[5000];
3535
double b[5000];
36+
std::mt19937 rng(42);
37+
std::uniform_real_distribution<double> dist(-100.0, 100.0);
3638
for (size_t i = 0; i < n; i++) {
37-
a[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
39+
a[i] = dist(rng);
3840
}
3941
for (size_t i = 0; i < n; i++) {
40-
b[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
42+
b[i] = dist(rng);
4143
}
4244
double actual_acc = 0.0;
4345
for (size_t i = 0; i < n; i++) {
@@ -67,11 +69,13 @@ TEST(accuracy, bad_accuracy_norm_test_L) {
6769
size_t n = 5000;
6870
double a[5000];
6971
double b[5000];
72+
std::mt19937 rng2(42);
73+
std::uniform_real_distribution<double> dist2(-100.0, 100.0);
7074
for (size_t i = 0; i < n; i++) {
71-
a[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
75+
a[i] = dist2(rng2);
7276
}
7377
for (size_t i = 0; i < n; i++) {
74-
b[i] = (static_cast<double>(rand()) / RAND_MAX - 1.0) * 100; // [-100;100]
78+
b[i] = dist2(rng2);
7579
}
7680
double actual_acc = 0.0;
7781
for (size_t i = 0; i < n; i++) {

test/benchmarking/test_layers_time.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ TEST(pooling_test, is_pooling_tbb_ok) {
2323
size_t w = 224;
2424
Shape test_shape = {n, c, h, w};
2525
std::vector<int> a1(n * c * h * w);
26+
std::mt19937 rng(42);
27+
std::uniform_int_distribution<int> dist(0, std::numeric_limits<int>::max());
2628
for (size_t i = 0; i < n * c * h * w; i++) {
27-
a1[i] = rand();
29+
a1[i] = dist(rng);
2830
}
2931
Tensor input = make_tensor(a1, test_shape);
3032
Tensor output;
@@ -45,11 +47,13 @@ TEST(conv_test, is_conv_stl_ok) {
4547
Shape test_shape = {n, c, h, w};
4648
std::vector<int> a1(n * c * h * w);
4749
std::vector<int> a2(3 * 25 * 16);
50+
std::mt19937 rng2(42);
51+
std::uniform_int_distribution<int> dist2(0, std::numeric_limits<int>::max());
4852
for (size_t i = 0; i < n * c * h * w; i++) {
49-
a1[i] = rand();
53+
a1[i] = dist2(rng2);
5054
}
5155
for (size_t i = 0; i < 3 * 25 * 16; i++) {
52-
a2[i] = rand();
56+
a2[i] = dist2(rng2);
5357
}
5458
Tensor input = make_tensor(a1, test_shape);
5559
Tensor kernel = make_tensor(a2, Shape({5, 5, 3, 16}));

test/graph/test_graph.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,14 @@ TEST(graph_transformations, check_subgraphs_big_random) {
586586
layers.push_back(std::make_unique<EWLayer>("relu"));
587587
layer_ptrs.push_back(layers.back().get());
588588
}
589+
graph.setInput(layers[0], input);
590+
std::mt19937 rng(42);
591+
std::uniform_int_distribution<int> first_dist(0, num_vertices - 2);
592+
std::uniform_int_distribution<int> second_dist(1, num_vertices - 1);
589593

590-
graph.setInput(layer_ptrs[0], input);
591594
for (int i = 0; i < num_vertices; i++) {
592-
int rFirst = rand() % (num_vertices - 1);
593-
int rSecond = 1 + rand() % (num_vertices - 1);
595+
int rFirst = first_dist(rng);
596+
int rSecond = second_dist(rng);
594597
if ((rFirst == rSecond) ||
595598
((layer_ptrs[rFirst]->getID() == layer_ptrs[rSecond]->getID()) &&
596599
(layer_ptrs[rFirst]->getID() != 0))) {

test/single_layer/test_outputlayer.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <cstdlib>
21
#include <fstream>
32
#include <iostream>
3+
#include <random>
44
#include <string>
55

66
#include "gtest/gtest.h"
@@ -62,8 +62,10 @@ TEST(OutputLayer, can_get_topk_with_vector) {
6262
labels);
6363
std::vector<double> input;
6464
// get random nums
65+
std::mt19937 rng(42);
66+
std::uniform_real_distribution<double> dist01(0.0, 1.0);
6567
for (size_t i = 0; i < labels.size(); i++) {
66-
input.push_back(static_cast<double>(std::rand()) / RAND_MAX);
68+
input.push_back(dist01(rng));
6769
}
6870
ASSERT_NO_THROW(auto topk1 = top_k_vec(input, labels, k));
6971
}
@@ -75,9 +77,10 @@ TEST(OutputLayer, can_get_topk_with_layer_float) {
7577
labels);
7678
std::vector<float> input;
7779
// get random nums
80+
std::mt19937 rng2(42);
81+
std::uniform_real_distribution<float> dist01f(0.0F, 1.0F);
7882
for (size_t i = 0; i < labels.size(); i++) {
79-
input.push_back(
80-
static_cast<float>(static_cast<double>(std::rand()) / RAND_MAX));
83+
input.push_back(dist01f(rng2));
8184
}
8285
Tensor input_tensor = make_tensor(input);
8386
OutputLayer layer(labels);
@@ -91,8 +94,11 @@ TEST(OutputLayer, can_get_topk_with_layer_int) {
9194
labels);
9295
std::vector<int> input;
9396
// get random nums
97+
std::mt19937 rng3(42);
98+
std::uniform_int_distribution<int> dist_int(0,
99+
std::numeric_limits<int>::max());
94100
for (size_t i = 0; i < labels.size(); i++) {
95-
input.push_back(std::rand());
101+
input.push_back(dist_int(rng3));
96102
}
97103
Tensor input_tensor = make_tensor(input);
98104
OutputLayer layer(labels);
@@ -106,8 +112,11 @@ TEST(OutputLayer, topk_throws_when_not_1d_input) {
106112
labels);
107113
std::vector<int> input;
108114
// get random nums
115+
std::mt19937 rng4(42);
116+
std::uniform_int_distribution<int> dist_int2(0,
117+
std::numeric_limits<int>::max());
109118
for (size_t i = 0; i < labels.size(); i++) {
110-
input.push_back(std::rand());
119+
input.push_back(dist_int2(rng4));
111120
}
112121
Tensor input_tensor = make_tensor(input, {5, 200});
113122
OutputLayer layer(labels);
@@ -121,8 +130,11 @@ TEST(OutputLayer, topk_throws_when_incorrect_input_size) {
121130
labels);
122131
std::vector<int> input;
123132
// get random nums
133+
std::mt19937 rng5(42);
134+
std::uniform_int_distribution<int> dist_int3(0,
135+
std::numeric_limits<int>::max());
124136
for (size_t i = 0; i < 20; i++) {
125-
input.push_back(std::rand());
137+
input.push_back(dist_int3(rng5));
126138
}
127139
Tensor input_tensor = make_tensor(input);
128140
OutputLayer layer(labels);
@@ -136,8 +148,11 @@ TEST(OutputLayer, topk_throws_when_too_big_k) {
136148
labels);
137149
std::vector<int> input;
138150
// get random nums
151+
std::mt19937 rng6(42);
152+
std::uniform_int_distribution<int> dist_int4(0,
153+
std::numeric_limits<int>::max());
139154
for (size_t i = 0; i < labels.size(); i++) {
140-
input.push_back(std::rand());
155+
input.push_back(dist_int4(rng6));
141156
}
142157
Tensor input_tensor = make_tensor(input);
143158
OutputLayer layer(labels);

test/single_layer/test_poolinglayer.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include <vector>
1+
#include <random>
2+
#include <vector>
23

34
#include "gtest/gtest.h"
45
#include "layers/PoolingLayer.hpp"
@@ -365,9 +366,10 @@ TEST(poolinglayer, maxpool_onnx_example) {
365366
EXPECT_EQ(impl.get_output_shape(), expected_output_shape);
366367

367368
std::vector<float> input(input_shape.count());
369+
std::mt19937 rng(42);
370+
std::uniform_real_distribution<float> dist(0.0F, 10.0F);
368371
for (size_t i = 0; i < input.size(); i++) {
369-
input[i] =
370-
static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * 10.0f;
372+
input[i] = dist(rng);
371373
}
372374

373375
std::vector<float> output = impl.run(input);
@@ -403,9 +405,10 @@ TEST(poolinglayer, maxpool_onnx_with_pooling_layer) {
403405
PoolingLayer layer(poolshape, strides, pads, dilations, ceil_mode, "max");
404406

405407
std::vector<float> input(input_shape.count());
408+
std::mt19937 rng2(42);
409+
std::uniform_real_distribution<float> dist2(0.0F, 10.0F);
406410
for (size_t i = 0; i < input.size(); i++) {
407-
input[i] =
408-
static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * 10.0f;
411+
input[i] = dist2(rng2);
409412
}
410413

411414
Tensor input_tensor = make_tensor(input, input_shape);

0 commit comments

Comments
 (0)