Skip to content

Commit

Permalink
Fix for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
msg7086 committed Jun 22, 2020
1 parent 20e6d7e commit ce598cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.15)
cmake_minimum_required (VERSION 3.1)
project (neo_vague_denoiser CXX)
file(GLOB CODE "src/*.cpp")
file(GLOB SSE_CODE_IMPL "src/*SSE.cpp")
Expand All @@ -7,6 +7,7 @@ file(GLOB AVX_CODE_IMPL "src/*AVX.cpp")
file(GLOB AVX2_CODE_IMPL "src/*AVX2.cpp")
add_library(neo-vague-denoiser SHARED main.cpp src/version.rc ${CODE} ${CODE_IMPL})
set_property(TARGET neo-vague-denoiser PROPERTY CXX_STANDARD 17)
option(ENABLE_PAR "Enable C++17 Parallel Execution" ON)
add_compile_definitions(VS_TARGET_CPU_X86)

find_package(Git REQUIRED)
Expand Down Expand Up @@ -64,10 +65,20 @@ else()
set_source_files_properties(${SSE41_CODE_IMPL} PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(${AVX_CODE_IMPL} PROPERTIES COMPILE_FLAGS "-mavx")
set_source_files_properties(${AVX2_CODE_IMPL} PROPERTIES COMPILE_FLAGS "-mfma -mavx2")

endif()

include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(execution HAS_EXECUTION)
if(HAS_EXECUTION)
add_definitions(-DHAS_EXECUTION)
endif()
if(ENABLE_PAR AND HAS_EXECUTION)
add_definitions(-DENABLE_PAR)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(neo-vague-denoiser tbb)
endif()

endif()

add_custom_command(
Expand Down
19 changes: 16 additions & 3 deletions src/neo_vd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

#pragma once

#ifdef HAS_EXECUTION
#include <execution>
#endif

#ifndef __cpp_lib_execution
#undef ENABLE_PAR
#endif

#include <numeric>
#include <execution>
#include <mutex>
#include "common.h"
#include "core.h"
Expand Down Expand Up @@ -238,9 +245,12 @@ struct VagueDenoiser final : Filter {
auto src0 = in_frames[n];
auto dst = src0.Create(false);

// for (int p = 0; p < in_vi.Format.Planes; p++) {
#ifdef ENABLE_PAR
std::for_each_n(std::execution::par, reinterpret_cast<char*>(0), in_vi.Format.Planes, [&](char&idx) {
int p = static_cast<int>(reinterpret_cast<intptr_t>(&idx));
#else
for (int p = 0; p < in_vi.Format.Planes; p++) {
#endif
bool chroma = in_vi.Format.IsFamilyYUV && p > 0 && p < 3;
auto height = in_vi.Height;
auto width = in_vi.Width;
Expand Down Expand Up @@ -279,7 +289,10 @@ struct VagueDenoiser final : Filter {
else if (ep.process[p] == 2) {
framecpy(dst0_ptr, dst0_stride, src0_ptr, src0_stride, width * in_vi.Format.BytesPerSample, height);
}
});
}
#ifdef ENABLE_PAR
);
#endif

thread_id_store[thread_id] = false;
return dst;
Expand Down

0 comments on commit ce598cb

Please sign in to comment.