Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
Language: Cpp
Standard: c++20
BasedOnStyle: Google
UseTab: Never
AllowShortFunctionsOnASingleLine: Empty
IndentPPDirectives: AfterHash
SortIncludes: true
FixNamespaceComments: true
InsertBraces: true
QualifierAlignment: Left
PointerAlignment: Right
ReferenceAlignment: Right
SortUsingDeclarations: LexicographicNumeric
InsertNewlineAtEOF: true
LambdaBodyIndentation: OuterScope
MaxEmptyLinesToKeep: 1
LineEnding: LF
2 changes: 1 addition & 1 deletion app/Converters/reader_weights_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ int main() {
}

return 0;
}
}
2 changes: 1 addition & 1 deletion app/Converters/reader_weights_sample_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ int main() {
}

return 0;
}
}
18 changes: 13 additions & 5 deletions app/Graph/acc_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ int main(int argc, char* argv[]) {
for (int i = 0; i < 28; ++i) {
for (int j = 0; j < 28; ++j) {
size_t a = ind;
for (size_t n = 0; n < name; n++) a += counts[n] + 1;
for (size_t n = 0; n < name; n++) {
a += counts[n] + 1;
}
res[(a) * 28 * 28 + i * 28 + j] = channels[0].at<uchar>(j, i);
}
}
Expand All @@ -124,8 +126,12 @@ int main(int argc, char* argv[]) {
for (size_t name = 0; name < 10; name++) {
for (size_t ind = 0; ind < counts[name] + 1; ind++) {
size_t a = ind;
for (size_t n = 0; n < name; n++) a += counts[n] + 1;
if (name == indices[a]) stat++;
for (size_t n = 0; n < name; n++) {
a += counts[n] + 1;
}
if (name == indices[a]) {
stat++;
}
}
}
double percentage =
Expand Down Expand Up @@ -177,7 +183,9 @@ int main(int argc, char* argv[]) {
folder_oss << std::setw(5) << std::setfill('0') << class_id;
std::string class_folder_path = dataset_path + "/" + folder_oss.str();

if (!fs::exists(class_folder_path)) continue;
if (!fs::exists(class_folder_path)) {
continue;
}

for (const auto& entry : fs::directory_iterator(class_folder_path)) {
if (entry.path().extension() == ".png" ||
Expand Down Expand Up @@ -280,4 +288,4 @@ int main(int argc, char* argv[]) {
<< final_accuracy_top5 << "%" << '\n';

return 0;
}
}
57 changes: 39 additions & 18 deletions app/Graph/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
std::string json_file = MODEL_PATH_H5;
it_lab_ai::json model_data = it_lab_ai::read_json(json_file);

if (comments) std::cout << "Loaded model data from JSON." << '\n';
if (comments) {
std::cout << "Loaded model data from JSON." << '\n';
}

for (const auto& layer_data : model_data) {
std::string layer_type = layer_data["type"];
Expand Down Expand Up @@ -70,7 +72,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
options, 1, pads, 1, tmp_values, tmp_bias, 1, true);
layers.push_back(conv_layer);
layerpostop.push_back(false);
if (comments) std::cout << "ConvLayer added to layers." << '\n';
if (comments) {
std::cout << "ConvLayer added to layers." << '\n';
}
}
if (layer_type.find("relu") != std::string::npos) {
auto ew_layer = LayerFactory::createEwLayer("relu", options);
Expand All @@ -85,7 +89,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
auto fc_layer = std::make_shared<it_lab_ai::FCLayer>(tensor, tmp_bias);
layers.push_back(fc_layer);
layerpostop.push_back(false);
if (comments) std::cout << "DenseLayer added to layers." << '\n';
if (comments) {
std::cout << "DenseLayer added to layers." << '\n';
}
}

if (layer_type.find("Pool") != std::string::npos) {
Expand All @@ -105,15 +111,19 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,

layers.push_back(pool_layer);
layerpostop.push_back(false);
if (comments) std::cout << "PoolingLayer added to layers." << '\n';
if (comments) {
std::cout << "PoolingLayer added to layers." << '\n';
}
}

if (layer_type.find("Flatten") != std::string::npos) {
auto flatten_layer = std::make_shared<it_lab_ai::FlattenLayer>(
std::vector<size_t>({0, 3, 2, 1}));
layers.push_back(flatten_layer);
layerpostop.push_back(false);
if (comments) std::cout << "FlattenLayer added to layers." << '\n';
if (comments) {
std::cout << "FlattenLayer added to layers." << '\n';
}
}

if (layer_type.find("Dropout") != std::string::npos) {
Expand All @@ -128,14 +138,20 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
}
}
}
if (comments) std::cout << "number of layers - " << layers.size() + 1 << '\n';
if (comments) {
std::cout << "number of layers - " << layers.size() + 1 << '\n';
}
auto a1 = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
it_lab_ai::kNchw);

if (comments) std::cout << "InputLayer created." << '\n';
if (comments) {
std::cout << "InputLayer created." << '\n';
}

graph.setInput(a1, input);
if (comments) std::cout << "Input set in graph." << '\n';
if (comments) {
std::cout << "Input set in graph." << '\n';
}

graph.makeConnection(a1, layers[0]);
if (comments) {
Expand Down Expand Up @@ -199,13 +215,12 @@ void build_graph(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
try {
std::sort(connection_list.begin(), connection_list.end(),
[&](const auto& a, const auto& b) {
if (!name_to_layer.contains(a.first) ||
!name_to_layer.contains(b.first)) {
return false;
}
return name_to_layer[a.first]->getID() <
name_to_layer[b.first]->getID();
});
if (!name_to_layer.contains(a.first) ||
!name_to_layer.contains(b.first)) {
return false;
}
return name_to_layer[a.first]->getID() < name_to_layer[b.first]->getID();
});

} catch (const std::exception& e) {
std::cerr << "ERROR during sorting: " << e.what() << '\n';
Expand Down Expand Up @@ -298,7 +313,9 @@ ParseResult parse_json_model(RuntimeOptions options,
}
}

if (comments) std::cout << "Loaded model data from JSON." << '\n';
if (comments) {
std::cout << "Loaded model data from JSON." << '\n';
}

auto input_layer = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw,
it_lab_ai::kNchw);
Expand All @@ -311,7 +328,9 @@ ParseResult parse_json_model(RuntimeOptions options,
try {
std::string layer_type = layer_data["type"];

if (layer_type == "InputLayer") continue;
if (layer_type == "InputLayer") {
continue;
}
std::string layer_name = layer_data["name"];
int layer_index = layer_data["index"];
if (comments) {
Expand Down Expand Up @@ -705,7 +724,9 @@ ParseResult parse_json_model(RuntimeOptions options,
std::cout << "TransposeLayer added with perm: [";
for (size_t i = 0; i < perm.size(); ++i) {
std::cout << perm[i];
if (i < perm.size() - 1) std::cout << ", ";
if (i < perm.size() - 1) {
std::cout << ", ";
}
}
std::cout << "]" << '\n';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Graph/graph_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ int main(int argc, char* argv[]) {
}
}
return 0;
}
}
44 changes: 33 additions & 11 deletions include/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class Graph {
#endif

public:
Graph() { arrayV_.push_back(0); }
Graph() {
arrayV_.push_back(0);
}

Graph(int vertices, std::vector<std::vector<std::pair<int, int>>> split)
: BiggestSize_(vertices), split_distribution_(std::move(split)) {
Expand Down Expand Up @@ -150,7 +152,9 @@ class Graph {
arrayE_.begin() + arrayV_[layerID + 1]);
}

[[nodiscard]] int getLayersCount() const { return V_; }
[[nodiscard]] int getLayersCount() const {
return V_;
}

[[nodiscard]] std::shared_ptr<Layer> getLayerFromID(size_t layerID) const {
if (layerID >= layers_.size()) {
Expand Down Expand Up @@ -188,7 +192,9 @@ class Graph {
}

void addSingleLayer(const std::shared_ptr<Layer>& layer) {
if (!layer) return;
if (!layer) {
return;
}

int id = layer->getID();
bool layer_exists = (id >= 0 && id < V_ && layers_[id] == layer);
Expand Down Expand Up @@ -314,7 +320,9 @@ class Graph {

bool areLayerNext(const std::shared_ptr<Layer>& layPrev,
const std::shared_ptr<Layer>& layNext) {
if (!layPrev || !layNext) return false;
if (!layPrev || !layNext) {
return false;
}

if (layPrev->getID() >= V_ || layPrev->getID() < 0) {
throw std::invalid_argument("No such layer in graph");
Expand Down Expand Up @@ -433,8 +441,12 @@ class Graph {
stats.min_time = elapsed_ms;
stats.max_time = elapsed_ms;
} else {
if (elapsed_ms < stats.min_time) stats.min_time = elapsed_ms;
if (elapsed_ms > stats.max_time) stats.max_time = elapsed_ms;
if (elapsed_ms < stats.min_time) {
stats.min_time = elapsed_ms;
}
if (elapsed_ms > stats.max_time) {
stats.max_time = elapsed_ms;
}
}
#endif
}
Expand All @@ -449,7 +461,9 @@ class Graph {
}

#ifdef ENABLE_STATISTIC_TENSORS
std::vector<Tensor> getTensors() { return tensors_; }
std::vector<Tensor> getTensors() {
return tensors_;
}
#endif
#ifdef ENABLE_STATISTIC_TIME
std::vector<std::string> getTimeInfo() {
Expand All @@ -461,10 +475,14 @@ class Graph {
}
return res;
}
std::vector<int> getTime() { return time_; }
std::vector<int> getTime() {
return time_;
}
#endif
#ifdef ENABLE_STATISTIC_WEIGHTS
std::vector<Tensor> getWEIGHTS() { return weights_; }
std::vector<Tensor> getWEIGHTS() {
return weights_;
}
#endif

[[nodiscard]] std::vector<std::pair<int, int>> getInOutDegrees() const {
Expand Down Expand Up @@ -495,7 +513,9 @@ class Graph {
}

private:
void markExecutionPlanDirty() { execution_plan_dirty_ = true; }
void markExecutionPlanDirty() {
execution_plan_dirty_ = true;
}

void ensureExecutionPlan() const {
if (execution_plan_dirty_) {
Expand Down Expand Up @@ -559,7 +579,9 @@ class Graph {
std::vector<int> traversal_in_degree = in_degree;

std::function<void(int)> dfs = [&](int vertex) {
if (visited[static_cast<size_t>(vertex)]) return;
if (visited[static_cast<size_t>(vertex)]) {
return;
}

visited[static_cast<size_t>(vertex)] = true;
traversal_order_.push_back(vertex);
Expand Down
18 changes: 13 additions & 5 deletions include/layers/BatchNormalizationLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ class BatchNormalizationLayer : public Layer {
std::vector<Tensor>& output) override;

#ifdef ENABLE_STATISTIC_WEIGHTS
Tensor get_weights() override { return Tensor(); }
Tensor get_weights() override {
return Tensor();
}
#endif

void set_epsilon(float epsilon) { epsilon_ = epsilon; }
void set_momentum(float momentum) { momentum_ = momentum; }
void set_training_mode(bool training_mode) { training_mode_ = training_mode; }
void set_epsilon(float epsilon) {
epsilon_ = epsilon;
}
void set_momentum(float momentum) {
momentum_ = momentum;
}
void set_training_mode(bool training_mode) {
training_mode_ = training_mode;
}

private:
Tensor scale_;
Expand All @@ -47,4 +55,4 @@ class BatchNormalizationLayer : public Layer {
void validate_parameters(size_t num_channels) const;
};

} // namespace it_lab_ai
} // namespace it_lab_ai
2 changes: 1 addition & 1 deletion include/layers/BinaryOpLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ class BinaryOpLayer : public Layer {
class BinaryOpLayerImpl;
};

} // namespace it_lab_ai
} // namespace it_lab_ai
10 changes: 7 additions & 3 deletions include/layers/ConcatLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class ConcatLayer : public Layer {

void run(const std::vector<Tensor>& input,
std::vector<Tensor>& output) override;
void setInputOrder(const std::vector<int>& order) { input_order_ = order; }
void setInputOrder(const std::vector<int>& order) {
input_order_ = order;
}

#ifdef ENABLE_STATISTIC_WEIGHTS
Tensor get_weights() override { return Tensor(); }
Tensor get_weights() override {
return Tensor();
}
#endif

private:
Expand Down Expand Up @@ -81,4 +85,4 @@ class ConcatLayer : public Layer {
}
};

} // namespace it_lab_ai
} // namespace it_lab_ai
Loading
Loading