Skip to content

Commit 7978ff0

Browse files
committed
build(cmake): add an ability to opt in only for certain CV-CUDA operators
- adds an ability to compile only CV-CUDA files that match the given pattern so the user can have binary only with selected operators (which also reduces its size) Closes CVCUDA-0 Signed-off-by: Janusz Lisiecki <[email protected]>
1 parent e4f97ee commit 7978ff0

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

src/cvcuda/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
# cvcuda private implementation
1717
add_subdirectory(priv)
1818

19-
add_library(cvcuda SHARED
19+
set(CV_CUDA_LIB_FILES Operator.cpp)
20+
21+
set(CV_CUDA_OP_FILES
2022
OpBoxBlur.cpp
2123
OpBndBox.cpp
2224
OpBrightnessContrast.cpp
2325
OpRemap.cpp
2426
OpColorTwist.cpp
2527
OpCropFlipNormalizeReformat.cpp
2628
OpNonMaximumSuppression.cpp
27-
Operator.cpp
2829
OpReformat.cpp
2930
OpResize.cpp
3031
OpCustomCrop.cpp
@@ -57,6 +58,29 @@ add_library(cvcuda SHARED
5758
OpGaussianNoise.cpp
5859
)
5960

61+
# filter only one that matches the patern (case insensitive), should be set on the global level
62+
# usage:
63+
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
64+
#
65+
# will compile only files relevant to themedian blur op "OpMedianBlur.cpp"
66+
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
67+
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
68+
string(TOLOWER ${PATTERN} PATTERN)
69+
foreach(FILENAME ${CV_CUDA_OP_FILES})
70+
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
71+
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
72+
list(APPEND CV_CUDA_LIB_FILES ${FILENAME})
73+
endif()
74+
endforeach()
75+
endforeach()
76+
else()
77+
list(APPEND CV_CUDA_LIB_FILES ${CV_CUDA_OP_FILES})
78+
endif()
79+
80+
add_library(cvcuda SHARED
81+
${CV_CUDA_LIB_FILES}
82+
)
83+
6084
target_link_libraries(cvcuda
6185
PUBLIC
6286
CUDA::cudart_static

src/cvcuda/priv/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515

1616
add_subdirectory(legacy)
1717

18-
add_library(cvcuda_priv STATIC
18+
set(CV_CUDA_PRIV_FILES IOperator.cpp)
19+
20+
set(CV_CUDA_PRIV_OP_FILES
1921
OpBoxBlur.cpp
2022
OpBndBox.cpp
2123
OpBrightnessContrast.cu
2224
OpRemap.cu
2325
OpColorTwist.cu
2426
OpCropFlipNormalizeReformat.cu
2527
OpNonMaximumSuppression.cu
26-
IOperator.cpp
2728
OpReformat.cpp
2829
OpResize.cpp
2930
OpCustomCrop.cpp
@@ -56,6 +57,29 @@ add_library(cvcuda_priv STATIC
5657
OpGaussianNoise.cpp
5758
)
5859

60+
# filter only one that matches the patern (case insensitive), should be set on the global level
61+
# usage:
62+
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
63+
#
64+
# will compile only files relevant to themedian blur op "OpMedianBlur.cpp"
65+
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
66+
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
67+
string(TOLOWER ${PATTERN} PATTERN)
68+
foreach(FILENAME ${CV_CUDA_PRIV_OP_FILES})
69+
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
70+
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
71+
list(APPEND CV_CUDA_PRIV_FILES ${FILENAME})
72+
endif()
73+
endforeach()
74+
endforeach()
75+
else()
76+
list(APPEND CV_CUDA_PRIV_FILES ${CV_CUDA_PRIV_OP_FILES})
77+
endif()
78+
79+
add_library(cvcuda_priv STATIC
80+
${CV_CUDA_PRIV_FILES}
81+
)
82+
5983
target_link_libraries(cvcuda_priv
6084
PUBLIC
6185
nvcv_types

src/cvcuda/priv/legacy/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
add_library(cvcuda_legacy STATIC
16+
set(CV_CUDA_PRIV_LEGACY_FILES CvCudaLegacyHelpers.cpp)
17+
18+
set(CV_CUDA_PRIV_LEGACY_OP_FILES
1719
filter_utils.cu
1820
custom_crop.cu
1921
reformat.cu
@@ -49,7 +51,6 @@ add_library(cvcuda_legacy STATIC
4951
flip.cu
5052
flip_or_copy_var_shape.cu
5153
composite_var_shape.cu
52-
CvCudaLegacyHelpers.cpp
5354
custom_crop.cu
5455
reformat.cu
5556
resize.cu
@@ -75,6 +76,29 @@ add_library(cvcuda_legacy STATIC
7576
gaussian_noise_util.cu
7677
)
7778

79+
# filter only one that matches the patern (case insensitive), should be set on the global level
80+
# usage:
81+
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
82+
#
83+
# will compile only files relevant to themedian blur op "median_blur.cu;median_blur_var_shape.cu"
84+
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
85+
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
86+
string(TOLOWER ${PATTERN} PATTERN)
87+
foreach(FILENAME ${CV_CUDA_PRIV_LEGACY_OP_FILES})
88+
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
89+
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
90+
list(APPEND CV_CUDA_PRIV_LEGACY_FILES ${FILENAME})
91+
endif()
92+
endforeach()
93+
endforeach()
94+
else()
95+
list(APPEND CV_CUDA_PRIV_LEGACY_FILES ${CV_CUDA_PRIV_LEGACY_OP_FILES})
96+
endif()
97+
98+
add_library(cvcuda_legacy STATIC
99+
${CV_CUDA_PRIV_LEGACY_FILES}
100+
)
101+
78102
target_link_libraries(cvcuda_legacy
79103
PUBLIC
80104
CUDA::cudart_static

0 commit comments

Comments
 (0)