Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put saveguard to avoid defining target more than once #125

Open
wants to merge 1 commit into
base: amd-staging
Choose a base branch
from

Conversation

mtaillefumier
Copy link

  • set the INTERFACE_INCLUDE_DIRECTORIES property
  • These safeguards are needed when the CMakeLists.txt contains:
enable_language(HIP)
find_package(hipblas)

In that case add_library is called twice.

These safeguards are needed when the CMakeLists.txt contains:

enable_language(HIP)
find_package(hipblas)

In that case add_library is called twice.
@iassiour
Copy link
Contributor

Hi @mtaillefumier would it be possible to provide a few more details i.e attach a full reproducer and some logs of the error you are getting, if any. Are you trying to build for nvidia platform?

@mtaillefumier
Copy link
Author

mtaillefumier commented Jan 30, 2025

I am using hipblas, hipfft, and hip on nvidia platforms. the minimal reproducer is this block of code

cmake_minimum_required(VERSION 3.28)

project(hip-cuda-test)

set(CMAKE_HIP_ARCHITECTURES 90)
set(CMAKE_HIP_PLATFORM "nvidia")
enable_language(HIP)
find_package(CUDAToolkit)
find_package(hipblas REQUIRED IMPORTED CONFIG)
find_package(hipfft REQUIRED IMPORTED CONFIG)

cuda should be available before running cmake. If cmake is called with this CMakeLists.txt , we get

CMake Error at /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::device" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hipfft-6.3.0-6qywxfcm6hxqxoo6fbk6v6op5eik7du2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  CMakeLists.txt:10 (find_package)

CMake Error at /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::host" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hipfft-6.3.0-6qywxfcm6hxqxoo6fbk6v6op5eik7du2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  CMakeLists.txt:10 (find_package)
CMake Error at /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config-nvidia.cmake:23 (add_library):
  add_library cannot create imported target "hip::amdhip64" because another
  target with the same name already exists.
Call Stack (most recent call first):
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hip-6.3.0-n7hw6bc7wzyvb4e6gn4wn4mcfgpreywx/lib/cmake/hip/hip-config.cmake:153 (include)
  /usr/share/cmake/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
  /opt/spack/linux-fedora41-cascadelake/gcc-13.3.0/hipfft-6.3.0-6qywxfcm6hxqxoo6fbk6v6op5eik7du2/lib/cmake/hipfft/hipfft-config.cmake:90 (find_dependency)
  CMakeLists.txt:10 (find_package)

Moreover even if it passes adding the defined targets will not add the include directories paths which is also an issue.
Guarding around a add_library is required because the same config file can be called multiple times over by different packages. This problem only happen with hip/nvidia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants