Skip to content

Commit

Permalink
[fbsync] Remove include Python.h (#8413)
Browse files Browse the repository at this point in the history
Reviewed By: vmoens

Differential Revision: D57565241

fbshipit-source-id: 47c428651d5ca5a9d33a6c83fa5d64b08ff23a06
  • Loading branch information
NicolasHug authored and facebook-github-bot committed May 20, 2024
1 parent 183aba1 commit 2112785
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 50 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ option(WITH_CUDA "Enable CUDA support" OFF)
option(WITH_MPS "Enable MPS support" OFF)
option(WITH_PNG "Enable features requiring LibPNG." ON)
option(WITH_JPEG "Enable features requiring LibJPEG." ON)
option(USE_PYTHON "Link to Python when building" OFF)

if(WITH_CUDA)
enable_language(CUDA)
Expand All @@ -33,11 +32,6 @@ if (WITH_JPEG)
find_package(JPEG REQUIRED)
endif()

if (USE_PYTHON)
add_definitions(-DUSE_PYTHON)
find_package(Python3 REQUIRED COMPONENTS Development)
endif()

function(CUDA_CONVERT_FLAGS EXISTING_TARGET)
get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS)
if(NOT "${old_flags}" STREQUAL "")
Expand Down Expand Up @@ -110,10 +104,6 @@ if (WITH_JPEG)
target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES})
endif()

if (USE_PYTHON)
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES
EXPORT_NAME TorchVision
INSTALL_RPATH ${TORCH_INSTALL_PREFIX}/lib)
Expand Down
8 changes: 0 additions & 8 deletions cmake/TorchVisionConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,5 @@ if(@WITH_JPEG@)
target_compile_definitions(${PN}::${PN} INTERFACE JPEG_FOUND)
endif()

if (@USE_PYTHON@)
if(NOT TARGET Python3::Python)
find_package(Python3 COMPONENTS Development)
endif()
target_link_libraries(torch INTERFACE Python3::Python)
target_compile_definitions(${PN}::${PN} INTERFACE USE_PYTHON)
endif()

endif()
endif()
3 changes: 0 additions & 3 deletions examples/cpp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ cmake --install .
You may want to pass `-DCMAKE_INSTALL_PREFIX=/path/to/libtorchvision` for
cmake to copy/install the files to a specific location (e.g. `$CONDA_PREFIX`).

On Windows, you may also need to pass `-DUSE_PYTHON`. Refer to the corresponding
`CMakeLists.txt` for additional options.

**DISCLAIMER**: the `libtorchvision` library includes the torchvision
custom ops as well as most of the C++ torchvision APIs. Those APIs do not come
with any backward-compatibility guarantees and may change from one version to
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def get_extensions():

if sys.platform == "win32":
define_macros += [("torchvision_EXPORTS", None)]
define_macros += [("USE_PYTHON", None)]
extra_compile_args["cxx"].append("/MP")

if debug_mode:
Expand Down Expand Up @@ -254,9 +253,6 @@ def get_extensions():
image_library = []
image_link_flags = []

if sys.platform == "win32":
image_macros += [("USE_PYTHON", None)]

# Locating libPNG
libpng = shutil.which("libpng-config")
pngfix = shutil.which("pngfix")
Expand Down
8 changes: 1 addition & 7 deletions torchvision/csrc/io/image/image.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#include "image.h"

#include <ATen/core/op_registration/op_registration.h>
#ifdef USE_PYTHON
#include <Python.h>
#endif

// If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension
#ifdef USE_PYTHON
#ifdef _WIN32
PyMODINIT_FUNC PyInit_image(void) {
// No need to do anything.
void* PyInit_image(void) {
return nullptr;
}
#endif
#endif // USE_PYTHON

namespace vision {
namespace image {
Expand Down
9 changes: 1 addition & 8 deletions torchvision/csrc/io/video_reader/video_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include "video_reader.h"

#ifdef USE_PYTHON
#include <Python.h>
#endif

#include "../decoder/memory_buffer.h"
#include "../decoder/sync_decoder.h"

#ifdef USE_PYTHON
// If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension
#ifdef _WIN32
PyMODINIT_FUNC PyInit_video_reader(void) {
// No need to do anything.
void* PyInit_video_reader(void) {
return nullptr;
}
#endif
#endif // USE_PYTHONs

using namespace ffmpeg;

Expand Down
11 changes: 1 addition & 10 deletions torchvision/csrc/vision.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "vision.h"

#ifndef MOBILE
#ifdef USE_PYTHON
#include <Python.h>
#endif
#endif
#include <torch/library.h>

#ifdef WITH_CUDA
Expand All @@ -16,14 +11,10 @@

// If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension.
// For PyMODINIT_FUNC to work, we need to include Python.h
#if !defined(MOBILE) && defined(_WIN32)
#ifdef USE_PYTHON
PyMODINIT_FUNC PyInit__C(void) {
// No need to do anything.
void* PyInit__C(void) {
return nullptr;
}
#endif // USE_PYTHON
#endif // !defined(MOBILE) && defined(_WIN32)

namespace vision {
Expand Down

0 comments on commit 2112785

Please sign in to comment.