Skip to content

Commit

Permalink
build(cmake): add an ability to opt in only for certain CV-CUDA opera…
Browse files Browse the repository at this point in the history
…tors

- 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]>
  • Loading branch information
JanuszL committed Aug 9, 2023
1 parent e4f97ee commit 7978ff0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
28 changes: 26 additions & 2 deletions src/cvcuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
# cvcuda private implementation
add_subdirectory(priv)

add_library(cvcuda SHARED
set(CV_CUDA_LIB_FILES Operator.cpp)

set(CV_CUDA_OP_FILES
OpBoxBlur.cpp
OpBndBox.cpp
OpBrightnessContrast.cpp
OpRemap.cpp
OpColorTwist.cpp
OpCropFlipNormalizeReformat.cpp
OpNonMaximumSuppression.cpp
Operator.cpp
OpReformat.cpp
OpResize.cpp
OpCustomCrop.cpp
Expand Down Expand Up @@ -57,6 +58,29 @@ add_library(cvcuda SHARED
OpGaussianNoise.cpp
)

# filter only one that matches the patern (case insensitive), should be set on the global level
# usage:
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
#
# will compile only files relevant to themedian blur op "OpMedianBlur.cpp"
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
string(TOLOWER ${PATTERN} PATTERN)
foreach(FILENAME ${CV_CUDA_OP_FILES})
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
list(APPEND CV_CUDA_LIB_FILES ${FILENAME})
endif()
endforeach()
endforeach()
else()
list(APPEND CV_CUDA_LIB_FILES ${CV_CUDA_OP_FILES})
endif()

add_library(cvcuda SHARED
${CV_CUDA_LIB_FILES}
)

target_link_libraries(cvcuda
PUBLIC
CUDA::cudart_static
Expand Down
28 changes: 26 additions & 2 deletions src/cvcuda/priv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@

add_subdirectory(legacy)

add_library(cvcuda_priv STATIC
set(CV_CUDA_PRIV_FILES IOperator.cpp)

set(CV_CUDA_PRIV_OP_FILES
OpBoxBlur.cpp
OpBndBox.cpp
OpBrightnessContrast.cu
OpRemap.cu
OpColorTwist.cu
OpCropFlipNormalizeReformat.cu
OpNonMaximumSuppression.cu
IOperator.cpp
OpReformat.cpp
OpResize.cpp
OpCustomCrop.cpp
Expand Down Expand Up @@ -56,6 +57,29 @@ add_library(cvcuda_priv STATIC
OpGaussianNoise.cpp
)

# filter only one that matches the patern (case insensitive), should be set on the global level
# usage:
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
#
# will compile only files relevant to themedian blur op "OpMedianBlur.cpp"
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
string(TOLOWER ${PATTERN} PATTERN)
foreach(FILENAME ${CV_CUDA_PRIV_OP_FILES})
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
list(APPEND CV_CUDA_PRIV_FILES ${FILENAME})
endif()
endforeach()
endforeach()
else()
list(APPEND CV_CUDA_PRIV_FILES ${CV_CUDA_PRIV_OP_FILES})
endif()

add_library(cvcuda_priv STATIC
${CV_CUDA_PRIV_FILES}
)

target_link_libraries(cvcuda_priv
PUBLIC
nvcv_types
Expand Down
28 changes: 26 additions & 2 deletions src/cvcuda/priv/legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

add_library(cvcuda_legacy STATIC
set(CV_CUDA_PRIV_LEGACY_FILES CvCudaLegacyHelpers.cpp)

set(CV_CUDA_PRIV_LEGACY_OP_FILES
filter_utils.cu
custom_crop.cu
reformat.cu
Expand Down Expand Up @@ -49,7 +51,6 @@ add_library(cvcuda_legacy STATIC
flip.cu
flip_or_copy_var_shape.cu
composite_var_shape.cu
CvCudaLegacyHelpers.cpp
custom_crop.cu
reformat.cu
resize.cu
Expand All @@ -75,6 +76,29 @@ add_library(cvcuda_legacy STATIC
gaussian_noise_util.cu
)

# filter only one that matches the patern (case insensitive), should be set on the global level
# usage:
# set(CV_CUDA_SRC_PATERN medianblur median_blur"
#
# will compile only files relevant to themedian blur op "median_blur.cu;median_blur_var_shape.cu"
if (NOT "${CV_CUDA_SRC_PATERN}" STREQUAL "")
foreach(PATTERN ${CV_CUDA_SRC_PATERN})
string(TOLOWER ${PATTERN} PATTERN)
foreach(FILENAME ${CV_CUDA_PRIV_LEGACY_OP_FILES})
string(TOLOWER ${FILENAME} FILENAME_LOWERCASE)
if (${FILENAME_LOWERCASE} MATCHES ${PATTERN})
list(APPEND CV_CUDA_PRIV_LEGACY_FILES ${FILENAME})
endif()
endforeach()
endforeach()
else()
list(APPEND CV_CUDA_PRIV_LEGACY_FILES ${CV_CUDA_PRIV_LEGACY_OP_FILES})
endif()

add_library(cvcuda_legacy STATIC
${CV_CUDA_PRIV_LEGACY_FILES}
)

target_link_libraries(cvcuda_legacy
PUBLIC
CUDA::cudart_static
Expand Down

0 comments on commit 7978ff0

Please sign in to comment.