Skip to content

Add nihui's SimpleOMP support #4

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# CMake option to control OpenMP usage
option(USE_OPENMP "Use OpenMP for parallel programming" OFF)
option(USE_OPENMP "Use OpenMP for parallel programming" ON)
option(USE_SIMPLEOMP "Use nihui's SimpleOMP for parallel programming" ON)
option(USE_TBB "Use Intel oneTBB for parallel programming" OFF)

# CMake options to control project generation
option(BUILD_EXAMPLE "Build example target" ON)
option(BUILD_BENCHMARK "Build benchmark target" ON)
option(BUILD_CUDA_BENCHMARK "Build NVIDIA CUDA benchmark target" ON)
option(BUILD_ROCM_BENCHMARK "Build AMD ROCm benchmark target" ON)
option(BUILD_EXAMPLE_OPENCV "Build example-opencv target" OFF)
option(USE_TBB "Use Intel oneTBB for parallel programming" OFF)

# Check for OpenMP support if the option is enabled
set(OpenMP_FLAGS "")
if(USE_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
message(STATUS "Found OpenMP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(OpenMP_FLAGS ${OpenMP_CXX_FLAGS})
add_compile_definitions(USE_OPENMP)
else()
set(OpenMP_FLAGS "")
endif()
else()
set(OpenMP_FLAGS "")
endif()

set(SIMPLEOMP_FILES "")
if(USE_OPENMP AND USE_SIMPLEOMP)
set(SIMPLEOMP_FILES platform.h simpleomp.h simpleomp.cpp)
add_compile_definitions(USE_SIMPLEOMP)
endif()

# Check for Intel oneTBB support if the option is enabled
Expand All @@ -51,34 +55,36 @@ endif()

# Add executable targets based on options
if(BUILD_EXAMPLE)
add_executable(example FastChwHwcConverter.hpp test/example.cpp)
add_executable(example FastChwHwcConverter.hpp test/example.cpp ${SIMPLEOMP_FILES})
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${TBB_INCLUDE_DIRS})
target_compile_options(example PRIVATE ${OpenMP_FLAGS})
target_link_libraries(example PRIVATE ${TBB_LIBS})
endif()

if(BUILD_BENCHMARK)
add_executable(benchmark FastChwHwcConverter.hpp test/benchmark.cpp)
add_executable(benchmark FastChwHwcConverter.hpp test/benchmark.cpp ${SIMPLEOMP_FILES})
target_include_directories(benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${TBB_INCLUDE_DIRS})
target_compile_options(benchmark PRIVATE ${OpenMP_FLAGS})
target_link_libraries(benchmark PRIVATE ${TBB_LIBS})
endif()

if(BUILD_CUDA_BENCHMARK)
add_executable(cuda_benchmark DynamicLibraryManager.hpp FastChwHwcConverterCuda.hpp test/cuda_benchmark.cpp)
add_executable(cuda_benchmark DynamicLibraryManager.hpp FastChwHwcConverterCuda.hpp test/cuda_benchmark.cpp ${SIMPLEOMP_FILES})
target_include_directories(cuda_benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${TBB_INCLUDE_DIRS})
target_compile_options(cuda_benchmark PRIVATE ${OpenMP_FLAGS})
target_link_libraries(cuda_benchmark PRIVATE ${TBB_LIBS})
endif()

if(BUILD_ROCM_BENCHMARK)
add_executable(rocm_benchmark DynamicLibraryManager.hpp FastChwHwcConverterROCm.hpp test/rocm_benchmark.cpp)
add_executable(rocm_benchmark DynamicLibraryManager.hpp FastChwHwcConverterROCm.hpp test/rocm_benchmark.cpp ${SIMPLEOMP_FILES})
target_include_directories(rocm_benchmark PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${TBB_INCLUDE_DIRS})
target_compile_options(rocm_benchmark PRIVATE ${OpenMP_FLAGS})
target_link_libraries(rocm_benchmark PRIVATE ${TBB_LIBS})
endif()

if(BUILD_EXAMPLE_OPENCV)
add_executable(example-opencv FastChwHwcConverter.hpp test/example-opencv.cpp)
target_include_directories(example-opencv PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${OpenCV_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS})
target_include_directories(example-opencv PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${OpenCV_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS} ${SIMPLEOMP_FILES})
target_link_libraries(example-opencv PRIVATE ${OpenCV_LIBS})
target_compile_options(example-opencv PRIVATE ${OpenMP_FLAGS})
target_link_libraries(example-opencv PRIVATE ${TBB_LIBS})
Expand Down
4 changes: 4 additions & 0 deletions FastChwHwcConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
#include <future>

#ifdef USE_OPENMP
#ifdef USE_SIMPLEOMP
#include <simpleomp.h>
#else
#include <omp.h>
#endif
#endif

// Check if the compiler supports C++17
#if __cplusplus >= 201703L
Expand Down
Loading