Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt update && \
just gcc-14 g++-14 wget ccache sudo

RUN apt-get update && \
apt-get install -y iwyu cppcheck
apt-get install -y iwyu cppcheck gdb

RUN chown -R devcontainer:devcontainer /home/devcontainer

Expand Down
36 changes: 36 additions & 0 deletions .github/actions/build_cpplibs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: build_cpplibs
description: Builds CPP libraries.

inputs:
build_type:
description: Build type of the CPP libs (Release/Debug)
required: false
default: Release

build_tests:
description: Whether to build unit tests for CPP libs (ON/OFF)
required: false
default: OFF

enable_sanitizer_type:
description: Type of sanitizer to enable (address/undefined)
required: false
default: NONE

runs:
using: composite

steps:
- name: Install build tools
run: just install_build_tools
shell: bash

- name: Build CPP libraries
run: |
just build_project \
-DTRY_UPDATE_SUBMODULES=OFF \
-DCMAKE_BUILD_TYPE=${{ inputs.build_type }} \
-DBUILD_TESTS=${{ inputs.build_tests }} \
-DENABLE_SANITIZER_TYPE=${{ inputs.enable_sanitizer_type }}
shell: bash
32 changes: 32 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: setup
description: Sets up the environment before running main workflows' steps.

runs:
using: composite

steps:
- name: Install the latest version of UV
uses: astral-sh/setup-uv@v6
with:
version: latest
enable-cache: true
cache-dependency-glob: '**/uv.lock'

- name: Setup Just
uses: extractions/setup-just@v2

- name: Install container-level dependencies
run: |
sudo apt update
sudo apt install just gcc-14 g++-14 wget
sudo apt-get update
sudo apt-get install -y iwyu cppcheck
shell: bash

- name: ccache
uses: hendrikmuhs/[email protected]

- name: Set up virtual environment
run: just setup_venv
shell: bash
51 changes: 51 additions & 0 deletions .github/workflows/cpplibs-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: unit-tests


on:
pull_request:
branches: [main, develop]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
testing:
runs-on: ubuntu-24.04

strategy:
matrix:
build_type: [Release, Debug]
enable_sanitizer_type: [NONE, address, undefined]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT }}

- name: Setup packages
uses: ./.github/actions/setup

- name: Install ci dependencies
run: just ci_install_ci_tools
shell: bash

- name: Build libraries
uses: ./.github/actions/build_cpplibs
with:
build_type: ${{ matrix.build_type }}
build_tests: ON
enable_sanitizer_type: ${{ matrix.enable_sanitizer_type }}

- name: Run unit tests
run: just ci_run_tests
timeout-minutes: 5

- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test_results-${{ matrix.build_type }}-${{ matrix.enable_sanitizer_type }}
path: test_results/
61 changes: 61 additions & 0 deletions .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: static-checks

on:
pull_request:
branches: [main, develop]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-24.04

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT }}

- name: Setup packages
uses: ./.github/actions/setup

- name: Install Python dependencies
run: just install_py_tools
shell: bash

- name: Install ci dependencies
run: just ci_install_ci_tools
shell: bash

- name: Run pre-commit checks
run: just ci_run_precommit

cpp-libs-checkers:
runs-on: ubuntu-24.04
needs: pre-commit

strategy:
matrix:
tested-command: [ci_run_clang_tidy, ci_run_iwyu_checks, ci_run_cppcheck]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.PAT }}

- name: Setup packages
uses: ./.github/actions/setup

- name: Install ci dependencies
run: just ci_install_ci_tools
shell: bash

- name: Run cpp static checks
run: just ${{ matrix.tested-command }}
shell: bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/
.venv/
**/__pycache__/**
.mypy_cache
test_results/
4 changes: 3 additions & 1 deletion 3rdParty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

include("../setuputils/cmake/Common.cmake")

option(TRY_UPDATE_SUBMODULES "Try to update git submodules during configuration" ON)

find_package(Git QUIET)

# Ensure the submodules are synced.
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if(TRY_UPDATE_SUBMODULES AND GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(MAIN_PROJECT_VERSION ${PROJECT_VERSION})

set(ENABLE_SANITIZER_TYPE "NONE" CACHE STRING "Type of sanitizer to use. Options are: NONE, address, undefined")

# Validate variable value
set(SANITIZER_TYPES "NONE;address;undefined")
if(NOT ENABLE_SANITIZER_TYPE IN_LIST "SANITIZER_TYPES")
message(FATAL_ERROR "Invalid value for ENABLE_SANITIZER_TYPE: ${ENABLE_SANITIZER_TYPE}. Valid options are: ${SANITIZER_TYPES}")
endif()

# ----------------------------------------------------------------------------
# Set default properties.
# ----------------------------------------------------------------------------

set(DEFAULT_BUILD_TYPE "Release")
set(DEFAULT_SHARED_LIBS ON)
# set(DEFAULT_SANITIZERS "None") # None, Address, Thread, Undefined

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to default '${DEFAULT_BUILD_TYPE}'.")
Expand All @@ -59,6 +68,7 @@ cmake_print_variables(
ENABLE_IWYU
ENABLE_CLANG_TIDY
ENABLE_CPPCHECK
ENABLE_SANITIZER_TYPE
)

# ----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions cpplibs/Layers/tests/TestSequentialLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ class TestSequentialLayer : public testUtilities::fixtures::LayersTestFixture

void _testCalling() override
{
const auto input = std::make_shared<autoDiff::Constant>(mlCore::Tensor{mlCore::TensorShape{32, 100}});
const auto input = std::make_shared<autoDiff::Constant>(mlCore::Tensor{mlCore::TensorShape{32, 10}});

_layer->build({input->getOutputShape()});
const auto output = _layer->call({input});

const mlCore::TensorShape expectedOutputShape{32, 100};
const mlCore::TensorShape expectedOutputShape{32, 10};
ASSERT_EQ(output->getOutputShape(), expectedOutputShape);
}
};
Expand Down
1 change: 0 additions & 1 deletion cpplibs/LoggingLib/src/LoggingLib/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>

#include <fmt/format.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void BackwardPassContext::run()
_finishedTaskCv.wait(lock, [this] { return _entryPointsQueue.empty(); });
}

_threadPool->terminate();

_outerDerivatives.clear();
_threadPool.reset();
}
Expand Down
10 changes: 8 additions & 2 deletions cpplibs/MLCore/src/AutoDiff/GraphHelpers/ForwardPassContext.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include "AutoDiff/GraphHelpers/ForwardPassContext.h"

#include <numeric>
#include <ranges>
#include <algorithm>
#include <cstddef>
#include <functional>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <utility>

#include <Utilities/ThreadPool.h>

namespace autoDiff::detail
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "AutoDiff/GraphHelpers/GraphInfoExtractor.h"

#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <memory>
#include <numeric>
#include <ranges>

Expand Down
2 changes: 2 additions & 0 deletions cpplibs/MLCore/src/MLCore/TensorOperations.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "MLCore/TensorOperations.h"

#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <map>
#include <numeric>
#include <ranges>
#include <utility>
#include <variant>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions cpplibs/MLCore/src/MLCore/TensorOperationsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ void checkShapesForBroadcasting(const std::vector<size_t>& shape1, const std::ve
{
// checking if the rules of broadcasting are not breached
for(auto [leftShapeIter, rightShapeIter] = std::tuple{shape1.crbegin(), shape2.crbegin()};
(leftShapeIter > shape1.crend()) && (rightShapeIter > shape2.crend());
leftShapeIter--, rightShapeIter--)
(leftShapeIter < shape1.crend()) && (rightShapeIter < shape2.crend());
leftShapeIter++, rightShapeIter++)
{
if((*leftShapeIter != 1) && (*rightShapeIter != 1) && (*leftShapeIter != *rightShapeIter))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#define MLCORE_SRC_INCLUDE_AUTODIFF_GRAPHHELPERS_FORWARDPASSCONTEXT_H

#include <condition_variable>
#include <memory>
#include <set>
#include <shared_mutex>
#include <vector>

#include <Utilities/ThreadPool.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef MLCORE_INCLUDE_AUTODIFF_GRAPHHELPERS_GRAPHINFOEXTRACTOR_H
#define MLCORE_INCLUDE_AUTODIFF_GRAPHHELPERS_GRAPHINFOEXTRACTOR_H

#include <cstddef>
#include <cstdint>
#include <map>
#include <utility>
#include <vector>

#include "AutoDiff/GraphNodes.hpp"

Expand Down
27 changes: 20 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ ci_install_ci_tools:
@echo "Installing CI tools..."
uv pip install -r pyproject.toml --extra ci

# Run tests using ctest.
# Run tests using ctest and collects coverage stats.
ci_run_tests:
@echo "Running tests..."
uv run ctest --test-dir build --output-on-failure
rm -rf test_results/ && mkdir -p test_results/coverage
uv run ctest -T Test --test-dir build --output-on-failure
uv run gcovr -r . --gcov-executable gcov-14 \
-o test_results/coverage/coverage.html \
--fail-under-line 80 --html-details \
--filter "cpplibs/.*" \
--exclude ".*/tests/.*"

# Run static checks for repository, such as pre-commit hooks and clang-tidy.
ci_run_static_checks:
ci_run_precommit:
#!/usr/bin/env bash

echo "Running pre-commit checks..."
Expand All @@ -73,13 +79,20 @@ ci_run_static_checks:

# Run clang tidy static checks.
ci_run_clang_tidy:
just --justfile {{justfile()}} build_project -DENABLE_CLANG_TIDY=ON
just --justfile {{justfile()}} build_project -DENABLE_CLANG_TIDY=ON -DTRY_UPDATE_SUBMODULES=OFF

# Run include-what-you-use static checks.
ci_run_iwyu_checks:
just --justfile {{justfile()}} build_project -DENABLE_IWYU=ON | tee /tmp/ci_iwyu_output
grep -E "Warning: include-what-you-use reported diagnostics:" /tmp/ci_iwyu_output && exit 1
#!/usr/bin/env bash
just --justfile {{justfile()}} build_project \
-DENABLE_IWYU=ON -DBUILD_TESTS=ON -DTRY_UPDATE_SUBMODULES=OFF | tee /tmp/ci_iwyu_output
found_warnings=$(grep -E "Warning: include-what-you-use reported diagnostics:" /tmp/ci_iwyu_output)

if [[ $found_warnings ]]; then
exit 1
fi


# Run cppcheck static checks.
ci_run_cppcheck:
just --justfile {{justfile()}} build_project -DENABLE_CPPCHECK=ON
just --justfile {{justfile()}} build_project -DENABLE_CPPCHECK=ON -DTRY_UPDATE_SUBMODULES=OFF
Loading