1
11
编译器
cmakelist编写相关
2024-10-28 16:33:00
103
cmake_minimum_required(VERSION 3.10)

if(NOT DEFINED HIP_PATH)
    if(NOT DEFINED ENV{HIP_PATH})
        set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
    else()
        set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
    endif()
endif()

# 设置 CMake 模块路径
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})

project(HipVectorAdd LANGUAGES HIP CXX)


# set(CMAKE_MODULE_PATH "/opt/dtk-23.10.1/hip/cmake" ${CMAKE_MODULE_PATH})

# Enable HIP support
find_package(HIP REQUIRED)
if(HIP_FOUND)
    message(STATUS "Found HIP: " ${HIP_VERSION})
else()
    message(FATAL_ERROR "Could not find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location.")
endif()

# Specify HIP flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_HIP_ARCHITECTURES "gfx1032;gfx1035")  # 根据目标GPU架构设置

# Add executable
add_executable(hip_vector_add ./src/main.cpp ./src/hip_functions.hip)

# Link HIP library
target_link_libraries(hip_vector_add PRIVATE hip::device)
target_compile_features(hip_vector_add PRIVATE cxx_std_11)

CMake Error at CMakeLists.txt:32 (add_executable):
Target "hip_vector_add" links to target "hip::device" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?

上述构建过程报错,请帮忙看看写的哪里有问题吗

全部评论(2)
只看楼主
C
chenxi
1楼
这里有打印HIP信息吗?export HIP_PATH=/opt/dtk/hip试试呢
2024/10/28
网
网友9lSqax
回复 @chenxi

cmake -B./cmake-build-hip -S./ -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=/opt/dtk-23.10.1/bin/hipcc -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"

-- The HIP compiler identification is Clang 15.0.0

-- The CXX compiler identification is Clang 15.0.0

-- Detecting HIP compiler ABI info

-- Detecting HIP compiler ABI info - done

-- Check for working HIP compiler: /opt/dtk-23.10.1/llvm/bin/clang++ - skipped

-- Detecting HIP compile features

-- Detecting HIP compile features - done

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Check for working CXX compiler: /opt/dtk-23.10.1/bin/hipcc - skipped

-- Detecting CXX compile features

-- Detecting CXX compile features - done

-- Found HIP: /opt/dtk-23.10.1/hip (found version "5.4.23453")

-- Performing Test HIP_CLANG_SUPPORTS_PARALLEL_JOBS

-- Performing Test HIP_CLANG_SUPPORTS_PARALLEL_JOBS - Success

-- Found HIP: 5.4.23453

-- Configuring done

CMake Error at CMakeLists.txt:32 (add_executable):

Target "hip_vector_add" links to target "hip::device" but the target was

not found. Perhaps a find_package() call is missing for an IMPORTED

target, or an ALIAS target is missing?

-- Generating done

CMake Generate step failed. Build files cannot be regenerated correctly.
2024/10/28
没有更多内容了
--
楼主
Level.1
0 帖子
楼主热帖
暂无数据