Skip to content

Commit 2e7ec23

Browse files
allnesaobolensk
andauthored
Remove OpenCV and add STB (#372)
Co-authored-by: Arseniy Obolenskiy <[email protected]>
1 parent bfaa28f commit 2e7ec23

File tree

12 files changed

+43
-98
lines changed

12 files changed

+43
-98
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ CheckOptions:
8787
value: 1
8888
# Functions with scores beyond 15 are typically flagged as potentially problematic (empirically)
8989
- key: readability-function-cognitive-complexity.Threshold
90-
value: 15 # default: 25
90+
value: 20 # default: 25
9191
- key: misc-include-cleaner.IgnoreHeaders
9292
value: '(opencv2/.*|__chrono/.*)'

.github/workflows/static-analysis-pr.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
id: review
2222
with:
2323
build_dir: build
24-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind,libopencv-dev
24+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind
2525
cmake_command: >
2626
cmake -S . -B build
2727
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
@@ -30,7 +30,6 @@ jobs:
3030
-D USE_SEQ=ON -D USE_MPI=ON
3131
-D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON
3232
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
33-
-D USE_SYSTEM_OPENCV=ON
3433
config_file: .clang-tidy
3534
exclude: 3rdparty
3635
split_workflow: true
@@ -59,7 +58,7 @@ jobs:
5958
id: review
6059
with:
6160
build_dir: build
62-
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind,libopencv-dev
61+
apt_packages: mpich,libmpich*,mpi*,openmpi-bin,ninja-build,libomp-19-dev,valgrind
6362
cmake_command: >
6463
cmake -S . -B build
6564
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
@@ -68,7 +67,6 @@ jobs:
6867
-D USE_SEQ=ON -D USE_MPI=ON
6968
-D USE_OMP=ON -D USE_TBB=ON -D USE_STL=ON
7069
-D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
71-
-D USE_SYSTEM_OPENCV=ON
7270
config_file: .clang-tidy
7371
exclude: 3rdparty
7472
split_workflow: true

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
[submodule "3rdparty/onetbb"]
55
path = 3rdparty/onetbb
66
url = https://github.com/uxlfoundation/oneTBB
7-
[submodule "3rdparty/opencv"]
8-
path = 3rdparty/opencv
9-
url = https://github.com/opencv/opencv
7+
[submodule "3rdparty/stb"]
8+
path = 3rdparty/stb
9+
url = https://github.com/nothings/stb

3rdparty/opencv

Lines changed: 0 additions & 1 deletion
This file was deleted.

3rdparty/stb

Submodule stb added at 802cd45

3rdparty/stb_library.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#if defined(__clang__)
4+
#pragma clang diagnostic push
5+
#pragma clang diagnostic ignored "-Wcast-align"
6+
#endif
7+
8+
#define STB_IMAGE_IMPLEMENTATION
9+
#include <stb/stb_image.h>
10+
11+
#if defined(__clang__)
12+
#pragma clang diagnostic pop
13+
#endif

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ include(cmake/onetbb.cmake)
2121
######################### External projects #########################
2222

2323
message( STATUS "PPC step: Setup external projects" )
24-
include(cmake/opencv.cmake)
2524
include(cmake/gtest.cmake)
2625

2726
########################### Documentation ###########################

cmake/configure.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ else ()
2525
endif ()
2626

2727
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
28+
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
29+
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
30+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
31+
set(CMAKE_SKIP_BUILD_RPATH OFF)
2832

2933
if( UNIX )
3034
set(COMMON_COMPILER_FLAGS
@@ -52,7 +56,7 @@ if( UNIX )
5256
-Wold-style-definition \
5357
-Wmissing-prototypes")
5458

55-
if (${ENABLE_ADDRESS_SANITIZER} OR ${ENABLE_UB_SANITIZER})
59+
if ("${ENABLE_ADDRESS_SANITIZER}" OR "${ENABLE_UB_SANITIZER}")
5660
set (COMMON_COMPILER_FLAGS "${COMMON_COMPILER_FLAGS} -Wno-cast-align")
5761
endif()
5862

cmake/opencv.cmake

Lines changed: 0 additions & 45 deletions
This file was deleted.

scripts/run_tests.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ def __init__(self):
2929
self.work_dir = None
3030
self.valgrind_cmd = "valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all"
3131

32-
if platform.system() == "Windows":
33-
self.ocv_script_name = "setup_vars_opencv4.cmd"
34-
self.ocv_script_path = Path("build/ppc_opencv/install/") / self.ocv_script_name
35-
else:
36-
self.ocv_script_name = "setup_vars_opencv4.sh"
37-
self.ocv_script_path = Path("build/ppc_opencv/install/bin/") / self.ocv_script_name
38-
3932
if platform.system() == "Windows":
4033
self.mpi_exec = "mpiexec"
4134
else:
@@ -66,16 +59,7 @@ def __source_script(script_path):
6659
return {}
6760

6861
def setup_env(self):
69-
if os.path.isfile(Path(self.__get_project_path()) / self.ocv_script_path):
70-
_work_dir = Path(self.__get_project_path()) / "build/bin"
71-
env_vars = self.__source_script(Path(self.__get_project_path()) / self.ocv_script_path)
72-
else:
73-
_work_dir = Path(self.__get_project_path()) / "install/bin"
74-
env_vars = self.__source_script(Path(_work_dir) / self.ocv_script_name)
75-
76-
self.work_dir = Path(_work_dir)
77-
if not platform.system() == "Windows":
78-
os.environ.update(env_vars)
62+
self.work_dir = Path(self.__get_project_path()) / "install" / "bin"
7963

8064
@staticmethod
8165
def __run_exec(command):

tasks/CMakeLists.txt

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ endif ()
3838

3939
add_compile_definitions(PATH_TO_PPC_PROJECT="${CMAKE_SOURCE_DIR}")
4040

41+
add_library(stb_image INTERFACE)
42+
4143
foreach(TASK_TYPE ${LIST_OF_TASKS})
4244
set(PATH_TO_TASK "${CMAKE_CURRENT_SOURCE_DIR}/${TASK_TYPE}")
4345
get_filename_component(MODULE_NAME ${PATH_TO_TASK} NAME)
@@ -130,27 +132,8 @@ foreach(TASK_TYPE ${LIST_OF_TASKS})
130132
endif()
131133
endif ()
132134

133-
add_dependencies(${EXEC_FUNC} ppc_opencv)
134-
if(WIN32)
135-
target_include_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/install/include")
136-
else()
137-
target_include_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/install/include/opencv4")
138-
endif()
139-
140-
141-
if(WIN32)
142-
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/build/lib")
143-
set(OCV_VERSION "4110")
144-
else()
145-
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_opencv/install/lib")
146-
endif()
147-
148-
target_link_libraries(${EXEC_FUNC} PUBLIC
149-
opencv_core${OCV_VERSION}
150-
opencv_highgui${OCV_VERSION}
151-
opencv_imgcodecs${OCV_VERSION}
152-
opencv_imgproc${OCV_VERSION}
153-
opencv_videoio${OCV_VERSION})
135+
target_link_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
136+
target_link_libraries(${EXEC_FUNC} PUBLIC stb_image)
154137

155138
add_dependencies(${EXEC_FUNC} ppc_googletest)
156139
target_link_directories(${EXEC_FUNC} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")

tasks/all/example/func_tests/func_all.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <cstddef>
44
#include <cstdint>
55
#include <memory>
6-
#include <opencv2/opencv.hpp>
6+
#include <stb_library.hpp>
7+
#include <string>
78
#include <vector>
89

910
#include "all/example/include/ops_all.hpp"
@@ -38,9 +39,17 @@ TEST(nesterov_a_test_task_all, test_matmul_50) {
3839
}
3940

4041
TEST(nesterov_a_test_task_all, test_matmul_from_pic) {
41-
cv::Mat img = cv::imread(ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg"));
42-
EXPECT_EQ(img.rows, img.cols);
43-
const int count = (img.rows + img.cols) / 10;
42+
int width = -1;
43+
int height = -1;
44+
int channels = -1;
45+
std::string abs_path = ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg");
46+
unsigned char *data = stbi_load(abs_path.c_str(), &width, &height, &channels, 0);
47+
EXPECT_TRUE(data != nullptr) << "Failed to load image: " << stbi_failure_reason() << '\n';
48+
auto img = std::vector<uint8_t>(data, data + (width * height * channels));
49+
stbi_image_free(data);
50+
51+
EXPECT_EQ(width, height);
52+
const int count = (width + height) / 10;
4453

4554
// Create data
4655
std::vector<int> in(count * count, 0);

0 commit comments

Comments
 (0)