Skip to content

Commit c5ab56c

Browse files
authored
[hipDNN] Use regular FlatBuffers dependency install (ROCm#8092)
## Summary This PR follows up on [PR ROCm#8026](ROCm#8026) by removing `hipdnn_flatbuffers_sdk`'s standalone/local dependency vendoring path. Fetched FlatBuffers now participates in the normal dependency install flow, and the installed flatbuffers SDK package resolves FlatBuffers through `find_dependency(flatbuffers REQUIRED)` instead of exporting or copying dependency headers itself. ## Risk Assessment Medium risk. This changes standalone hipDNN install/package layout for locally fetched FlatBuffers, but keeps the build-time dependency resolution model and consumer CMake dependency declarations intact; focused install and external-consumer validation passed for both local-fetch and `/opt/rocm` FlatBuffers paths. ## Testing Summary - Verified standalone hipDNN configure/build/install with local FlatBuffers and nlohmann fetch forced by disabling system package lookup. - Verified standalone hipDNN configure/build/install with FlatBuffers resolved from `/opt/rocm` and nlohmann fetched locally. - Confirmed installed package layout keeps dependency package configs/headers separate from `hipdnn_flatbuffers_sdk` and exports only the hipDNN target. - Verified external installed-package consumers configure/build against `hipdnn_flatbuffers_sdk` and `hipdnn_frontend`, including the `/opt/rocm` FlatBuffers path. ## Testing Checklist - [x] Standalone local-fetch configure - `cmake -G Ninja -DCMAKE_DISABLE_FIND_PACKAGE_flatbuffers=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_nlohmann_json=TRUE -DCMAKE_INSTALL_PREFIX=/tmp/hipdnn-install /home/sareeder/ROCm-workspace/repos/rocm-libraries/projects/hipdnn` - ASICs: gfx90a - Status: Passed - [x] Standalone local-fetch build/install - `cd /tmp/hipdnn-build && ninja && cmake --install .` - ASICs: gfx90a - Status: Passed - [x] Installed package layout validation - checked dependency package configs/headers, absence of vendored dependency headers under `include/hipdnn/flatbuffers_sdk`, and `hipdnn_flatbuffers_sdkTargets.cmake` exporting only `hipdnn_flatbuffers_sdk` - Status: Passed - [x] Installed consumer configure/build - `cd /tmp/test-consumer-build && cmake -G Ninja /tmp/test-consumer && ninja` - ASICs: gfx90a - Status: Passed - [x] `/opt/rocm` FlatBuffers build/install and consumer - Docker `hipdnn_env:fullbuild_20260602_gfx90a`; hipDNN configured with `-DCMAKE_PREFIX_PATH=/opt/rocm`, installed, then consumer configured/built/run with `-DCMAKE_PREFIX_PATH="/tmp/hipdnn-optfb-install;/opt/rocm"` - Status: Passed - [ ] PR CI - GitHub PR checks - Status: Pending ## Technical Changes - Removes `hipdnn_flatbuffers_sdk` local dependency export/include bundling machinery and deletes the local-only package config template. - Exports and installs only the `hipdnn_flatbuffers_sdk` target from `hipdnn_flatbuffers_sdkTargets.cmake`. - Uses the installed-package `flatbuffers::flatbuffers` target spelling during local fetch builds by aliasing the fetched `FlatBuffers` target for build-time include propagation. - Enables regular FlatBuffers install participation in `Dependencies.cmake` by building/installing the FlatBuffers package target and not excluding the fetched subdirectory from parent install rules.
1 parent f3a04f0 commit c5ab56c

5 files changed

Lines changed: 15 additions & 110 deletions

File tree

projects/hipdnn/cmake/Dependencies.cmake

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function(_fetch_flatbuffers VERSION HASH)
177177

178178
set(FLATBUFFERS_BUILD_FLATC ON)
179179
set(FLATBUFFERS_INSTALL ON)
180-
set(FLATBUFFERS_BUILD_FLATLIB OFF)
180+
set(FLATBUFFERS_BUILD_FLATLIB ON)
181181
set(FLATBUFFERS_BUILD_TESTS OFF)
182182
set(FLATBUFFERS_BUILD_FLATHASH OFF)
183183
set(FLATBUFFERS_ENABLE_PCH ON)
@@ -199,11 +199,6 @@ function(_fetch_flatbuffers VERSION HASH)
199199
_restore_var(FLATBUFFERS_BUILD_FLATHASH)
200200
_restore_var(FLATBUFFERS_ENABLE_PCH)
201201

202-
set(HIP_DNN_FLATBUFFERS_INCLUDE_DIR ${flatbuffers_SOURCE_DIR}/include
203-
CACHE PATH "Path to flatbuffers include"
204-
)
205-
206-
_exclude_from_all(${flatbuffers_SOURCE_DIR})
207202
_mark_targets_as_system(${flatbuffers_SOURCE_DIR})
208203
endfunction()
209204

projects/hipdnn/flatbuffers_sdk/CMakeLists.txt

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -49,57 +49,13 @@ if(NOT HIPDNN_FLATBUFFERS_SDK_SKIP_JSON_LIB AND NOT TARGET nlohmann_json::nlohma
4949
hipdnn_add_dependency(nlohmann_json VERSION ${HIPDNN_NLOHMANN_JSON_VERSION})
5050
endif()
5151

52-
# --- Dependency processing ---
53-
set(_hipdnn_flatbuffers_sdk_local_export_targets)
54-
set(_hipdnn_flatbuffers_sdk_local_export_includes)
5552

56-
# Function to process flatbuffers_sdk dependencies and populate local export lists.
57-
# TARGET_NAME - The actual target name (e.g., FlatBuffers)
58-
# ALIAS_NAME - The alias target name (e.g., flatbuffers::flatbuffers)
59-
# INCLUDE_DIR - Optional parent include directory to bundle with the install
60-
function(_hipdnn_flatbuffers_sdk_process_dependency TARGET_NAME ALIAS_NAME)
61-
set(options "")
62-
set(oneValueArgs INCLUDE_DIR)
63-
set(multiValueArgs "")
64-
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
65-
66-
if(NOT TARGET ${TARGET_NAME})
67-
return()
68-
endif()
69-
70-
if(NOT TARGET ${ALIAS_NAME})
71-
add_library(${ALIAS_NAME} ALIAS ${TARGET_NAME})
72-
endif()
73-
74-
get_target_property(_is_imported ${TARGET_NAME} IMPORTED)
75-
if(NOT _is_imported)
76-
list(APPEND _hipdnn_flatbuffers_sdk_local_export_targets ${TARGET_NAME})
77-
set(_hipdnn_flatbuffers_sdk_local_export_targets ${_hipdnn_flatbuffers_sdk_local_export_targets} PARENT_SCOPE)
78-
79-
if(ARG_INCLUDE_DIR)
80-
list(APPEND _hipdnn_flatbuffers_sdk_local_export_includes ${ARG_INCLUDE_DIR})
81-
set(_hipdnn_flatbuffers_sdk_local_export_includes ${_hipdnn_flatbuffers_sdk_local_export_includes} PARENT_SCOPE)
82-
endif()
83-
endif()
84-
endfunction()
85-
86-
if(TARGET FlatBuffers)
87-
# Workaround: flatbuffers sets INSTALL_INTERFACE to include/include which resolves incorrectly.
88-
# Force it to the correct install path for hipdnn_flatbuffers_sdk.
89-
get_target_property(_is_imported FlatBuffers IMPORTED)
90-
if(NOT _is_imported)
91-
get_target_property(current_includes FlatBuffers INTERFACE_INCLUDE_DIRECTORIES)
92-
list(REMOVE_ITEM current_includes "$<INSTALL_INTERFACE:include/include>")
93-
list(APPEND current_includes "$<INSTALL_INTERFACE:${HIP_DNN_FLATBUFFERS_SDK_INSTALL_INCLUDE_DIR}>")
94-
set_target_properties(
95-
FlatBuffers PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${current_includes}"
96-
)
97-
endif()
98-
_hipdnn_flatbuffers_sdk_process_dependency(
99-
FlatBuffers flatbuffers::flatbuffers INCLUDE_DIR ${HIP_DNN_FLATBUFFERS_INCLUDE_DIR}
100-
)
53+
# Upstream FlatBuffers exposes FlatBuffers when fetched via add_subdirectory,
54+
# while its installed package exposes flatbuffers::flatbuffers. Use the installed-package
55+
# spelling internally so the build and exported config follow the same dependency model.
56+
if(TARGET FlatBuffers AND NOT TARGET flatbuffers::flatbuffers)
57+
add_library(flatbuffers::flatbuffers ALIAS FlatBuffers)
10158
endif()
102-
10359
# --- Create the library target ---
10460
add_library(hipdnn_flatbuffers_sdk INTERFACE)
10561

@@ -180,13 +136,11 @@ if(HIPDNN_GENERATE_SDK_HEADERS)
180136
endif()
181137

182138
# --- Export and install ---
183-
export(TARGETS hipdnn_flatbuffers_sdk ${_hipdnn_flatbuffers_sdk_local_export_targets}
139+
export(TARGETS hipdnn_flatbuffers_sdk
184140
FILE "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk/hipdnn_flatbuffers_sdkTargets.cmake"
185141
)
186142

187-
install(TARGETS hipdnn_flatbuffers_sdk ${_hipdnn_flatbuffers_sdk_local_export_targets}
188-
EXPORT hipdnn_flatbuffers_sdk_targets COMPONENT Development
189-
)
143+
install(TARGETS hipdnn_flatbuffers_sdk EXPORT hipdnn_flatbuffers_sdk_targets COMPONENT Development)
190144

191145
# cmake-lint: disable=E1122
192146
install(
@@ -210,30 +164,11 @@ install(EXPORT hipdnn_flatbuffers_sdk_targets DESTINATION ${CMAKE_INSTALL_LIBDIR
210164
FILE hipdnn_flatbuffers_sdkTargets.cmake COMPONENT Development
211165
)
212166

213-
# Install behavior depends on local vs imported dependencies
214-
if(_hipdnn_flatbuffers_sdk_local_export_includes)
215-
# cmake-lint: disable=E1122
216-
install(
217-
DIRECTORY ${_hipdnn_flatbuffers_sdk_local_export_includes}/
218-
DESTINATION ${HIP_DNN_FLATBUFFERS_SDK_INSTALL_INCLUDE_DIR}
219-
COMPONENT Development
220-
FILES_MATCHING
221-
PATTERN "*.h"
222-
PATTERN "*.hpp"
223-
PATTERN "codegen" EXCLUDE
224-
)
225-
configure_package_config_file(
226-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/hipdnn_flatbuffers_sdkConfig_local.cmake.in"
227-
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk/hipdnn_flatbuffers_sdkConfig.cmake"
228-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk
229-
)
230-
else()
231-
configure_package_config_file(
232-
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/hipdnn_flatbuffers_sdkConfig_imported.cmake.in"
233-
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk/hipdnn_flatbuffers_sdkConfig.cmake"
234-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk
235-
)
236-
endif()
167+
configure_package_config_file(
168+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/hipdnn_flatbuffers_sdkConfig.cmake.in"
169+
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk/hipdnn_flatbuffers_sdkConfig.cmake"
170+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipdnn_flatbuffers_sdk
171+
)
237172

238173
# Generate package version file for find_package version checking
239174
write_basic_package_version_file(

projects/hipdnn/flatbuffers_sdk/cmake/hipdnn_flatbuffers_sdkConfig_imported.cmake.in renamed to projects/hipdnn/flatbuffers_sdk/cmake/hipdnn_flatbuffers_sdkConfig.cmake.in

File renamed without changes.

projects/hipdnn/flatbuffers_sdk/cmake/hipdnn_flatbuffers_sdkConfig_local.cmake.in

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

projects/hipdnn/flatbuffers_sdk/cmake/hipdnn_flatbuffers_version_check.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# SPDX-License-Identifier: MIT
33

44
# Shared FlatBuffers version validation, used by both the in-tree
5-
# flatbuffers_sdk/CMakeLists.txt at build time and by the installed imported
6-
# Config (hipdnn_flatbuffers_sdkConfig_imported.cmake.in) at consumer
5+
# flatbuffers_sdk/CMakeLists.txt at build time and by the installed
6+
# hipdnn_flatbuffers_sdkConfig.cmake package config at consumer
77
# find_package() time. Single-sourcing the comparison and core message keeps
88
# the two call sites from drifting.
99
#

0 commit comments

Comments
 (0)