Skip to content

Commit

Permalink
python: support free-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Oct 19, 2024
1 parent 10446e8 commit 6ca0147
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include (CTest)

check_cxx_compiler_flag (-Wa,-mbig-obj HAVE_MBIG_OBJ)
check_cxx_compiler_flag (/bigobj HAVE_BIGOBJ)
check_cxx_compiler_flag (/Zc:preprocessor HAVE_ZC_PREPROCESSOR)

find_package (Boost 1.70 COMPONENTS unit_test_framework NO_MODULE)
find_package (Eigen3 3.3.7 REQUIRED NO_MODULE)
Expand All @@ -30,6 +31,14 @@ endif (MSVC AND MSVC_VERSION GREATER_EQUAL 1930)

check_cxx_symbol_exists (std::execution::par execution HAVE_EXECUTION)

if (WIN32)
add_compile_definitions (WIN32_LEAN_AND_MEAN)
endif (WIN32)

if (HAVE_ZC_PREPROCESSOR)
add_compile_options (/Zc:preprocessor)
endif (HAVE_ZC_PREPROCESSOR)

add_library (hogpp INTERFACE)
add_library (hogpp::hogpp ALIAS hogpp)

Expand Down Expand Up @@ -81,6 +90,7 @@ if (pybind11_FOUND AND Python_Development_FOUND)
python/blocknormalizer.hpp
python/formatter.hpp
python/hogpp.cpp
python/hogpp.hpp
python/integralhogdescriptor.cpp
python/integralhogdescriptor.hpp
python/magnitude.cpp
Expand Down
10 changes: 9 additions & 1 deletion python/hogpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@

#include "binning.hpp"
#include "blocknormalizer.hpp"
#include "hogpp.hpp"
#include "integralhogdescriptor.hpp"
#include "magnitude.hpp"
#include "type_caster/bounds.hpp"

PYBIND11_MODULE(hogpp, m)
#if defined(HOGPP_GIL_DISABLED)
#define HOGPP_MODULE(name, module, ...) \
PYBIND11_MODULE(name, module, pybind11::mod_gil_not_used())
#else // !defined(HOGPP_GIL_DISABLED)
#define HOGPP_MODULE PYBIND11_MODULE
#endif // defined(HOGPP_GIL_DISABLED)

HOGPP_MODULE(hogpp, m)
{
namespace py = pybind11;

Expand Down
36 changes: 36 additions & 0 deletions python/hogpp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// HOGpp - Fast histogram of oriented gradients computation using integral
// histograms
//
// Copyright 2024 Sergiu Deitsch <sergiu.deitsch@gmail.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef PYTHON_HOGPP_HPP
#define PYTHON_HOGPP_HPP

#include <pybind11/pybind11.h>

#define HOGPP_PYBIND11_MAKE_VERSION(major, minor, patch) \
((major) << 16 | (minor) << 8 | (patch))

#define HOGPP_PYBIND11_VERSION_AT_LEAST(...) \
(((PYBIND11_VERSION_HEX & 0xFF'FF'FF'00) >> 8) >= \
HOGPP_PYBIND11_MAKE_VERSION(__VA_ARGS__))

#if defined(Py_GIL_DISABLED) && HOGPP_PYBIND11_VERSION_AT_LEAST(2, 13, 0)
#define HOGPP_GIL_DISABLED
#endif // (defined(Py_GIL_DISABLED) && HOGPP_PYBIND11_AT_LEAST(2, 13, 0))

#endif // PYTHON_HOGPP_HPP
3 changes: 3 additions & 0 deletions python/integralhogdescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#if defined(HAVE_OPENCV)
#include "type_caster/opencv.hpp"
#endif // defined(HAVE_OPENCV)
#include "hogpp.hpp"
#include "type_caster/tensor.hpp"

namespace {
Expand Down Expand Up @@ -547,7 +548,9 @@ pybind11::object IntegralHOGDescriptor::featuresROIs(
};

{
#if !defined(HOGPP_GIL_DISABLED)
pybind11::gil_scoped_release release;
#endif // !defined(HOGPP_GIL_DISABLED)

// Process the remaining bounds
std::for_each(
Expand Down

0 comments on commit 6ca0147

Please sign in to comment.