Skip to content

Commit 1bacdd2

Browse files
[hipDNN] Fix invalid exported include paths and remove old check cmake targets. (#3670)
## Motivation Resolves ROCm/TheRock#2807 Also removes the unneeded cmake *check-old test targets as the new ctest targets have proven sufficient. ## Technical Details Issue was due to TheRock install propagating build paths for installed targets. This fix removes the propagated build paths, and adds the proper include paths to the installed cmake config. ## Test Plan Tests & build are passing correctly. Adding a test to TheRock as a separate follow-up to emulate client consumption of hipDNN to prevent regressions. Locally installing the artifacts, and using them to build samples from hipDNN. ## Test Result Test & build are working. Samples are now building and installing properly using artifacts generated with this change. --------- Co-authored-by: BrianHarrisonAMD <169072757+BrianHarrisonAMD@users.noreply.github.com>
1 parent 7e63522 commit 1bacdd2

File tree

7 files changed

+212
-287
lines changed

7 files changed

+212
-287
lines changed

projects/hipdnn/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ if(HIP_DNN_BUILD_PLUGINS)
189189
endif()
190190

191191
if(NOT HIP_DNN_SKIP_TESTS)
192-
# keep this after all build folder have been added so they have a chance to register their tests
193-
# using append_test_to_check_target
192+
# Keep this after all build folders have been added so they have a chance to register their tests
193+
# using add_*_test_target()
194194
finalize_test_targets()
195195
endif()
196196

projects/hipdnn/backend/src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ clang_tidy_check(hipdnn_backend_private)
4444

4545
add_library(hipdnn_backend SHARED HipdnnBackend.cpp)
4646

47-
target_include_directories(hipdnn_backend SYSTEM PUBLIC ${HIP_INCLUDE_DIRS})
48-
4947
target_include_directories(
5048
hipdnn_backend
5149
PUBLIC $<BUILD_INTERFACE:${HIP_DNN_BACKEND_INCLUDE_DIR}>

projects/hipdnn/cmake/Dependencies.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ function(hipdnn_add_dependency_includes TARGET_NAME HEADER_LIB_TARGET_NAME)
7777
if(TARGET ${HEADER_LIB_TARGET_NAME})
7878
get_target_property(_dep_includes ${HEADER_LIB_TARGET_NAME} INTERFACE_INCLUDE_DIRECTORIES)
7979
if(_dep_includes)
80-
message(VERBOSE "${TARGET_NAME} adding includes from ${HEADER_LIB_TARGET_NAME}: ${_dep_includes}")
81-
target_include_directories(${TARGET_NAME} SYSTEM INTERFACE ${_dep_includes})
80+
foreach(_include IN LISTS _dep_includes)
81+
message(VERBOSE "${TARGET_NAME} adding include from ${HEADER_LIB_TARGET_NAME}: ${_include}")
82+
target_include_directories(${TARGET_NAME} SYSTEM INTERFACE $<BUILD_INTERFACE:${_include}>)
83+
endforeach()
8284
endif()
8385

8486
if(ARG_COMPILE_DEFINITIONS)

projects/hipdnn/cmake/Tests.cmake

Lines changed: 31 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,8 @@ find_package(Python3 COMPONENTS Interpreter)
1313

1414
findandcheckllvmsymbolizer()
1515

16-
# Set executable prefix based on platform
17-
if(WIN32)
18-
set(EXEC_PREFIX "")
19-
else()
20-
set(EXEC_PREFIX "./")
21-
endif()
22-
23-
set(CHECK_COMMAND_GLOBAL "" CACHE INTERNAL "Accumulated check commands" FORCE)
24-
set(CHECK_DEPENDS_GLOBAL "" CACHE INTERNAL "Accumulated check depends" FORCE)
25-
set(CHECK_EXECUTABLE_PATHS_GLOBAL "" CACHE INTERNAL "Accumulated check executable paths" FORCE)
26-
27-
# Global collections for unit tests
28-
set(UNIT_CHECK_COMMAND_GLOBAL "" CACHE INTERNAL "Accumulated unit check commands" FORCE)
29-
set(UNIT_CHECK_DEPENDS_GLOBAL "" CACHE INTERNAL "Accumulated unit check depends" FORCE)
30-
31-
# Global collections for integration tests
32-
set(INTEGRATION_CHECK_COMMAND_GLOBAL "" CACHE INTERNAL "Accumulated integration check commands"
33-
FORCE
34-
)
35-
set(INTEGRATION_CHECK_DEPENDS_GLOBAL "" CACHE INTERNAL "Accumulated integration check depends"
36-
FORCE
37-
)
16+
set(CHECK_DEPENDS_GLOBAL "" CACHE INTERNAL "Accumulated global dependencies for test name validation" FORCE)
17+
set(CHECK_EXECUTABLE_PATHS_GLOBAL "" CACHE INTERNAL "Accumulated global check executable paths" FORCE)
3818

3919
# Builds the test environment list with optional code coverage support
4020
# ~~~
@@ -98,86 +78,6 @@ function(_create_test_name_validation_target_internal)
9878
endif() # Python3_FOUND
9979
endfunction() # _create_test_name_validation_target_internal
10080

101-
# Generic internal function to append tests to check targets
102-
function(_append_test_to_check_target_internal TARGET WORKING_DIR TEST_TYPE STATUS_MESSAGE)
103-
if(STATUS_MESSAGE)
104-
message(STATUS "${STATUS_MESSAGE}: ${TARGET} in working directory: ${WORKING_DIR}")
105-
endif()
106-
107-
if("${TEST_TYPE}" STREQUAL "UNIT")
108-
set(COMMAND_VAR "UNIT_CHECK_COMMAND_GLOBAL")
109-
set(DEPENDS_VAR "UNIT_CHECK_DEPENDS_GLOBAL")
110-
set(CACHE_DESC "Accumulated unit check targets")
111-
elseif("${TEST_TYPE}" STREQUAL "INTEGRATION")
112-
set(COMMAND_VAR "INTEGRATION_CHECK_COMMAND_GLOBAL")
113-
set(DEPENDS_VAR "INTEGRATION_CHECK_DEPENDS_GLOBAL")
114-
set(CACHE_DESC "Accumulated integration check targets")
115-
else()
116-
set(COMMAND_VAR "CHECK_COMMAND_GLOBAL")
117-
set(DEPENDS_VAR "CHECK_DEPENDS_GLOBAL")
118-
set(CACHE_DESC "Accumulated check targets")
119-
endif()
120-
121-
# Build environment list properly
122-
_build_test_environment_list_internal(ENVIRONMENT_LIST)
123-
124-
set(NEW_COMMAND "")
125-
if("${${COMMAND_VAR}}" STREQUAL "")
126-
set(NEW_COMMAND ${CMAKE_COMMAND} -E env ${ENVIRONMENT_LIST}
127-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${TARGET}
128-
)
129-
else()
130-
set(NEW_COMMAND && ${CMAKE_COMMAND} -E env ${ENVIRONMENT_LIST}
131-
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${TARGET}
132-
)
133-
endif()
134-
135-
set(${COMMAND_VAR} ${${COMMAND_VAR}} ${NEW_COMMAND} CACHE INTERNAL "${CACHE_DESC}" FORCE)
136-
set(${DEPENDS_VAR} ${${DEPENDS_VAR}} ${TARGET}
137-
CACHE INTERNAL "Accumulated ${TEST_TYPE} check depends" FORCE
138-
)
139-
140-
# Track the binary paths for test name validation
141-
set(EXECUTABLE_PATH "${CMAKE_INSTALL_BINDIR}/${TARGET}")
142-
set(CHECK_EXECUTABLE_PATHS_GLOBAL ${CHECK_EXECUTABLE_PATHS_GLOBAL} ${EXECUTABLE_PATH}
143-
CACHE INTERNAL "Accumulated check executable paths" FORCE
144-
)
145-
endfunction() # _append_test_to_check_target_internal
146-
147-
# Generic internal function to finalize DIY check targets
148-
function(_finalize_check_target_internal TARGET_NAME COMMAND_VAR DEPENDS_VAR)
149-
add_custom_target(
150-
${TARGET_NAME}
151-
COMMAND ${${COMMAND_VAR}}
152-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
153-
DEPENDS ${${DEPENDS_VAR}}
154-
VERBATIM
155-
COMMENT "Running ${TARGET_NAME}"
156-
USES_TERMINAL
157-
)
158-
message(VERBOSE "Created ${TARGET_NAME} target")
159-
endfunction() # _finalize_check_target_internal
160-
161-
# Internal function to finalize the DIY unclassified check-old target
162-
function(_finalize_unclassified_check_target_internal)
163-
_finalize_check_target_internal("check-old" "CHECK_COMMAND_GLOBAL" "CHECK_DEPENDS_GLOBAL")
164-
endfunction() # _finalize_unclassified_check_target_internal
165-
166-
# Internal function to finalize the DIY unit-check-old target
167-
function(_finalize_unit_check_target_internal)
168-
_finalize_check_target_internal(
169-
"unit-check-old" "UNIT_CHECK_COMMAND_GLOBAL" "UNIT_CHECK_DEPENDS_GLOBAL"
170-
)
171-
endfunction() # _finalize_unit_check_target_internal
172-
173-
# Internal function to finalize the DIY integration-check-old target
174-
function(_finalize_integration_check_target_internal)
175-
_finalize_check_target_internal(
176-
"integration-check-old" "INTEGRATION_CHECK_COMMAND_GLOBAL"
177-
"INTEGRATION_CHECK_DEPENDS_GLOBAL"
178-
)
179-
endfunction() # _finalize_integration_check_target_internal
180-
18181
enable_testing() # Cmake wont discover or run tests without this line
18282

18383
# Internal helper function to create a ctest target
@@ -214,7 +114,7 @@ function(_add_ctest_target_internal TARGET_NAME LABEL VERBOSE COMMENT)
214114
message(VERBOSE "Created ${TARGET_NAME} target")
215115
endfunction() # _add_ctest_target_internal
216116

217-
# Internal helper function to create the (new) check targets for running tests via ctest
117+
# Internal helper function to create the check targets for running tests via ctest
218118
function(_create_ctest_targets_internal)
219119
# cmake-format: off
220120
# Build test environment once for all ctest targets
@@ -238,12 +138,6 @@ function(finalize_test_targets)
238138

239139
_create_ctest_targets_internal()
240140

241-
_finalize_unclassified_check_target_internal()
242-
_finalize_unit_check_target_internal()
243-
_finalize_integration_check_target_internal()
244-
245-
add_dependencies(check-old validate_test_names)
246-
247141
# cmake-format: off
248142
# Create alias test targets without '_ctest' in the name
249143
# Regular targets (without --verbose)
@@ -259,36 +153,37 @@ function(finalize_test_targets)
259153
# cmake-format: on
260154
endfunction() # finalize_test_targets
261155

262-
# Internal (old) DIY function to add a test target (assumes the test executable is a gtest
263-
# executable) Still needed for collecting list of test executables in HIPDNN_TEST_TARGETS and
264-
# setting test-type labels. TODO: Deprecate this funcion and remove manual test collection once new
265-
# ctest-based method is proven.
266-
function(_add_gtest_target_internal APPEND_FUNCTION_SUFFIX TARGET WORKING_DIR)
267-
if("${APPEND_FUNCTION_SUFFIX}" STREQUAL "test")
268-
_append_test_to_check_target_internal(
269-
${TARGET} ${WORKING_DIR} "" "Appending unclassified check target"
270-
)
271-
elseif("${APPEND_FUNCTION_SUFFIX}" STREQUAL "unit_test")
272-
_append_test_to_check_target_internal(
273-
${TARGET} ${WORKING_DIR} "UNIT" "Appending unit check target"
274-
)
275-
_append_test_to_check_target_internal(${TARGET} ${WORKING_DIR} "" "")
276-
elseif("${APPEND_FUNCTION_SUFFIX}" STREQUAL "integration_test")
277-
_append_test_to_check_target_internal(
278-
${TARGET} ${WORKING_DIR} "INTEGRATION" "Appending integration check target"
279-
)
280-
_append_test_to_check_target_internal(${TARGET} ${WORKING_DIR} "" "")
281-
else()
282-
message(FATAL_ERROR "Unknown test type suffix: ${APPEND_FUNCTION_SUFFIX}")
283-
endif()
156+
# ~~~
157+
# Internal helper function to record, configure, and register a ctest test target. Assumes that the
158+
# test target is a gtest executable, setting up:
159+
# - Test name validation tracking (adds to global dependency and executable path lists)
160+
# - RPATH settings for relocatable test executables
161+
# - Installation rules for test binaries
162+
# - CTest registration with appropriate labels (e.g. unit / integration test labels)
163+
# Parameters:
164+
# APPEND_FUNCTION_SUFFIX - Label to apply to the test (e.g., "unit_test", "integration_test", "test")
165+
# TARGET - Name of the test executable target (must already exist)
166+
# WORKING_DIR - Working directory for test execution
167+
# ~~~
168+
function(_add_test_target_internal APPEND_FUNCTION_SUFFIX TARGET WORKING_DIR)
169+
message(STATUS "Appending ${APPEND_FUNCTION_SUFFIX} check target: ${TARGET} in working directory: ${WORKING_DIR}")
284170

285-
set_target_properties(
286-
${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}"
171+
# Track the dependencies for test name validation
172+
set(CHECK_DEPENDS_GLOBAL ${CHECK_DEPENDS_GLOBAL} ${TARGET}
173+
CACHE INTERNAL "Accumulated global dependencies for test name validation" FORCE
174+
)
175+
# Track the binary paths for test name validation
176+
set(CHECK_EXECUTABLE_PATHS_GLOBAL ${CHECK_EXECUTABLE_PATHS_GLOBAL} "${CMAKE_INSTALL_BINDIR}/${TARGET}"
177+
CACHE INTERNAL "Accumulated global check executable paths" FORCE
287178
)
288179

289180
# Track this test target for later use in generating installed CTestTestfile.cmake
290181
set_property(GLOBAL APPEND PROPERTY HIPDNN_TEST_TARGETS ${TARGET})
291182

183+
set_target_properties(
184+
${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}"
185+
)
186+
292187
# Make test executables relocatable so they can find libraries when build directory is moved
293188
# Include both the main lib directory and the engine plugin directories
294189
set_target_properties(
@@ -309,17 +204,17 @@ endfunction() # _add_gtest_target_internal
309204

310205
# Adds a generic test target
311206
function(add_unclassified_test_target TARGET WORKING_DIR)
312-
_add_gtest_target_internal(test ${TARGET} ${WORKING_DIR})
207+
_add_test_target_internal(test ${TARGET} ${WORKING_DIR})
313208
endfunction() # add_unclassified_test_target
314209

315210
# Adds a unit test target
316211
function(add_unit_test_target TARGET WORKING_DIR)
317-
_add_gtest_target_internal(unit_test ${TARGET} ${WORKING_DIR})
212+
_add_test_target_internal(unit_test ${TARGET} ${WORKING_DIR})
318213
endfunction() # add_unit_test_target
319214

320215
# Adds an integration test target
321216
function(add_integration_test_target TARGET WORKING_DIR)
322-
_add_gtest_target_internal(integration_test ${TARGET} ${WORKING_DIR})
217+
_add_test_target_internal(integration_test ${TARGET} ${WORKING_DIR})
323218
endfunction() # add_integration_test_target
324219

325220
# Install CTest configuration files for direct test execution This should be called once at the end

projects/hipdnn/data_sdk/cmake/hipdnn_data_sdkConfig_imported.cmake.in

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33

44
@PACKAGE_INIT@
55

6+
# Extract and use include directories from dependency targets instead of linking
7+
# Function to add include directories and optional compile definitions from dependency targets
8+
# !!!! Note !!!! We are using this to force a headeronly consumption of 3rd party dependencies for hipdnn_data_sdk
9+
# Using regular linking will result in a non-header only consumption of these libraries due to the way they are configured when installing
10+
function(hipdnn_add_dependency_includes TARGET_NAME HEADER_LIB_TARGET_NAME)
11+
# Parse optional arguments
12+
set(options "")
13+
set(oneValueArgs "")
14+
set(multiValueArgs COMPILE_DEFINITIONS)
15+
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
16+
17+
# Validate required parameters
18+
if(NOT TARGET ${TARGET_NAME})
19+
message(FATAL_ERROR "hipdnn_add_dependency_includes: Target '${TARGET_NAME}' does not exist")
20+
return()
21+
endif()
22+
23+
if(NOT TARGET ${HEADER_LIB_TARGET_NAME})
24+
message(FATAL_ERROR "hipdnn_add_dependency_includes: Header library target '${HEADER_LIB_TARGET_NAME}' does not exist")
25+
return()
26+
endif()
27+
28+
if(TARGET ${HEADER_LIB_TARGET_NAME})
29+
get_target_property(_dep_includes ${HEADER_LIB_TARGET_NAME} INTERFACE_INCLUDE_DIRECTORIES)
30+
if(_dep_includes)
31+
message(VERBOSE "${TARGET_NAME} adding includes from ${HEADER_LIB_TARGET_NAME}: ${_dep_includes}")
32+
target_include_directories(${TARGET_NAME} SYSTEM INTERFACE ${_dep_includes})
33+
endif()
34+
35+
if(ARG_COMPILE_DEFINITIONS)
36+
target_compile_definitions(${TARGET_NAME} INTERFACE ${ARG_COMPILE_DEFINITIONS})
37+
endif()
38+
endif()
39+
endfunction()
40+
641
# Find required dependencies
742
find_package(Threads REQUIRED)
843

@@ -12,6 +47,9 @@ find_dependency(flatbuffers REQUIRED)
1247
find_dependency(spdlog REQUIRED)
1348
find_dependency(nlohmann_json REQUIRED)
1449

50+
# fmt can potentially be embedded in spdlog, make this dependency quiet, and conditional include the path
51+
find_dependency(fmt QUIET)
52+
1553
# Subdirectory path for hipDNN engine plugins (relative to lib)
1654
set(HIPDNN_PLUGIN_ENGINE_SUBDIR "@HIPDNN_PLUGIN_ENGINE_SUBDIR@")
1755

@@ -21,6 +59,16 @@ set(HIPDNN_RELATIVE_INSTALL_PLUGIN_ENGINE_DIR "@HIPDNN_RELATIVE_INSTALL_PLUGIN_E
2159

2260
include("${CMAKE_CURRENT_LIST_DIR}/hipdnn_data_sdkTargets.cmake")
2361

62+
hipdnn_add_dependency_includes(hipdnn_data_sdk flatbuffers::flatbuffers)
63+
hipdnn_add_dependency_includes(hipdnn_data_sdk spdlog::spdlog_header_only)
64+
hipdnn_add_dependency_includes(hipdnn_data_sdk nlohmann_json::nlohmann_json)
65+
if (fmt_FOUND)
66+
message(STATUS "Found fmt: using system fmt")
67+
hipdnn_add_dependency_includes(hipdnn_data_sdk fmt::fmt COMPILE_DEFINITIONS SPDLOG_FMT_EXTERNAL)
68+
else()
69+
message(STATUS "Not found fmt: using bundled fmt from spdlog")
70+
endif()
71+
2472
message(STATUS "hipDNN Data SDK: Engine plugin build directory is ${CMAKE_INSTALL_LIBDIR}/${HIPDNN_PLUGIN_ENGINE_SUBDIR}")
2573
message(STATUS "hipDNN Data SDK: Plugin absolute installation directory ${HIPDNN_FULL_INSTALL_PLUGIN_ENGINE_DIR}")
2674
message(STATUS "hipDNN Data SDK: Plugin relative installation directory ${HIPDNN_RELATIVE_INSTALL_PLUGIN_ENGINE_DIR}")

projects/hipdnn/plugins/miopen_legacy_plugin/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,9 @@ if(NOT HIP_DNN_SKIP_TESTS)
159159
add_subdirectory(integration_tests)
160160

161161
if(NOT BUILD_PLUGIN_AS_DEPENDENCY)
162-
create_test_name_validation_target()
163-
164-
finalize_custom_check_target()
165-
finalize_unit_check_target()
166-
finalize_integration_check_target()
167-
168-
add_dependencies(check validate_test_names)
169-
add_dependencies(check_ctest validate_test_names)
162+
# Keep this after all build folders have been added so they have a chance to register their tests
163+
# using add_*_test_target()
164+
finalize_test_targets()
170165

171166
# For standalone builds we need to install the ctest files
172167
install_miopen_legacy_plugin_ctest_files()

0 commit comments

Comments
 (0)