Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance tests improvements #65

Merged
merged 12 commits into from
Oct 24, 2023
36 changes: 29 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ jobs:
sudo apt install libgdcm-dev

# install from source, because apt has old version
- name: Install GoogleTest and GoogleMock
- name: Install xsimd
if: ${{ endsWith(matrix.gamma-version, 'SIMD') }}
run: |
git clone https://github.com/google/googletest.git -b v1.13.0
cd googletest
git clone https://github.com/xtensor-stack/xsimd.git -b 11.1.0
cd xsimd
mkdir build && cd build
cmake ..
make
sudo make install

# install from source, because apt has old version
- name: Install xsimd
if: ${{ endsWith(matrix.gamma-version, 'SIMD') }}
- name: Install GoogleTest and GoogleMock
run: |
git clone https://github.com/xtensor-stack/xsimd.git -b 11.1.0
cd xsimd
git clone https://github.com/google/googletest.git -b v1.13.0
cd googletest
mkdir build && cd build
cmake ..
make
Expand Down Expand Up @@ -86,6 +86,28 @@ jobs:
run: |
cmake --install build --prefix ./yagit_install_dir

run-setup-linux:
if: >
github.repository == 'DataMedSci/yagit' &&
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]')
name: Run setup.sh on Linux
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Check versions
run: |
gcc --version
g++ --version
cmake --version

- name: Run setup.sh script
run: |
./setup.sh

build-windows:
if: >
github.repository == 'DataMedSci/yagit' &&
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ docs/build
# tests data files
!tests/unit/data/*.dcm
!tests/unit/data/*.mha

# plot output files
*plot*.png
*plot*.svg
*plot*.pdf
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[requires]
gdcm/3.0.20
gtest/1.13.0
xsimd/11.1.0
gtest/1.13.0

[generators]
CMakeDeps
Expand Down
2 changes: 1 addition & 1 deletion examples/gamma3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
std::string floatToString(float d){
std::ostringstream oss;
oss << d;
return oss.str();
return oss.str();
}

std::string gammaParametersToString(const yagit::GammaParameters& gammaParams){
Expand Down
10 changes: 5 additions & 5 deletions setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set BUILD_EXAMPLES=ON
set BUILD_TESTING=OFF
set BUILD_PERFORMANCE_TESTING=OFF

set REF_IMG=original_dose_beam_4.dcm
set EVAL_IMG=logfile_dose_beam_4.dcm
set REF_IMG=img_reference.dcm
set EVAL_IMG=img_evaluated.dcm

set INSTALL=OFF
set INSTALL_DIR=./yagit
Expand All @@ -30,7 +30,7 @@ if not exist build\CMakeCache.txt (
echo CONFIGURING CMAKE FIRST TIME...
mkdir build
cd build
conan install ..
conan install .. --output-folder . --build missing
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
cd ..
)
Expand Down Expand Up @@ -95,10 +95,10 @@ if %INSTALL% == ON (
echo:
echo INSTALLING...
IF "%INSTALL_DIR%" NEQ "" (
echo INSTALLING TO %INSTALL_DIR%
echo INSTALLING IN %INSTALL_DIR%
cmake --install build --prefix %INSTALL_DIR%
) else (
echo INSTALLING TO SYSTEM DIRECTORY
echo INSTALLING IN SYSTEM DIRECTORY
echo MAKE SURE YOU RUN THIS AS ADMINISTRATOR
cmake --install build
)
Expand Down
160 changes: 160 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash
michal367 marked this conversation as resolved.
Show resolved Hide resolved

BUILD_TYPE=Release
BUILD_SHARED_LIBS=OFF

# INSTALL_DEPENDENCIES=OFF
INSTALL_DEPENDENCIES=LOCAL
# INSTALL_DEPENDENCIES=GLOBAL # requires root privileges
# INSTALL_DEPENDENCIES=CONAN

# GAMMA_VERSION=SEQUENTIAL
GAMMA_VERSION=THREADS
# GAMMA_VERSION=SIMD
# GAMMA_VERSION=THREADS_SIMD

SIMD_EXTENSION=DEFAULT
# SIMD_EXTENSION=AVX2

ENABLE_FMA=OFF

BUILD_EXAMPLES=ON
BUILD_TESTING=OFF
BUILD_PERFORMANCE_TESTING=OFF

REF_IMG=img_reference.dcm
EVAL_IMG=img_evaluated.dcm

INSTALL=OFF
INSTALL_DIR=./yagit


# ============================================================
mkdir -p build
cd build

# ============================================================

install () {
# $1 - path to library to install

cd $1
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release -j

if [ $INSTALL_DEPENDENCIES == LOCAL ]; then
cmake --install . --prefix ./installed
elif [ $INSTALL_DEPENDENCIES == GLOBAL ]; then
sudo cmake --install .
fi

cd ../..
}

DEPENDENCIES_PATHS=""
TOOLCHAIN_FILE=""

if [[ $INSTALL_DEPENDENCIES == LOCAL || $INSTALL_DEPENDENCIES == GLOBAL ]]; then
echo "INSTALLING DEPENDENCIES..."
mkdir -p deps && cd deps

# GDCM
if [ ! -d GDCM ]; then
git clone https://github.com/malaterre/GDCM.git -b v3.0.22
install GDCM
fi

# xsimd
if [ ! -d xsimd ]; then
git clone https://github.com/xtensor-stack/xsimd.git -b 11.1.0
install xsimd
fi

# GoogleTest
if [ ! -d googletest ]; then
git clone https://github.com/google/googletest.git -b v1.13.0
install googletest
fi

if [ $INSTALL_DEPENDENCIES == LOCAL ]; then
GDCM_PATH="$(pwd)/GDCM/build/installed"
XSIMD_PATH="$(pwd)/xsimd/build/installed"
GTEST_PATH="$(pwd)/googletest/build/installed"
DEPENDENCIES_PATHS="$GDCM_PATH;$XSIMD_PATH;$GTEST_PATH"
fi

cd ..
elif [ $INSTALL_DEPENDENCIES == CONAN ]; then
conan install .. --output-folder . --build missing
TOOLCHAIN_FILE=conan_toolchain.cmake
fi


# ============================================================
echo ""
echo "CONFIGURING CMAKE..."
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
-DGAMMA_VERSION=$GAMMA_VERSION \
-DSIMD_EXTENSION=$SIMD_EXTENSION \
-DENABLE_FMA=$ENABLE_FMA \
-DBUILD_EXAMPLES=$BUILD_EXAMPLES \
-DBUILD_TESTING=$BUILD_TESTING \
-DBUILD_PERFORMANCE_TESTING=$BUILD_PERFORMANCE_TESTING \
-DCMAKE_PREFIX_PATH="$DEPENDENCIES_PATHS" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE"


# ============================================================
echo ""
echo "COMPILING..."
cmake --build . --config $BUILD_TYPE -j
COMPILE_RESULT=$?
cd ..

if [ $COMPILE_RESULT -ne 0 ]; then
exit $COMPILE_RESULT
fi


# ============================================================
if [ $BUILD_EXAMPLES == ON ]; then
echo ""
echo "RUNNING EXAMPLES..."
./build/examples/gamma2DInterp "$REF_IMG" "$EVAL_IMG"
echo ""
./build/examples/gamma25D "$REF_IMG" "$EVAL_IMG"
echo ""
./build/examples/gamma3D "$REF_IMG" "$EVAL_IMG"
echo ""
./build/examples/gammaImage
fi

if [ $BUILD_TESTING == ON ]; then
echo ""
echo "RUNNING UNIT TESTS..."
ctest -C $BUILD_TYPE --test-dir build --output-on-failure
fi

if [ $BUILD_PERFORMANCE_TESTING == ON ]; then
echo ""
echo "RUNNING PERFORMANCE TEST..."
./build/tests/performance/gammaPerf "$REF_IMG" "$EVAL_IMG" gammaTimes.csv
echo ""
./build/tests/performance/interpPerf "$EVAL_IMG"
fi


# ============================================================
if [ $INSTALL == ON ]; then
echo ""
echo "INSTALLING..."
if [ -n "$INSTALL_DIR" ]; then
echo "INSTALLING IN $INSTALL_DIR"
cmake --install build --prefix "$INSTALL_DIR"
else
echo "INSTALLING IN SYSTEM DIRECTORY"
sudo cmake --install build
fi
fi
2 changes: 1 addition & 1 deletion src/GammaResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace yagit{

double GammaResult::passingRate() const{
return static_cast<value_type>(std::count_if(m_data.begin(), m_data.end(), [](value_type el) {
return static_cast<double>(std::count_if(m_data.begin(), m_data.end(), [](value_type el) {
return !std::isnan(el) && el <= 1;
})) / nansize();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace yagit::Interpolation{
namespace{
// absolute tolerance that is useful for floating-point computations
// currently it is absolute tolerance, but it can be changed to relative tolerance if it turns out to work better
constexpr double Tolerance{5e-6};
constexpr double Tolerance{5e-7};

float calcNewOffset(float oldOffset, float gridOffset, float spacing){
// calculate closest point to oldOffset that is greater than or equal to oldOffset and also lies on grid.
// Tolerance here is useful in cases where value passed to ceil function is e.g. 12.0000001 due to computer
// floating-point errors and will be evaluated as 13 which is actually an incorrect result (correct is 12)
int n = std::ceil((oldOffset - gridOffset) / static_cast<double>(spacing) - Tolerance);
int n = std::ceil((oldOffset - gridOffset - Tolerance) / static_cast<double>(spacing));
float newOffset = gridOffset + n * spacing;
return newOffset;
}
Expand All @@ -43,7 +43,7 @@ constexpr uint32_t calcNewSize(uint32_t oldSize, float oldSpacing, float offsetR
// Tolerance here is useful in cases where value passed to truncation function (cast to integer)
// is e.g. 15.9999999 due to computer floating-point errors and will be evaluated as 15 which is actually
// an incorrect result (correct is 16)
return static_cast<uint32_t>((oldSpacing * (oldSize - 1) - offsetRel) / newSpacing + 1 + Tolerance);
return static_cast<uint32_t>((oldSpacing * (oldSize - 1) - offsetRel + Tolerance) / newSpacing + 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gamma/Gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ GammaResult gammaIndex2DClassic(const ImageData& refImg2D, const ImageData& eval

GammaResult gammaIndex2_5DClassic(const ImageData& refImg3D, const ImageData& evalImg3D,
const GammaParameters& gammaParams){
if(refImg3D.getSize().frames != evalImg3D.getSize().frames){
throw std::invalid_argument("reference image and evaluated image don't have the same number of frames");
if(evalImg3D.getSize().frames < refImg3D.getSize().frames){
throw std::invalid_argument("evaluated image must have at least the same number of frames as the reference image");
}
validateGammaParameters(gammaParams);

Expand Down
4 changes: 2 additions & 2 deletions src/gamma/GammaSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ GammaResult gammaIndex2DClassic(const ImageData& refImg2D, const ImageData& eval

GammaResult gammaIndex2_5DClassic(const ImageData& refImg3D, const ImageData& evalImg3D,
const GammaParameters& gammaParams){
if(refImg3D.getSize().frames != evalImg3D.getSize().frames){
throw std::invalid_argument("reference image and evaluated image don't have the same number of frames");
if(evalImg3D.getSize().frames < refImg3D.getSize().frames){
throw std::invalid_argument("evaluated image must have at least the same number of frames as the reference image");
}
validateGammaParameters(gammaParams);

Expand Down
4 changes: 2 additions & 2 deletions src/gamma/GammaThreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ GammaResult gammaIndex2DClassic(const ImageData& refImg2D, const ImageData& eval

GammaResult gammaIndex2_5DClassic(const ImageData& refImg3D, const ImageData& evalImg3D,
const GammaParameters& gammaParams){
if(refImg3D.getSize().frames != evalImg3D.getSize().frames){
throw std::invalid_argument("reference image and evaluated image don't have the same number of frames");
if(evalImg3D.getSize().frames < refImg3D.getSize().frames){
throw std::invalid_argument("evaluated image must have at least the same number of frames as the reference image");
}
validateGammaParameters(gammaParams);

Expand Down
4 changes: 2 additions & 2 deletions src/gamma/GammaThreadsSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ GammaResult gammaIndex2DClassic(const ImageData& refImg2D, const ImageData& eval

GammaResult gammaIndex2_5DClassic(const ImageData& refImg3D, const ImageData& evalImg3D,
const GammaParameters& gammaParams){
if(refImg3D.getSize().frames != evalImg3D.getSize().frames){
throw std::invalid_argument("reference image and evaluated image don't have the same number of frames");
if(evalImg3D.getSize().frames < refImg3D.getSize().frames){
throw std::invalid_argument("evaluated image must have at least the same number of frames as the reference image");
}
validateGammaParameters(gammaParams);

Expand Down
Loading