From 3420106602fbc3b6b7997cbd11b07655a2440765 Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Thu, 10 Dec 2020 10:13:53 -0800 Subject: [PATCH] Restructuring C++ project: Summary: * Reduce unnecessary header inclusions in models and io. * Move autocast to separate folder and hide autograd implementation in an anonymous namespace. * Moving files in subfolders. Reviewed By: fmassa Differential Revision: D25461523 fbshipit-source-id: 756eeb6848aacaa474de4825ed4c1045d17e2cea --- CMakeLists.txt | 40 ++++++-------- examples/cpp/hello_world/main.cpp | 2 + setup.py | 27 +++++----- test/tracing/frcnn/test_frcnn_tracing.cpp | 5 +- torchvision/csrc/cpu/image/image.h | 11 ---- .../{cpu => io}/decoder/audio_sampler.cpp | 0 .../csrc/{cpu => io}/decoder/audio_sampler.h | 0 .../csrc/{cpu => io}/decoder/audio_stream.cpp | 0 .../csrc/{cpu => io}/decoder/audio_stream.h | 0 .../csrc/{cpu => io}/decoder/cc_stream.cpp | 0 .../csrc/{cpu => io}/decoder/cc_stream.h | 0 .../csrc/{cpu => io}/decoder/decoder.cpp | 0 .../csrc/{cpu => io}/decoder/decoder.h | 0 torchvision/csrc/{cpu => io}/decoder/defs.h | 0 .../{cpu => io}/decoder/memory_buffer.cpp | 0 .../csrc/{cpu => io}/decoder/memory_buffer.h | 0 .../{cpu => io}/decoder/seekable_buffer.cpp | 0 .../{cpu => io}/decoder/seekable_buffer.h | 0 .../csrc/{cpu => io}/decoder/stream.cpp | 0 torchvision/csrc/{cpu => io}/decoder/stream.h | 0 .../{cpu => io}/decoder/subtitle_sampler.cpp | 0 .../{cpu => io}/decoder/subtitle_sampler.h | 0 .../{cpu => io}/decoder/subtitle_stream.cpp | 0 .../{cpu => io}/decoder/subtitle_stream.h | 0 .../csrc/{cpu => io}/decoder/sync_decoder.cpp | 0 .../csrc/{cpu => io}/decoder/sync_decoder.h | 0 .../{cpu => io}/decoder/sync_decoder_test.cpp | 0 .../csrc/{cpu => io}/decoder/time_keeper.cpp | 0 .../csrc/{cpu => io}/decoder/time_keeper.h | 0 torchvision/csrc/{cpu => io}/decoder/util.cpp | 0 torchvision/csrc/{cpu => io}/decoder/util.h | 0 .../csrc/{cpu => io}/decoder/util_test.cpp | 0 .../{cpu => io}/decoder/video_sampler.cpp | 0 .../csrc/{cpu => io}/decoder/video_sampler.h | 0 .../csrc/{cpu => io}/decoder/video_stream.cpp | 0 .../csrc/{cpu => io}/decoder/video_stream.h | 0 .../image => io/image/cpu}/read_image_cpu.cpp | 1 + .../image => io/image/cpu}/read_image_cpu.h | 4 +- .../image/cpu}/read_write_file_cpu.cpp | 0 .../image/cpu}/read_write_file_cpu.h | 3 +- .../image => io/image/cpu}/readjpeg_cpu.cpp | 6 +-- .../image => io/image/cpu}/readjpeg_cpu.h | 4 +- .../image => io/image/cpu}/readpng_cpu.cpp | 2 - .../{cpu/image => io/image/cpu}/readpng_cpu.h | 4 +- .../image => io/image/cpu}/writejpeg_cpu.cpp | 7 +-- .../image => io/image/cpu}/writejpeg_cpu.h | 2 +- .../image => io/image/cpu}/writepng_cpu.cpp | 5 +- .../image => io/image/cpu}/writepng_cpu.h | 2 +- torchvision/csrc/{cpu => io}/image/image.cpp | 3 +- torchvision/csrc/io/image/image.h | 8 +++ .../csrc/{cpu => io}/image/image_read_mode.h | 0 .../csrc/{cpu => io}/image/jpegcommon.cpp | 3 +- .../csrc/{cpu => io}/image/jpegcommon.h | 1 - torchvision/csrc/{cpu => io}/video/Video.cpp | 0 torchvision/csrc/{cpu => io}/video/Video.h | 0 .../csrc/{cpu => io}/video/register.cpp | 0 .../{cpu => io}/video_reader/VideoReader.cpp | 0 .../{cpu => io}/video_reader/VideoReader.h | 0 torchvision/csrc/models/alexnet.h | 2 +- torchvision/csrc/models/densenet.h | 2 +- torchvision/csrc/models/googlenet.cpp | 2 - torchvision/csrc/models/googlenet.h | 2 +- torchvision/csrc/models/inception.h | 2 +- torchvision/csrc/models/mnasnet.h | 2 +- torchvision/csrc/models/mobilenet.h | 2 +- torchvision/csrc/models/modelsimpl.h | 6 +-- torchvision/csrc/models/resnet.cpp | 2 - torchvision/csrc/models/resnet.h | 2 +- torchvision/csrc/models/shufflenetv2.h | 2 +- torchvision/csrc/models/squeezenet.h | 2 +- torchvision/csrc/models/vgg.h | 2 +- .../ops/autocast/deform_conv2d_kernel.cpp | 52 +++++++++++++++++++ torchvision/csrc/ops/autocast/nms_kernel.cpp | 29 +++++++++++ .../csrc/ops/autocast/ps_roi_align_kernel.cpp | 39 ++++++++++++++ .../csrc/ops/autocast/ps_roi_pool_kernel.cpp | 37 +++++++++++++ .../csrc/ops/autocast/roi_align_kernel.cpp | 38 ++++++++++++++ .../csrc/ops/autocast/roi_pool_kernel.cpp | 37 +++++++++++++ .../{ => ops}/cpu/deform_conv2d_kernel.cpp | 0 torchvision/csrc/{ => ops}/cpu/nms_kernel.cpp | 0 .../{ => ops}/cpu/ps_roi_align_kernel.cpp | 0 .../csrc/{ => ops}/cpu/ps_roi_pool_kernel.cpp | 0 .../csrc/{ => ops}/cpu/roi_align_kernel.cpp | 0 .../csrc/{ => ops}/cpu/roi_pool_kernel.cpp | 0 .../csrc/{ => ops}/cuda/cuda_helpers.h | 0 .../{ => ops}/cuda/deform_conv2d_kernel.cu | 0 torchvision/csrc/{ => ops}/cuda/nms_kernel.cu | 0 .../{ => ops}/cuda/ps_roi_align_kernel.cu | 0 .../csrc/{ => ops}/cuda/ps_roi_pool_kernel.cu | 0 .../csrc/{ => ops}/cuda/roi_align_kernel.cu | 0 .../csrc/{ => ops}/cuda/roi_pool_kernel.cu | 0 torchvision/csrc/{ => ops}/deform_conv2d.cpp | 48 +---------------- torchvision/csrc/{ => ops}/deform_conv2d.h | 2 +- .../csrc/{ => ops}/new_empty_tensor_op.cpp | 0 .../csrc/{ => ops}/new_empty_tensor_op.h | 2 +- torchvision/csrc/{ => ops}/nms.cpp | 21 -------- torchvision/csrc/{ => ops}/nms.h | 2 +- torchvision/csrc/{ => ops}/ps_roi_align.cpp | 35 +------------ torchvision/csrc/{ => ops}/ps_roi_align.h | 2 +- torchvision/csrc/{ => ops}/ps_roi_pool.cpp | 33 +----------- torchvision/csrc/{ => ops}/ps_roi_pool.h | 2 +- torchvision/csrc/{ => ops}/roi_align.cpp | 34 +----------- torchvision/csrc/{ => ops}/roi_align.h | 2 +- torchvision/csrc/{ => ops}/roi_pool.cpp | 33 +----------- torchvision/csrc/{ => ops}/roi_pool.h | 2 +- 104 files changed, 318 insertions(+), 302 deletions(-) delete mode 100644 torchvision/csrc/cpu/image/image.h rename torchvision/csrc/{cpu => io}/decoder/audio_sampler.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/audio_sampler.h (100%) rename torchvision/csrc/{cpu => io}/decoder/audio_stream.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/audio_stream.h (100%) rename torchvision/csrc/{cpu => io}/decoder/cc_stream.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/cc_stream.h (100%) rename torchvision/csrc/{cpu => io}/decoder/decoder.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/decoder.h (100%) rename torchvision/csrc/{cpu => io}/decoder/defs.h (100%) rename torchvision/csrc/{cpu => io}/decoder/memory_buffer.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/memory_buffer.h (100%) rename torchvision/csrc/{cpu => io}/decoder/seekable_buffer.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/seekable_buffer.h (100%) rename torchvision/csrc/{cpu => io}/decoder/stream.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/stream.h (100%) rename torchvision/csrc/{cpu => io}/decoder/subtitle_sampler.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/subtitle_sampler.h (100%) rename torchvision/csrc/{cpu => io}/decoder/subtitle_stream.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/subtitle_stream.h (100%) rename torchvision/csrc/{cpu => io}/decoder/sync_decoder.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/sync_decoder.h (100%) rename torchvision/csrc/{cpu => io}/decoder/sync_decoder_test.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/time_keeper.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/time_keeper.h (100%) rename torchvision/csrc/{cpu => io}/decoder/util.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/util.h (100%) rename torchvision/csrc/{cpu => io}/decoder/util_test.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/video_sampler.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/video_sampler.h (100%) rename torchvision/csrc/{cpu => io}/decoder/video_stream.cpp (100%) rename torchvision/csrc/{cpu => io}/decoder/video_stream.h (100%) rename torchvision/csrc/{cpu/image => io/image/cpu}/read_image_cpu.cpp (99%) rename torchvision/csrc/{cpu/image => io/image/cpu}/read_image_cpu.h (70%) rename torchvision/csrc/{cpu/image => io/image/cpu}/read_write_file_cpu.cpp (100%) rename torchvision/csrc/{cpu/image => io/image/cpu}/read_write_file_cpu.h (80%) rename torchvision/csrc/{cpu/image => io/image/cpu}/readjpeg_cpu.cpp (98%) rename torchvision/csrc/{cpu/image => io/image/cpu}/readjpeg_cpu.h (70%) rename torchvision/csrc/{cpu/image => io/image/cpu}/readpng_cpu.cpp (99%) rename torchvision/csrc/{cpu/image => io/image/cpu}/readpng_cpu.h (70%) rename torchvision/csrc/{cpu/image => io/image/cpu}/writejpeg_cpu.cpp (97%) rename torchvision/csrc/{cpu/image => io/image/cpu}/writejpeg_cpu.h (79%) rename torchvision/csrc/{cpu/image => io/image/cpu}/writepng_cpu.cpp (99%) rename torchvision/csrc/{cpu/image => io/image/cpu}/writepng_cpu.h (82%) rename torchvision/csrc/{cpu => io}/image/image.cpp (97%) create mode 100644 torchvision/csrc/io/image/image.h rename torchvision/csrc/{cpu => io}/image/image_read_mode.h (100%) rename torchvision/csrc/{cpu => io}/image/jpegcommon.cpp (96%) rename torchvision/csrc/{cpu => io}/image/jpegcommon.h (96%) rename torchvision/csrc/{cpu => io}/video/Video.cpp (100%) rename torchvision/csrc/{cpu => io}/video/Video.h (100%) rename torchvision/csrc/{cpu => io}/video/register.cpp (100%) rename torchvision/csrc/{cpu => io}/video_reader/VideoReader.cpp (100%) rename torchvision/csrc/{cpu => io}/video_reader/VideoReader.h (100%) create mode 100644 torchvision/csrc/ops/autocast/deform_conv2d_kernel.cpp create mode 100644 torchvision/csrc/ops/autocast/nms_kernel.cpp create mode 100644 torchvision/csrc/ops/autocast/ps_roi_align_kernel.cpp create mode 100644 torchvision/csrc/ops/autocast/ps_roi_pool_kernel.cpp create mode 100644 torchvision/csrc/ops/autocast/roi_align_kernel.cpp create mode 100644 torchvision/csrc/ops/autocast/roi_pool_kernel.cpp rename torchvision/csrc/{ => ops}/cpu/deform_conv2d_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cpu/nms_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cpu/ps_roi_align_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cpu/ps_roi_pool_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cpu/roi_align_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cpu/roi_pool_kernel.cpp (100%) rename torchvision/csrc/{ => ops}/cuda/cuda_helpers.h (100%) rename torchvision/csrc/{ => ops}/cuda/deform_conv2d_kernel.cu (100%) rename torchvision/csrc/{ => ops}/cuda/nms_kernel.cu (100%) rename torchvision/csrc/{ => ops}/cuda/ps_roi_align_kernel.cu (100%) rename torchvision/csrc/{ => ops}/cuda/ps_roi_pool_kernel.cu (100%) rename torchvision/csrc/{ => ops}/cuda/roi_align_kernel.cu (100%) rename torchvision/csrc/{ => ops}/cuda/roi_pool_kernel.cu (100%) rename torchvision/csrc/{ => ops}/deform_conv2d.cpp (87%) rename torchvision/csrc/{ => ops}/deform_conv2d.h (95%) rename torchvision/csrc/{ => ops}/new_empty_tensor_op.cpp (100%) rename torchvision/csrc/{ => ops}/new_empty_tensor_op.h (90%) rename torchvision/csrc/{ => ops}/nms.cpp (51%) rename torchvision/csrc/{ => ops}/nms.h (90%) rename torchvision/csrc/{ => ops}/ps_roi_align.cpp (87%) rename torchvision/csrc/{ => ops}/ps_roi_align.h (93%) rename torchvision/csrc/{ => ops}/ps_roi_pool.cpp (87%) rename torchvision/csrc/{ => ops}/ps_roi_pool.h (93%) rename torchvision/csrc/{ => ops}/roi_align.cpp (88%) rename torchvision/csrc/{ => ops}/roi_align.h (93%) rename torchvision/csrc/{ => ops}/roi_pool.cpp (87%) rename torchvision/csrc/{ => ops}/roi_pool.h (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6b97786888..329feb6c6d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,19 +28,6 @@ function(CUDA_CONVERT_FLAGS EXISTING_TARGET) endif() endfunction() -file(GLOB HEADERS torchvision/csrc/*.h) -# Image extension -file(GLOB IMAGE_HEADERS torchvision/csrc/cpu/image/*.h) -file(GLOB IMAGE_SOURCES torchvision/csrc/cpu/image/*.cpp) -file(GLOB OPERATOR_HEADERS torchvision/csrc/cpu/*.h) -file(GLOB OPERATOR_SOURCES ${OPERATOR_HEADERS} torchvision/csrc/cpu/*.cpp ${IMAGE_HEADERS} ${IMAGE_SOURCES} ${HEADERS} torchvision/csrc/*.cpp) -if(WITH_CUDA) - file(GLOB OPERATOR_HEADERS ${OPERATOR_HEADERS} torchvision/csrc/cuda/*.h) - file(GLOB OPERATOR_SOURCES ${OPERATOR_SOURCES} ${OPERATOR_HEADERS} torchvision/csrc/cuda/*.cu) -endif() -file(GLOB MODELS_HEADERS torchvision/csrc/models/*.h) -file(GLOB MODELS_SOURCES torchvision/csrc/models/*.h torchvision/csrc/models/*.cpp) - if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819") if(WITH_CUDA) @@ -64,7 +51,17 @@ endif() include(GNUInstallDirs) include(CMakePackageConfigHelpers) -add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES} ${IMAGE_SOURCES}) +set(TVCPP torchvision/csrc) +list(APPEND ALLOW_LISTED ${TVCPP} ${TVCPP}/io/image ${TVCPP}/io/image/cpu ${TVCPP}/models ${TVCPP}/ops ${TVCPP}/ops/cpu) +if(WITH_CUDA) + list(APPEND ALLOW_LISTED ${TVCPP}/ops/cuda ${TVCPP}/ops/autocast) +endif() + +FOREACH(DIR ${ALLOW_LISTED}) + file(GLOB ALL_SOURCES ${ALL_SOURCES} ${DIR}/*.*) +ENDFOREACH() + +add_library(${PROJECT_NAME} SHARED ${ALL_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} ${JPEG_LIBRARIES} Python3::Python) set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchVision @@ -95,13 +92,8 @@ install(EXPORT TorchVisionTargets NAMESPACE TorchVision:: DESTINATION ${TORCHVISION_CMAKECONFIG_INSTALL_DIR}) -install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) -install(FILES - ${OPERATOR_HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cpu) -if(WITH_CUDA) - install(FILES - ${OPERATOR_HEADERS} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cuda) -endif() -install(FILES ${MODELS_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/models) +FOREACH(INPUT_DIR ${ALLOW_LISTED}) + string(REPLACE "${TVCPP}" "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}" OUTPUT_DIR ${INPUT_DIR}) + file(GLOB INPUT_FILES ${INPUT_DIR}/*.*) + install(FILES ${INPUT_FILES} DESTINATION ${OUTPUT_DIR}) +ENDFOREACH() diff --git a/examples/cpp/hello_world/main.cpp b/examples/cpp/hello_world/main.cpp index 445924dd0e3..3a75bdec6cb 100644 --- a/examples/cpp/hello_world/main.cpp +++ b/examples/cpp/hello_world/main.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include int main() diff --git a/setup.py b/setup.py index 0d94e3ffb35..23cc53268c4 100644 --- a/setup.py +++ b/setup.py @@ -134,8 +134,9 @@ def get_extensions(): this_dir = os.path.dirname(os.path.abspath(__file__)) extensions_dir = os.path.join(this_dir, 'torchvision', 'csrc') - main_file = glob.glob(os.path.join(extensions_dir, '*.cpp')) - source_cpu = glob.glob(os.path.join(extensions_dir, 'cpu', '*.cpp')) + main_file = glob.glob(os.path.join(extensions_dir, '*.cpp')) + glob.glob(os.path.join(extensions_dir, 'ops', + '*.cpp')) + source_cpu = glob.glob(os.path.join(extensions_dir, 'ops', 'cpu', '*.cpp')) is_rocm_pytorch = False if torch.__version__ >= '1.5': @@ -146,17 +147,19 @@ def get_extensions(): hipify_python.hipify( project_directory=this_dir, output_directory=this_dir, - includes="torchvision/csrc/cuda/*", + includes="torchvision/csrc/ops/cuda/*", show_detailed=True, is_pytorch_extension=True, ) - source_cuda = glob.glob(os.path.join(extensions_dir, 'hip', '*.hip')) + source_cuda = glob.glob(os.path.join(extensions_dir, 'ops', 'hip', '*.hip')) # Copy over additional files - for file in glob.glob(r"torchvision/csrc/cuda/*.h"): - shutil.copy(file, "torchvision/csrc/hip") + for file in glob.glob(r"torchvision/csrc/ops/cuda/*.h"): + shutil.copy(file, "torchvision/csrc/ops/hip") else: - source_cuda = glob.glob(os.path.join(extensions_dir, 'cuda', '*.cu')) + source_cuda = glob.glob(os.path.join(extensions_dir, 'ops', 'cuda', '*.cu')) + + source_cuda += glob.glob(os.path.join(extensions_dir, 'ops', 'autocast', '*.cpp')) sources = main_file + source_cpu extension = CppExtension @@ -309,8 +312,8 @@ def get_extensions(): image_library += [jpeg_lib] image_include += [jpeg_include] - image_path = os.path.join(extensions_dir, 'cpu', 'image') - image_src = glob.glob(os.path.join(image_path, '*.cpp')) + image_path = os.path.join(extensions_dir, 'io', 'image') + image_src = glob.glob(os.path.join(image_path, '*.cpp')) + glob.glob(os.path.join(image_path, 'cpu', '*.cpp')) if png_found or jpeg_found: ext_modules.append(extension( @@ -377,13 +380,13 @@ def get_extensions(): print("ffmpeg library_dir: {}".format(ffmpeg_library_dir)) # TorchVision base decoder + video reader - video_reader_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'cpu', 'video_reader') + video_reader_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'io', 'video_reader') video_reader_src = glob.glob(os.path.join(video_reader_src_dir, "*.cpp")) - base_decoder_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'cpu', 'decoder') + base_decoder_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'io', 'decoder') base_decoder_src = glob.glob( os.path.join(base_decoder_src_dir, "*.cpp")) # Torchvision video API - videoapi_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'cpu', 'video') + videoapi_src_dir = os.path.join(this_dir, 'torchvision', 'csrc', 'io', 'video') videoapi_src = glob.glob(os.path.join(videoapi_src_dir, "*.cpp")) # exclude tests base_decoder_src = [x for x in base_decoder_src if '_test.cpp' not in x] diff --git a/test/tracing/frcnn/test_frcnn_tracing.cpp b/test/tracing/frcnn/test_frcnn_tracing.cpp index bd98c7866d8..8fef0519089 100644 --- a/test/tracing/frcnn/test_frcnn_tracing.cpp +++ b/test/tracing/frcnn/test_frcnn_tracing.cpp @@ -1,8 +1,7 @@ -#include #include #include -#include -#include +#include +#include #ifdef _WIN32 // Windows only diff --git a/torchvision/csrc/cpu/image/image.h b/torchvision/csrc/cpu/image/image.h deleted file mode 100644 index 3a652bef244..00000000000 --- a/torchvision/csrc/cpu/image/image.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -// Comment -#include -#include -#include "read_image_cpu.h" -#include "read_write_file_cpu.h" -#include "readjpeg_cpu.h" -#include "readpng_cpu.h" -#include "writejpeg_cpu.h" -#include "writepng_cpu.h" diff --git a/torchvision/csrc/cpu/decoder/audio_sampler.cpp b/torchvision/csrc/io/decoder/audio_sampler.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/audio_sampler.cpp rename to torchvision/csrc/io/decoder/audio_sampler.cpp diff --git a/torchvision/csrc/cpu/decoder/audio_sampler.h b/torchvision/csrc/io/decoder/audio_sampler.h similarity index 100% rename from torchvision/csrc/cpu/decoder/audio_sampler.h rename to torchvision/csrc/io/decoder/audio_sampler.h diff --git a/torchvision/csrc/cpu/decoder/audio_stream.cpp b/torchvision/csrc/io/decoder/audio_stream.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/audio_stream.cpp rename to torchvision/csrc/io/decoder/audio_stream.cpp diff --git a/torchvision/csrc/cpu/decoder/audio_stream.h b/torchvision/csrc/io/decoder/audio_stream.h similarity index 100% rename from torchvision/csrc/cpu/decoder/audio_stream.h rename to torchvision/csrc/io/decoder/audio_stream.h diff --git a/torchvision/csrc/cpu/decoder/cc_stream.cpp b/torchvision/csrc/io/decoder/cc_stream.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/cc_stream.cpp rename to torchvision/csrc/io/decoder/cc_stream.cpp diff --git a/torchvision/csrc/cpu/decoder/cc_stream.h b/torchvision/csrc/io/decoder/cc_stream.h similarity index 100% rename from torchvision/csrc/cpu/decoder/cc_stream.h rename to torchvision/csrc/io/decoder/cc_stream.h diff --git a/torchvision/csrc/cpu/decoder/decoder.cpp b/torchvision/csrc/io/decoder/decoder.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/decoder.cpp rename to torchvision/csrc/io/decoder/decoder.cpp diff --git a/torchvision/csrc/cpu/decoder/decoder.h b/torchvision/csrc/io/decoder/decoder.h similarity index 100% rename from torchvision/csrc/cpu/decoder/decoder.h rename to torchvision/csrc/io/decoder/decoder.h diff --git a/torchvision/csrc/cpu/decoder/defs.h b/torchvision/csrc/io/decoder/defs.h similarity index 100% rename from torchvision/csrc/cpu/decoder/defs.h rename to torchvision/csrc/io/decoder/defs.h diff --git a/torchvision/csrc/cpu/decoder/memory_buffer.cpp b/torchvision/csrc/io/decoder/memory_buffer.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/memory_buffer.cpp rename to torchvision/csrc/io/decoder/memory_buffer.cpp diff --git a/torchvision/csrc/cpu/decoder/memory_buffer.h b/torchvision/csrc/io/decoder/memory_buffer.h similarity index 100% rename from torchvision/csrc/cpu/decoder/memory_buffer.h rename to torchvision/csrc/io/decoder/memory_buffer.h diff --git a/torchvision/csrc/cpu/decoder/seekable_buffer.cpp b/torchvision/csrc/io/decoder/seekable_buffer.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/seekable_buffer.cpp rename to torchvision/csrc/io/decoder/seekable_buffer.cpp diff --git a/torchvision/csrc/cpu/decoder/seekable_buffer.h b/torchvision/csrc/io/decoder/seekable_buffer.h similarity index 100% rename from torchvision/csrc/cpu/decoder/seekable_buffer.h rename to torchvision/csrc/io/decoder/seekable_buffer.h diff --git a/torchvision/csrc/cpu/decoder/stream.cpp b/torchvision/csrc/io/decoder/stream.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/stream.cpp rename to torchvision/csrc/io/decoder/stream.cpp diff --git a/torchvision/csrc/cpu/decoder/stream.h b/torchvision/csrc/io/decoder/stream.h similarity index 100% rename from torchvision/csrc/cpu/decoder/stream.h rename to torchvision/csrc/io/decoder/stream.h diff --git a/torchvision/csrc/cpu/decoder/subtitle_sampler.cpp b/torchvision/csrc/io/decoder/subtitle_sampler.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/subtitle_sampler.cpp rename to torchvision/csrc/io/decoder/subtitle_sampler.cpp diff --git a/torchvision/csrc/cpu/decoder/subtitle_sampler.h b/torchvision/csrc/io/decoder/subtitle_sampler.h similarity index 100% rename from torchvision/csrc/cpu/decoder/subtitle_sampler.h rename to torchvision/csrc/io/decoder/subtitle_sampler.h diff --git a/torchvision/csrc/cpu/decoder/subtitle_stream.cpp b/torchvision/csrc/io/decoder/subtitle_stream.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/subtitle_stream.cpp rename to torchvision/csrc/io/decoder/subtitle_stream.cpp diff --git a/torchvision/csrc/cpu/decoder/subtitle_stream.h b/torchvision/csrc/io/decoder/subtitle_stream.h similarity index 100% rename from torchvision/csrc/cpu/decoder/subtitle_stream.h rename to torchvision/csrc/io/decoder/subtitle_stream.h diff --git a/torchvision/csrc/cpu/decoder/sync_decoder.cpp b/torchvision/csrc/io/decoder/sync_decoder.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/sync_decoder.cpp rename to torchvision/csrc/io/decoder/sync_decoder.cpp diff --git a/torchvision/csrc/cpu/decoder/sync_decoder.h b/torchvision/csrc/io/decoder/sync_decoder.h similarity index 100% rename from torchvision/csrc/cpu/decoder/sync_decoder.h rename to torchvision/csrc/io/decoder/sync_decoder.h diff --git a/torchvision/csrc/cpu/decoder/sync_decoder_test.cpp b/torchvision/csrc/io/decoder/sync_decoder_test.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/sync_decoder_test.cpp rename to torchvision/csrc/io/decoder/sync_decoder_test.cpp diff --git a/torchvision/csrc/cpu/decoder/time_keeper.cpp b/torchvision/csrc/io/decoder/time_keeper.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/time_keeper.cpp rename to torchvision/csrc/io/decoder/time_keeper.cpp diff --git a/torchvision/csrc/cpu/decoder/time_keeper.h b/torchvision/csrc/io/decoder/time_keeper.h similarity index 100% rename from torchvision/csrc/cpu/decoder/time_keeper.h rename to torchvision/csrc/io/decoder/time_keeper.h diff --git a/torchvision/csrc/cpu/decoder/util.cpp b/torchvision/csrc/io/decoder/util.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/util.cpp rename to torchvision/csrc/io/decoder/util.cpp diff --git a/torchvision/csrc/cpu/decoder/util.h b/torchvision/csrc/io/decoder/util.h similarity index 100% rename from torchvision/csrc/cpu/decoder/util.h rename to torchvision/csrc/io/decoder/util.h diff --git a/torchvision/csrc/cpu/decoder/util_test.cpp b/torchvision/csrc/io/decoder/util_test.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/util_test.cpp rename to torchvision/csrc/io/decoder/util_test.cpp diff --git a/torchvision/csrc/cpu/decoder/video_sampler.cpp b/torchvision/csrc/io/decoder/video_sampler.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/video_sampler.cpp rename to torchvision/csrc/io/decoder/video_sampler.cpp diff --git a/torchvision/csrc/cpu/decoder/video_sampler.h b/torchvision/csrc/io/decoder/video_sampler.h similarity index 100% rename from torchvision/csrc/cpu/decoder/video_sampler.h rename to torchvision/csrc/io/decoder/video_sampler.h diff --git a/torchvision/csrc/cpu/decoder/video_stream.cpp b/torchvision/csrc/io/decoder/video_stream.cpp similarity index 100% rename from torchvision/csrc/cpu/decoder/video_stream.cpp rename to torchvision/csrc/io/decoder/video_stream.cpp diff --git a/torchvision/csrc/cpu/decoder/video_stream.h b/torchvision/csrc/io/decoder/video_stream.h similarity index 100% rename from torchvision/csrc/cpu/decoder/video_stream.h rename to torchvision/csrc/io/decoder/video_stream.h diff --git a/torchvision/csrc/cpu/image/read_image_cpu.cpp b/torchvision/csrc/io/image/cpu/read_image_cpu.cpp similarity index 99% rename from torchvision/csrc/cpu/image/read_image_cpu.cpp rename to torchvision/csrc/io/image/cpu/read_image_cpu.cpp index 6039b870f31..d4c2bf0fdea 100644 --- a/torchvision/csrc/cpu/image/read_image_cpu.cpp +++ b/torchvision/csrc/io/image/cpu/read_image_cpu.cpp @@ -1,4 +1,5 @@ #include "read_image_cpu.h" + #include "readjpeg_cpu.h" #include "readpng_cpu.h" diff --git a/torchvision/csrc/cpu/image/read_image_cpu.h b/torchvision/csrc/io/image/cpu/read_image_cpu.h similarity index 70% rename from torchvision/csrc/cpu/image/read_image_cpu.h rename to torchvision/csrc/io/image/cpu/read_image_cpu.h index 6186d0d0d98..199c17ea481 100644 --- a/torchvision/csrc/cpu/image/read_image_cpu.h +++ b/torchvision/csrc/io/image/cpu/read_image_cpu.h @@ -1,7 +1,7 @@ #pragma once -#include -#include "image_read_mode.h" +#include +#include "../image_read_mode.h" C10_EXPORT torch::Tensor decode_image( const torch::Tensor& data, diff --git a/torchvision/csrc/cpu/image/read_write_file_cpu.cpp b/torchvision/csrc/io/image/cpu/read_write_file_cpu.cpp similarity index 100% rename from torchvision/csrc/cpu/image/read_write_file_cpu.cpp rename to torchvision/csrc/io/image/cpu/read_write_file_cpu.cpp diff --git a/torchvision/csrc/cpu/image/read_write_file_cpu.h b/torchvision/csrc/io/image/cpu/read_write_file_cpu.h similarity index 80% rename from torchvision/csrc/cpu/image/read_write_file_cpu.h rename to torchvision/csrc/io/image/cpu/read_write_file_cpu.h index 084f5c105f8..e0459f4d090 100644 --- a/torchvision/csrc/cpu/image/read_write_file_cpu.h +++ b/torchvision/csrc/io/image/cpu/read_write_file_cpu.h @@ -1,8 +1,7 @@ #pragma once -#include #include -#include +#include C10_EXPORT torch::Tensor read_file(const std::string& filename); diff --git a/torchvision/csrc/cpu/image/readjpeg_cpu.cpp b/torchvision/csrc/io/image/cpu/readjpeg_cpu.cpp similarity index 98% rename from torchvision/csrc/cpu/image/readjpeg_cpu.cpp rename to torchvision/csrc/io/image/cpu/readjpeg_cpu.cpp index 58584612697..7f1a411bc3d 100644 --- a/torchvision/csrc/cpu/image/readjpeg_cpu.cpp +++ b/torchvision/csrc/io/image/cpu/readjpeg_cpu.cpp @@ -1,16 +1,12 @@ #include "readjpeg_cpu.h" -#include - #if !JPEG_FOUND torch::Tensor decodeJPEG(const torch::Tensor& data, ImageReadMode mode) { TORCH_CHECK( false, "decodeJPEG: torchvision not compiled with libjpeg support"); } #else -#include -#include -#include "jpegcommon.h" +#include "../jpegcommon.h" struct torch_jpeg_mgr { struct jpeg_source_mgr pub; diff --git a/torchvision/csrc/cpu/image/readjpeg_cpu.h b/torchvision/csrc/io/image/cpu/readjpeg_cpu.h similarity index 70% rename from torchvision/csrc/cpu/image/readjpeg_cpu.h rename to torchvision/csrc/io/image/cpu/readjpeg_cpu.h index f05d05a9064..e99bcd1e3e9 100644 --- a/torchvision/csrc/cpu/image/readjpeg_cpu.h +++ b/torchvision/csrc/io/image/cpu/readjpeg_cpu.h @@ -1,7 +1,7 @@ #pragma once -#include -#include "image_read_mode.h" +#include +#include "../image_read_mode.h" C10_EXPORT torch::Tensor decodeJPEG( const torch::Tensor& data, diff --git a/torchvision/csrc/cpu/image/readpng_cpu.cpp b/torchvision/csrc/io/image/cpu/readpng_cpu.cpp similarity index 99% rename from torchvision/csrc/cpu/image/readpng_cpu.cpp rename to torchvision/csrc/io/image/cpu/readpng_cpu.cpp index 7adc125b2e8..adbbe52e097 100644 --- a/torchvision/csrc/cpu/image/readpng_cpu.cpp +++ b/torchvision/csrc/io/image/cpu/readpng_cpu.cpp @@ -1,7 +1,5 @@ #include "readpng_cpu.h" -#include - #if !PNG_FOUND torch::Tensor decodePNG(const torch::Tensor& data, ImageReadMode mode) { TORCH_CHECK(false, "decodePNG: torchvision not compiled with libPNG support"); diff --git a/torchvision/csrc/cpu/image/readpng_cpu.h b/torchvision/csrc/io/image/cpu/readpng_cpu.h similarity index 70% rename from torchvision/csrc/cpu/image/readpng_cpu.h rename to torchvision/csrc/io/image/cpu/readpng_cpu.h index 9c74cb2c678..e62d5cc82e0 100644 --- a/torchvision/csrc/cpu/image/readpng_cpu.h +++ b/torchvision/csrc/io/image/cpu/readpng_cpu.h @@ -1,7 +1,7 @@ #pragma once -#include -#include "image_read_mode.h" +#include +#include "../image_read_mode.h" C10_EXPORT torch::Tensor decodePNG( const torch::Tensor& data, diff --git a/torchvision/csrc/cpu/image/writejpeg_cpu.cpp b/torchvision/csrc/io/image/cpu/writejpeg_cpu.cpp similarity index 97% rename from torchvision/csrc/cpu/image/writejpeg_cpu.cpp rename to torchvision/csrc/io/image/cpu/writejpeg_cpu.cpp index 658ffaba55c..2787b19c447 100644 --- a/torchvision/csrc/cpu/image/writejpeg_cpu.cpp +++ b/torchvision/csrc/io/image/cpu/writejpeg_cpu.cpp @@ -1,8 +1,5 @@ #include "writejpeg_cpu.h" -#include -#include - #if !JPEG_FOUND torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality) { @@ -11,9 +8,7 @@ torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality) { } #else - -#include -#include "jpegcommon.h" +#include "../jpegcommon.h" torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality) { // Define compression structures and error handling diff --git a/torchvision/csrc/cpu/image/writejpeg_cpu.h b/torchvision/csrc/io/image/cpu/writejpeg_cpu.h similarity index 79% rename from torchvision/csrc/cpu/image/writejpeg_cpu.h rename to torchvision/csrc/io/image/cpu/writejpeg_cpu.h index 7f984af9407..ad7d2561764 100644 --- a/torchvision/csrc/cpu/image/writejpeg_cpu.h +++ b/torchvision/csrc/io/image/cpu/writejpeg_cpu.h @@ -1,5 +1,5 @@ #pragma once -#include +#include C10_EXPORT torch::Tensor encodeJPEG(const torch::Tensor& data, int64_t quality); diff --git a/torchvision/csrc/cpu/image/writepng_cpu.cpp b/torchvision/csrc/io/image/cpu/writepng_cpu.cpp similarity index 99% rename from torchvision/csrc/cpu/image/writepng_cpu.cpp rename to torchvision/csrc/io/image/cpu/writepng_cpu.cpp index f599a9824e0..515d0b85dc2 100644 --- a/torchvision/csrc/cpu/image/writepng_cpu.cpp +++ b/torchvision/csrc/io/image/cpu/writepng_cpu.cpp @@ -1,8 +1,5 @@ #include "writejpeg_cpu.h" -#include -#include - #if !PNG_FOUND torch::Tensor encodePNG(const torch::Tensor& data, int64_t compression_level) { @@ -10,8 +7,8 @@ torch::Tensor encodePNG(const torch::Tensor& data, int64_t compression_level) { } #else - #include +#include struct torch_mem_encode { char* buffer; diff --git a/torchvision/csrc/cpu/image/writepng_cpu.h b/torchvision/csrc/io/image/cpu/writepng_cpu.h similarity index 82% rename from torchvision/csrc/cpu/image/writepng_cpu.h rename to torchvision/csrc/io/image/cpu/writepng_cpu.h index 8f477191cbe..68543cdcd94 100644 --- a/torchvision/csrc/cpu/image/writepng_cpu.h +++ b/torchvision/csrc/io/image/cpu/writepng_cpu.h @@ -1,6 +1,6 @@ #pragma once -#include +#include C10_EXPORT torch::Tensor encodePNG( const torch::Tensor& data, diff --git a/torchvision/csrc/cpu/image/image.cpp b/torchvision/csrc/io/image/image.cpp similarity index 97% rename from torchvision/csrc/cpu/image/image.cpp rename to torchvision/csrc/io/image/image.cpp index d9234aceb6e..fffdebaad76 100644 --- a/torchvision/csrc/cpu/image/image.cpp +++ b/torchvision/csrc/io/image/image.cpp @@ -1,6 +1,5 @@ - #include "image.h" -#include + #include // If we are in a Windows environment, we need to define diff --git a/torchvision/csrc/io/image/image.h b/torchvision/csrc/io/image/image.h new file mode 100644 index 00000000000..12b93ae27f9 --- /dev/null +++ b/torchvision/csrc/io/image/image.h @@ -0,0 +1,8 @@ +#pragma once + +#include "cpu/read_image_cpu.h" +#include "cpu/read_write_file_cpu.h" +#include "cpu/readjpeg_cpu.h" +#include "cpu/readpng_cpu.h" +#include "cpu/writejpeg_cpu.h" +#include "cpu/writepng_cpu.h" diff --git a/torchvision/csrc/cpu/image/image_read_mode.h b/torchvision/csrc/io/image/image_read_mode.h similarity index 100% rename from torchvision/csrc/cpu/image/image_read_mode.h rename to torchvision/csrc/io/image/image_read_mode.h diff --git a/torchvision/csrc/cpu/image/jpegcommon.cpp b/torchvision/csrc/io/image/jpegcommon.cpp similarity index 96% rename from torchvision/csrc/cpu/image/jpegcommon.cpp rename to torchvision/csrc/io/image/jpegcommon.cpp index 9ef7c2903d7..744e9cfd72a 100644 --- a/torchvision/csrc/cpu/image/jpegcommon.cpp +++ b/torchvision/csrc/io/image/jpegcommon.cpp @@ -1,7 +1,6 @@ +#if JPEG_FOUND #include "jpegcommon.h" -#include -#if JPEG_FOUND void torch_jpeg_error_exit(j_common_ptr cinfo) { /* cinfo->err really points to a torch_jpeg_error_mgr struct, so coerce * pointer */ diff --git a/torchvision/csrc/cpu/image/jpegcommon.h b/torchvision/csrc/io/image/jpegcommon.h similarity index 96% rename from torchvision/csrc/cpu/image/jpegcommon.h rename to torchvision/csrc/io/image/jpegcommon.h index c0f8eee0457..275b4a1e1e8 100644 --- a/torchvision/csrc/cpu/image/jpegcommon.h +++ b/torchvision/csrc/io/image/jpegcommon.h @@ -8,7 +8,6 @@ #if JPEG_FOUND #include #include -#include static const JOCTET EOI_BUFFER[1] = {JPEG_EOI}; struct torch_jpeg_error_mgr { diff --git a/torchvision/csrc/cpu/video/Video.cpp b/torchvision/csrc/io/video/Video.cpp similarity index 100% rename from torchvision/csrc/cpu/video/Video.cpp rename to torchvision/csrc/io/video/Video.cpp diff --git a/torchvision/csrc/cpu/video/Video.h b/torchvision/csrc/io/video/Video.h similarity index 100% rename from torchvision/csrc/cpu/video/Video.h rename to torchvision/csrc/io/video/Video.h diff --git a/torchvision/csrc/cpu/video/register.cpp b/torchvision/csrc/io/video/register.cpp similarity index 100% rename from torchvision/csrc/cpu/video/register.cpp rename to torchvision/csrc/io/video/register.cpp diff --git a/torchvision/csrc/cpu/video_reader/VideoReader.cpp b/torchvision/csrc/io/video_reader/VideoReader.cpp similarity index 100% rename from torchvision/csrc/cpu/video_reader/VideoReader.cpp rename to torchvision/csrc/io/video_reader/VideoReader.cpp diff --git a/torchvision/csrc/cpu/video_reader/VideoReader.h b/torchvision/csrc/io/video_reader/VideoReader.h similarity index 100% rename from torchvision/csrc/cpu/video_reader/VideoReader.h rename to torchvision/csrc/io/video_reader/VideoReader.h diff --git a/torchvision/csrc/models/alexnet.h b/torchvision/csrc/models/alexnet.h index d2529c88882..e584446d205 100644 --- a/torchvision/csrc/models/alexnet.h +++ b/torchvision/csrc/models/alexnet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/densenet.h b/torchvision/csrc/models/densenet.h index 9358631e4ba..d1d8f6645da 100644 --- a/torchvision/csrc/models/densenet.h +++ b/torchvision/csrc/models/densenet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/googlenet.cpp b/torchvision/csrc/models/googlenet.cpp index 14c12ebca5e..9e381b1628d 100644 --- a/torchvision/csrc/models/googlenet.cpp +++ b/torchvision/csrc/models/googlenet.cpp @@ -1,7 +1,5 @@ #include "googlenet.h" -#include "modelsimpl.h" - namespace vision { namespace models { diff --git a/torchvision/csrc/models/googlenet.h b/torchvision/csrc/models/googlenet.h index 3d4b3faf7e4..cb10a0b90b7 100644 --- a/torchvision/csrc/models/googlenet.h +++ b/torchvision/csrc/models/googlenet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/inception.h b/torchvision/csrc/models/inception.h index 08f329fbc1b..53ce07a703a 100644 --- a/torchvision/csrc/models/inception.h +++ b/torchvision/csrc/models/inception.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/mnasnet.h b/torchvision/csrc/models/mnasnet.h index e69559b2dd7..f08b5cf4284 100644 --- a/torchvision/csrc/models/mnasnet.h +++ b/torchvision/csrc/models/mnasnet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/mobilenet.h b/torchvision/csrc/models/mobilenet.h index 63d26474b23..0d1b8f1d0c9 100644 --- a/torchvision/csrc/models/mobilenet.h +++ b/torchvision/csrc/models/mobilenet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/modelsimpl.h b/torchvision/csrc/models/modelsimpl.h index 8f7663b32ad..f159d1502a3 100644 --- a/torchvision/csrc/models/modelsimpl.h +++ b/torchvision/csrc/models/modelsimpl.h @@ -1,10 +1,6 @@ #pragma once -#include - -#ifndef TORCH_CHECK -#define TORCH_CHECK AT_CHECK -#endif +#include namespace vision { namespace models { diff --git a/torchvision/csrc/models/resnet.cpp b/torchvision/csrc/models/resnet.cpp index fe8059a15ec..e97ba767745 100644 --- a/torchvision/csrc/models/resnet.cpp +++ b/torchvision/csrc/models/resnet.cpp @@ -1,7 +1,5 @@ #include "resnet.h" -#include "modelsimpl.h" - namespace vision { namespace models { namespace _resnetimpl { diff --git a/torchvision/csrc/models/resnet.h b/torchvision/csrc/models/resnet.h index b8caf4332c6..7e41de6e072 100644 --- a/torchvision/csrc/models/resnet.h +++ b/torchvision/csrc/models/resnet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/shufflenetv2.h b/torchvision/csrc/models/shufflenetv2.h index ea8524c72fa..00a73b36a06 100644 --- a/torchvision/csrc/models/shufflenetv2.h +++ b/torchvision/csrc/models/shufflenetv2.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/squeezenet.h b/torchvision/csrc/models/squeezenet.h index c43d2b07f13..37bc5825717 100644 --- a/torchvision/csrc/models/squeezenet.h +++ b/torchvision/csrc/models/squeezenet.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/models/vgg.h b/torchvision/csrc/models/vgg.h index 4a540bea822..dd5b30512c9 100644 --- a/torchvision/csrc/models/vgg.h +++ b/torchvision/csrc/models/vgg.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "../macros.h" namespace vision { diff --git a/torchvision/csrc/ops/autocast/deform_conv2d_kernel.cpp b/torchvision/csrc/ops/autocast/deform_conv2d_kernel.cpp new file mode 100644 index 00000000000..f86e3d31057 --- /dev/null +++ b/torchvision/csrc/ops/autocast/deform_conv2d_kernel.cpp @@ -0,0 +1,52 @@ +#include "../deform_conv2d.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +at::Tensor deform_conv2d_autocast( + const at::Tensor& input, + const at::Tensor& weight, + const at::Tensor& offset, + const at::Tensor& mask, + const at::Tensor& bias, + int64_t stride_h, + int64_t stride_w, + int64_t pad_h, + int64_t pad_w, + int64_t dilation_h, + int64_t dilation_w, + int64_t groups, + int64_t offset_groups, + bool use_mask) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + return deform_conv2d( + at::autocast::cached_cast(at::kFloat, input), + at::autocast::cached_cast(at::kFloat, weight), + at::autocast::cached_cast(at::kFloat, offset), + at::autocast::cached_cast(at::kFloat, mask), + at::autocast::cached_cast(at::kFloat, bias), + stride_h, + stride_w, + pad_h, + pad_w, + dilation_h, + dilation_w, + groups, + offset_groups, + use_mask) + .to(input.scalar_type()); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("deform_conv2d", deform_conv2d_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/ops/autocast/nms_kernel.cpp b/torchvision/csrc/ops/autocast/nms_kernel.cpp new file mode 100644 index 00000000000..33cd9f1077e --- /dev/null +++ b/torchvision/csrc/ops/autocast/nms_kernel.cpp @@ -0,0 +1,29 @@ +#include "../nms.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +at::Tensor nms_autocast( + const at::Tensor& dets, + const at::Tensor& scores, + double iou_threshold) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + return nms( + at::autocast::cached_cast(at::kFloat, dets), + at::autocast::cached_cast(at::kFloat, scores), + iou_threshold); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("nms", nms_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/ops/autocast/ps_roi_align_kernel.cpp b/torchvision/csrc/ops/autocast/ps_roi_align_kernel.cpp new file mode 100644 index 00000000000..b59417da544 --- /dev/null +++ b/torchvision/csrc/ops/autocast/ps_roi_align_kernel.cpp @@ -0,0 +1,39 @@ +#include "../ps_roi_align.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +std::tuple ps_roi_align_autocast( + const at::Tensor& input, + const at::Tensor& rois, + double spatial_scale, + int64_t pooled_height, + int64_t pooled_width, + int64_t sampling_ratio) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + auto result = ps_roi_align( + at::autocast::cached_cast(at::kFloat, input), + at::autocast::cached_cast(at::kFloat, rois), + spatial_scale, + pooled_height, + pooled_width, + sampling_ratio); + + return std::make_tuple( + std::get<0>(result).to(input.scalar_type()), + std::get<1>(result).to(input.scalar_type())); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("ps_roi_align", ps_roi_align_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/ops/autocast/ps_roi_pool_kernel.cpp b/torchvision/csrc/ops/autocast/ps_roi_pool_kernel.cpp new file mode 100644 index 00000000000..026a53a49da --- /dev/null +++ b/torchvision/csrc/ops/autocast/ps_roi_pool_kernel.cpp @@ -0,0 +1,37 @@ +#include "../ps_roi_pool.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +std::tuple ps_roi_pool_autocast( + const at::Tensor& input, + const at::Tensor& rois, + double spatial_scale, + int64_t pooled_height, + int64_t pooled_width) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + auto result = ps_roi_pool( + at::autocast::cached_cast(at::kFloat, input), + at::autocast::cached_cast(at::kFloat, rois), + spatial_scale, + pooled_height, + pooled_width); + + return std::make_tuple( + std::get<0>(result).to(input.scalar_type()), + std::get<1>(result).to(input.scalar_type())); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("ps_roi_pool", ps_roi_pool_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/ops/autocast/roi_align_kernel.cpp b/torchvision/csrc/ops/autocast/roi_align_kernel.cpp new file mode 100644 index 00000000000..313753d9a3f --- /dev/null +++ b/torchvision/csrc/ops/autocast/roi_align_kernel.cpp @@ -0,0 +1,38 @@ +#include "../roi_align.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +at::Tensor roi_align_autocast( + const at::Tensor& input, + const at::Tensor& rois, + double spatial_scale, + int64_t pooled_height, + int64_t pooled_width, + int64_t sampling_ratio, + bool aligned) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + return roi_align( + at::autocast::cached_cast(at::kFloat, input), + at::autocast::cached_cast(at::kFloat, rois), + spatial_scale, + pooled_height, + pooled_width, + sampling_ratio, + aligned) + .to(input.scalar_type()); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("roi_align", roi_align_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/ops/autocast/roi_pool_kernel.cpp b/torchvision/csrc/ops/autocast/roi_pool_kernel.cpp new file mode 100644 index 00000000000..4f9cf6bdfc9 --- /dev/null +++ b/torchvision/csrc/ops/autocast/roi_pool_kernel.cpp @@ -0,0 +1,37 @@ +#include "../roi_pool.h" + +#include +#include + +namespace vision { +namespace ops { + +namespace { + +std::tuple roi_pool_autocast( + const at::Tensor& input, + const at::Tensor& rois, + double spatial_scale, + int64_t pooled_height, + int64_t pooled_width) { + c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); + auto result = roi_pool( + at::autocast::cached_cast(at::kFloat, input), + at::autocast::cached_cast(at::kFloat, rois), + spatial_scale, + pooled_height, + pooled_width); + + return std::make_tuple( + std::get<0>(result).to(input.scalar_type()), + std::get<1>(result).to(input.scalar_type())); +} + +} // namespace + +TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { + m.impl("roi_pool", roi_pool_autocast); +} + +} // namespace ops +} // namespace vision diff --git a/torchvision/csrc/cpu/deform_conv2d_kernel.cpp b/torchvision/csrc/ops/cpu/deform_conv2d_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/deform_conv2d_kernel.cpp rename to torchvision/csrc/ops/cpu/deform_conv2d_kernel.cpp diff --git a/torchvision/csrc/cpu/nms_kernel.cpp b/torchvision/csrc/ops/cpu/nms_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/nms_kernel.cpp rename to torchvision/csrc/ops/cpu/nms_kernel.cpp diff --git a/torchvision/csrc/cpu/ps_roi_align_kernel.cpp b/torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/ps_roi_align_kernel.cpp rename to torchvision/csrc/ops/cpu/ps_roi_align_kernel.cpp diff --git a/torchvision/csrc/cpu/ps_roi_pool_kernel.cpp b/torchvision/csrc/ops/cpu/ps_roi_pool_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/ps_roi_pool_kernel.cpp rename to torchvision/csrc/ops/cpu/ps_roi_pool_kernel.cpp diff --git a/torchvision/csrc/cpu/roi_align_kernel.cpp b/torchvision/csrc/ops/cpu/roi_align_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/roi_align_kernel.cpp rename to torchvision/csrc/ops/cpu/roi_align_kernel.cpp diff --git a/torchvision/csrc/cpu/roi_pool_kernel.cpp b/torchvision/csrc/ops/cpu/roi_pool_kernel.cpp similarity index 100% rename from torchvision/csrc/cpu/roi_pool_kernel.cpp rename to torchvision/csrc/ops/cpu/roi_pool_kernel.cpp diff --git a/torchvision/csrc/cuda/cuda_helpers.h b/torchvision/csrc/ops/cuda/cuda_helpers.h similarity index 100% rename from torchvision/csrc/cuda/cuda_helpers.h rename to torchvision/csrc/ops/cuda/cuda_helpers.h diff --git a/torchvision/csrc/cuda/deform_conv2d_kernel.cu b/torchvision/csrc/ops/cuda/deform_conv2d_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/deform_conv2d_kernel.cu rename to torchvision/csrc/ops/cuda/deform_conv2d_kernel.cu diff --git a/torchvision/csrc/cuda/nms_kernel.cu b/torchvision/csrc/ops/cuda/nms_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/nms_kernel.cu rename to torchvision/csrc/ops/cuda/nms_kernel.cu diff --git a/torchvision/csrc/cuda/ps_roi_align_kernel.cu b/torchvision/csrc/ops/cuda/ps_roi_align_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/ps_roi_align_kernel.cu rename to torchvision/csrc/ops/cuda/ps_roi_align_kernel.cu diff --git a/torchvision/csrc/cuda/ps_roi_pool_kernel.cu b/torchvision/csrc/ops/cuda/ps_roi_pool_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/ps_roi_pool_kernel.cu rename to torchvision/csrc/ops/cuda/ps_roi_pool_kernel.cu diff --git a/torchvision/csrc/cuda/roi_align_kernel.cu b/torchvision/csrc/ops/cuda/roi_align_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/roi_align_kernel.cu rename to torchvision/csrc/ops/cuda/roi_align_kernel.cu diff --git a/torchvision/csrc/cuda/roi_pool_kernel.cu b/torchvision/csrc/ops/cuda/roi_pool_kernel.cu similarity index 100% rename from torchvision/csrc/cuda/roi_pool_kernel.cu rename to torchvision/csrc/ops/cuda/roi_pool_kernel.cu diff --git a/torchvision/csrc/deform_conv2d.cpp b/torchvision/csrc/ops/deform_conv2d.cpp similarity index 87% rename from torchvision/csrc/deform_conv2d.cpp rename to torchvision/csrc/ops/deform_conv2d.cpp index 512c4e02584..4b8b2e97668 100644 --- a/torchvision/csrc/deform_conv2d.cpp +++ b/torchvision/csrc/ops/deform_conv2d.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -45,46 +41,6 @@ at::Tensor deform_conv2d( use_mask); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -at::Tensor deform_conv2d_autocast( - const at::Tensor& input, - const at::Tensor& weight, - const at::Tensor& offset, - const at::Tensor& mask, - const at::Tensor& bias, - int64_t stride_h, - int64_t stride_w, - int64_t pad_h, - int64_t pad_w, - int64_t dilation_h, - int64_t dilation_w, - int64_t groups, - int64_t offset_groups, - bool use_mask) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - return deform_conv2d( - at::autocast::cached_cast(at::kFloat, input), - at::autocast::cached_cast(at::kFloat, weight), - at::autocast::cached_cast(at::kFloat, offset), - at::autocast::cached_cast(at::kFloat, mask), - at::autocast::cached_cast(at::kFloat, bias), - stride_h, - stride_w, - pad_h, - pad_w, - dilation_h, - dilation_w, - groups, - offset_groups, - use_mask) - .to(input.scalar_type()); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("deform_conv2d", deform_conv2d_autocast); -} -#endif - std::tuple _deform_conv2d_backward( const at::Tensor& grad, @@ -307,8 +263,6 @@ class DeformConv2dBackwardFunction } }; -} // namespace - at::Tensor deform_conv2d_autograd( const at::Tensor& input, const at::Tensor& weight, @@ -378,6 +332,8 @@ deform_conv2d_backward_autograd( return std::make_tuple(result[0], result[1], result[2], result[3], result[4]); } +} // namespace + TORCH_LIBRARY_IMPL(torchvision, Autograd, m) { m.impl("deform_conv2d", deform_conv2d_autograd); m.impl("_deform_conv2d_backward", deform_conv2d_backward_autograd); diff --git a/torchvision/csrc/deform_conv2d.h b/torchvision/csrc/ops/deform_conv2d.h similarity index 95% rename from torchvision/csrc/deform_conv2d.h rename to torchvision/csrc/ops/deform_conv2d.h index 3f65036a9b1..e94636fb280 100644 --- a/torchvision/csrc/deform_conv2d.h +++ b/torchvision/csrc/ops/deform_conv2d.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/new_empty_tensor_op.cpp b/torchvision/csrc/ops/new_empty_tensor_op.cpp similarity index 100% rename from torchvision/csrc/new_empty_tensor_op.cpp rename to torchvision/csrc/ops/new_empty_tensor_op.cpp diff --git a/torchvision/csrc/new_empty_tensor_op.h b/torchvision/csrc/ops/new_empty_tensor_op.h similarity index 90% rename from torchvision/csrc/new_empty_tensor_op.h rename to torchvision/csrc/ops/new_empty_tensor_op.h index f1435517cba..6f22cfecda9 100644 --- a/torchvision/csrc/new_empty_tensor_op.h +++ b/torchvision/csrc/ops/new_empty_tensor_op.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/nms.cpp b/torchvision/csrc/ops/nms.cpp similarity index 51% rename from torchvision/csrc/nms.cpp rename to torchvision/csrc/ops/nms.cpp index 74e0dbf82ef..3655a8d00df 100644 --- a/torchvision/csrc/nms.cpp +++ b/torchvision/csrc/ops/nms.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -20,23 +16,6 @@ at::Tensor nms( return op.call(dets, scores, iou_threshold); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -at::Tensor nms_autocast( - const at::Tensor& dets, - const at::Tensor& scores, - double iou_threshold) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - return nms( - at::autocast::cached_cast(at::kFloat, dets), - at::autocast::cached_cast(at::kFloat, scores), - iou_threshold); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("nms", nms_autocast); -} -#endif - TORCH_LIBRARY_FRAGMENT(torchvision, m) { m.def("nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor"); } diff --git a/torchvision/csrc/nms.h b/torchvision/csrc/ops/nms.h similarity index 90% rename from torchvision/csrc/nms.h rename to torchvision/csrc/ops/nms.h index efe50acc136..8c75a242bff 100644 --- a/torchvision/csrc/nms.h +++ b/torchvision/csrc/ops/nms.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/ps_roi_align.cpp b/torchvision/csrc/ops/ps_roi_align.cpp similarity index 87% rename from torchvision/csrc/ps_roi_align.cpp rename to torchvision/csrc/ops/ps_roi_align.cpp index b684431f567..6092ee4cb68 100644 --- a/torchvision/csrc/ps_roi_align.cpp +++ b/torchvision/csrc/ops/ps_roi_align.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -24,33 +20,6 @@ std::tuple ps_roi_align( input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -std::tuple ps_roi_align_autocast( - const at::Tensor& input, - const at::Tensor& rois, - double spatial_scale, - int64_t pooled_height, - int64_t pooled_width, - int64_t sampling_ratio) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - auto result = ps_roi_align( - at::autocast::cached_cast(at::kFloat, input), - at::autocast::cached_cast(at::kFloat, rois), - spatial_scale, - pooled_height, - pooled_width, - sampling_ratio); - - return std::make_tuple( - std::get<0>(result).to(input.scalar_type()), - std::get<1>(result).to(input.scalar_type())); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("ps_roi_align", ps_roi_align_autocast); -} -#endif - at::Tensor _ps_roi_align_backward( const at::Tensor& grad, const at::Tensor& rois, @@ -194,8 +163,6 @@ class PSROIAlignBackwardFunction } }; -} // namespace - std::tuple ps_roi_align_autograd( const at::Tensor& input, const at::Tensor& rois, @@ -235,6 +202,8 @@ at::Tensor ps_roi_align_backward_autograd( width)[0]; } +} // namespace + TORCH_LIBRARY_IMPL(torchvision, Autograd, m) { m.impl("ps_roi_align", ps_roi_align_autograd); m.impl("_ps_roi_align_backward", ps_roi_align_backward_autograd); diff --git a/torchvision/csrc/ps_roi_align.h b/torchvision/csrc/ops/ps_roi_align.h similarity index 93% rename from torchvision/csrc/ps_roi_align.h rename to torchvision/csrc/ops/ps_roi_align.h index b04359b70ed..cee53455f0c 100644 --- a/torchvision/csrc/ps_roi_align.h +++ b/torchvision/csrc/ops/ps_roi_align.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/ps_roi_pool.cpp b/torchvision/csrc/ops/ps_roi_pool.cpp similarity index 87% rename from torchvision/csrc/ps_roi_pool.cpp rename to torchvision/csrc/ops/ps_roi_pool.cpp index 99d72771750..2c87d0c4fe8 100644 --- a/torchvision/csrc/ps_roi_pool.cpp +++ b/torchvision/csrc/ops/ps_roi_pool.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -22,31 +18,6 @@ std::tuple ps_roi_pool( return op.call(input, rois, spatial_scale, pooled_height, pooled_width); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -std::tuple ps_roi_pool_autocast( - const at::Tensor& input, - const at::Tensor& rois, - double spatial_scale, - int64_t pooled_height, - int64_t pooled_width) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - auto result = ps_roi_pool( - at::autocast::cached_cast(at::kFloat, input), - at::autocast::cached_cast(at::kFloat, rois), - spatial_scale, - pooled_height, - pooled_width); - - return std::make_tuple( - std::get<0>(result).to(input.scalar_type()), - std::get<1>(result).to(input.scalar_type())); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("ps_roi_pool", ps_roi_pool_autocast); -} -#endif - at::Tensor _ps_roi_pool_backward( const at::Tensor& grad, const at::Tensor& rois, @@ -176,8 +147,6 @@ class PSROIPoolBackwardFunction } }; -} // namespace - std::tuple ps_roi_pool_autograd( const at::Tensor& input, const at::Tensor& rois, @@ -214,6 +183,8 @@ at::Tensor ps_roi_pool_backward_autograd( width)[0]; } +} // namespace + TORCH_LIBRARY_IMPL(torchvision, Autograd, m) { m.impl("ps_roi_pool", ps_roi_pool_autograd); m.impl("_ps_roi_pool_backward", ps_roi_pool_backward_autograd); diff --git a/torchvision/csrc/ps_roi_pool.h b/torchvision/csrc/ops/ps_roi_pool.h similarity index 93% rename from torchvision/csrc/ps_roi_pool.h rename to torchvision/csrc/ops/ps_roi_pool.h index c9ae946a4e2..2c2bab314d0 100644 --- a/torchvision/csrc/ps_roi_pool.h +++ b/torchvision/csrc/ops/ps_roi_pool.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/roi_align.cpp b/torchvision/csrc/ops/roi_align.cpp similarity index 88% rename from torchvision/csrc/roi_align.cpp rename to torchvision/csrc/ops/roi_align.cpp index 4a249c97ded..7116cc422ba 100644 --- a/torchvision/csrc/roi_align.cpp +++ b/torchvision/csrc/ops/roi_align.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -34,32 +30,6 @@ at::Tensor roi_align( aligned); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -at::Tensor roi_align_autocast( - const at::Tensor& input, - const at::Tensor& rois, - double spatial_scale, - int64_t pooled_height, - int64_t pooled_width, - int64_t sampling_ratio, - bool aligned) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - return roi_align( - at::autocast::cached_cast(at::kFloat, input), - at::autocast::cached_cast(at::kFloat, rois), - spatial_scale, - pooled_height, - pooled_width, - sampling_ratio, - aligned) - .to(input.scalar_type()); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("roi_align", roi_align_autocast); -} -#endif - at::Tensor _roi_align_backward( const at::Tensor& grad, const at::Tensor& rois, @@ -198,8 +168,6 @@ class ROIAlignBackwardFunction } }; -} // namespace - at::Tensor roi_align_autograd( const at::Tensor& input, const at::Tensor& rois, @@ -244,6 +212,8 @@ at::Tensor roi_align_backward_autograd( aligned)[0]; } +} // namespace + TORCH_LIBRARY_IMPL(torchvision, Autograd, m) { m.impl("roi_align", roi_align_autograd); m.impl("_roi_align_backward", roi_align_backward_autograd); diff --git a/torchvision/csrc/roi_align.h b/torchvision/csrc/ops/roi_align.h similarity index 93% rename from torchvision/csrc/roi_align.h rename to torchvision/csrc/ops/roi_align.h index 84c357d9c5f..628c0fd33dd 100644 --- a/torchvision/csrc/roi_align.h +++ b/torchvision/csrc/ops/roi_align.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops { diff --git a/torchvision/csrc/roi_pool.cpp b/torchvision/csrc/ops/roi_pool.cpp similarity index 87% rename from torchvision/csrc/roi_pool.cpp rename to torchvision/csrc/ops/roi_pool.cpp index a23ad4f8614..237c5e9adf8 100644 --- a/torchvision/csrc/roi_pool.cpp +++ b/torchvision/csrc/ops/roi_pool.cpp @@ -3,10 +3,6 @@ #include #include -#if defined(WITH_CUDA) || defined(WITH_HIP) -#include -#endif - namespace vision { namespace ops { @@ -22,31 +18,6 @@ std::tuple roi_pool( return op.call(input, rois, spatial_scale, pooled_height, pooled_width); } -#if defined(WITH_CUDA) || defined(WITH_HIP) -std::tuple roi_pool_autocast( - const at::Tensor& input, - const at::Tensor& rois, - double spatial_scale, - int64_t pooled_height, - int64_t pooled_width) { - c10::impl::ExcludeDispatchKeyGuard no_autocast(c10::DispatchKey::Autocast); - auto result = roi_pool( - at::autocast::cached_cast(at::kFloat, input), - at::autocast::cached_cast(at::kFloat, rois), - spatial_scale, - pooled_height, - pooled_width); - - return std::make_tuple( - std::get<0>(result).to(input.scalar_type()), - std::get<1>(result).to(input.scalar_type())); -} - -TORCH_LIBRARY_IMPL(torchvision, Autocast, m) { - m.impl("roi_pool", roi_pool_autocast); -} -#endif - at::Tensor _roi_pool_backward( const at::Tensor& grad, const at::Tensor& rois, @@ -175,8 +146,6 @@ class ROIPoolBackwardFunction } }; -} // namespace - std::tuple roi_pool_autograd( const at::Tensor& input, const at::Tensor& rois, @@ -213,6 +182,8 @@ at::Tensor roi_pool_backward_autograd( width)[0]; } +} // namespace + TORCH_LIBRARY_IMPL(torchvision, Autograd, m) { m.impl("roi_pool", roi_pool_autograd); m.impl("_roi_pool_backward", roi_pool_backward_autograd); diff --git a/torchvision/csrc/roi_pool.h b/torchvision/csrc/ops/roi_pool.h similarity index 93% rename from torchvision/csrc/roi_pool.h rename to torchvision/csrc/ops/roi_pool.h index ceebf201769..5ecdb711e1b 100644 --- a/torchvision/csrc/roi_pool.h +++ b/torchvision/csrc/ops/roi_pool.h @@ -1,7 +1,7 @@ #pragma once #include -#include "macros.h" +#include "../macros.h" namespace vision { namespace ops {