Skip to content

Commit 0ebbb0a

Browse files
authored
Encapsulate and Standardise C++ Ops (#3097)
* Encapsulate and standardize deform_conv2d (#3074) * Rename files. * Standardizing method names. * Adding anonymous namespaces. * Applying C++ naming rules and alinging variable names across headers and cpp files. * Syncing names across implementations. * Rename deform_conv2d.h to deform_conv2d.cpp * Use header files: - Create header files for kernel implementation and remove definitions from vision_*.h files. - Eliminate unnecessary headers and ensure all cpp include their headers. * Change the naming convention for kernel implementations. * Remove the _param postfix from the variables and standardizing names. * Exposing public forward/backward methods to the C++ API and moving methods around to minimize git blame changes. * Encapsulate and standardize nms (#3081) * Syncing, where possible, the names of functions across devices. * Adding all internal functions in anonymous namespaces. * Renaming C++/CUDA kernel files and moving operator code from header to cpp file. * Create foreach cpp file a separate header file with "public" functions. * Removing unnecessary repeated includes. * Update CMakeLists.txt to include all headers. * Encapsulate and standardize ps_roi_align (#3082) * Renaming C++ files & methods according to recommended naming conventions and aligning them with Python's API. Syncing, where possible, the names of functions across devices. * Adding all internal functions in anonymous namespaces. * Renaming C++/CUDA kernel files and moving operator code from header to cpp file. * Create foreach cpp file a separate header file with "public" functions. * Removing unnecessary repeated includes. * Encapsulate and standardize ps_roi_pool (#3084) * Renaming C++ files & methods according to recommended naming conventions and aligning them with Python's API. * Adding all internal functions in anonymous namespaces. * Renaming C++/CUDA kernel files and moving operator code from header to cpp file. * Create foreach cpp file a separate header file with "public" functions. * Removing unnecessary repeated includes. * Encapsulate and standardize roi_align (#3085) * Renaming C++ files & methods according to recommended naming conventions and aligning them with Python's API. * Adding all internal functions in anonymous namespaces. * Renaming C++/CUDA kernel files and moving operator code from header to cpp file. * Create foreach cpp file a separate header file with "public" functions. * Removing unnecessary repeated includes. * Encapsulate and standardize roi_pool (#3088) * Renaming C++ files & methods according to recommended naming conventions and aligning them with Python's API. * Adding all internal functions in anonymous namespaces. * Syncing variable names between the cpp files and their header files. * Renaming C++/CUDA kernel files and moving operator code from header to cpp file. * Create foreach cpp file a separate header file with "public" functions. * Removing unnecessary repeated includes. * Encapsulate and standardize new_empty_tensor_op (#3089) * Renaming C++ files & methods according to recommended naming conventions and aligning them with Python's API. * Create foreach cpp file a separate header file with "public" functions. * Adding all internal functions in anonymous namespaces. * Convert to const ref all possible parameters. * Removing unnecessary repeated includes. * Encapsulate and standardize C++ Ops - Clean up (#3094) * Removing unnecessary repeated includes. * Remove unnecessary vision_cpu.h, vision_cuda.h, autocast.h. * Fixing naming convention and correcting method names on macros. * Turn on clang formatter for cu files and fixing broken styles. * Replace "#ifndef ... #define ... #endif" with "#pragma once" on header files. * Adding operator methods in vision::ops namespace. (#3096) * Adding operator methods in vision::ops namespace. * Replace general.h with macros.h * Adding vision.h to the necessary cpp files.
1 parent 8520f0b commit 0ebbb0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1885
-1264
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ file(GLOB HEADERS torchvision/csrc/*.h)
3232
# Image extension
3333
file(GLOB IMAGE_HEADERS torchvision/csrc/cpu/image/*.h)
3434
file(GLOB IMAGE_SOURCES torchvision/csrc/cpu/image/*.cpp)
35-
file(GLOB OPERATOR_SOURCES torchvision/csrc/cpu/*.h torchvision/csrc/cpu/*.cpp ${IMAGE_HEADERS} ${IMAGE_SOURCES} ${HEADERS} torchvision/csrc/*.cpp)
35+
file(GLOB OPERATOR_HEADERS torchvision/csrc/cpu/*.h)
36+
file(GLOB OPERATOR_SOURCES ${OPERATOR_HEADERS} torchvision/csrc/cpu/*.cpp ${IMAGE_HEADERS} ${IMAGE_SOURCES} ${HEADERS} torchvision/csrc/*.cpp)
3637
if(WITH_CUDA)
37-
file(GLOB OPERATOR_SOURCES ${OPERATOR_SOURCES} torchvision/csrc/cuda/*.h torchvision/csrc/cuda/*.cu)
38+
file(GLOB OPERATOR_HEADERS ${OPERATOR_HEADERS} torchvision/csrc/cuda/*.h)
39+
file(GLOB OPERATOR_SOURCES ${OPERATOR_SOURCES} ${OPERATOR_HEADERS} torchvision/csrc/cuda/*.cu)
3840
endif()
3941
file(GLOB MODELS_HEADERS torchvision/csrc/models/*.h)
4042
file(GLOB MODELS_SOURCES torchvision/csrc/models/*.h torchvision/csrc/models/*.cpp)
@@ -95,11 +97,11 @@ install(EXPORT TorchVisionTargets
9597

9698
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
9799
install(FILES
98-
torchvision/csrc/cpu/vision_cpu.h
100+
${OPERATOR_HEADERS}
99101
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cpu)
100102
if(WITH_CUDA)
101103
install(FILES
102-
torchvision/csrc/cuda/vision_cuda.h
104+
${OPERATOR_HEADERS}
103105
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cuda)
104106
endif()
105107
install(FILES ${MODELS_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/models)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def get_extensions():
152152
)
153153
source_cuda = glob.glob(os.path.join(extensions_dir, 'hip', '*.hip'))
154154
# Copy over additional files
155-
shutil.copy("torchvision/csrc/cuda/cuda_helpers.h", "torchvision/csrc/hip/cuda_helpers.h")
156-
shutil.copy("torchvision/csrc/cuda/vision_cuda.h", "torchvision/csrc/hip/vision_cuda.h")
155+
for file in glob.glob(r"torchvision/csrc/cuda/*.h"):
156+
shutil.copy(file, "torchvision/csrc/hip")
157157

158158
else:
159159
source_cuda = glob.glob(os.path.join(extensions_dir, 'cuda', '*.cu'))

test/tracing/frcnn/test_frcnn_tracing.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#include <ATen/ATen.h>
22
#include <torch/script.h>
33
#include <torch/torch.h>
4-
#include <torchvision/ROIAlign.h>
5-
#include <torchvision/cpu/vision_cpu.h>
4+
#include <torchvision/roi_align.h>
65
#include <torchvision/nms.h>
76

87
#ifdef _WIN32
98
// Windows only
109
// This is necessary until operators are automatically registered on include
11-
static auto _nms = &nms_cpu;
10+
static auto _nms = &vision::ops::nms_cpu;
1211
#endif
1312

1413
int main() {

torchvision/csrc/autocast.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)