Skip to content

Commit d41edca

Browse files
authored
Initial HIP binding build support using headers from standard HIP install (#7867)
* Add upstream HIP as submodule to get header file definitions * A simple vadd example for hip * Added support for installing hip-dev -- which provides the official HIP header files -- from the Linux distribution * Updated build infra to use HIP header files from HIP install area * Add comment about defining __HIP_PLATFORM_AMD__ * Drop installation of hip.h file * Minor code adjustments Signed-off-by: Sonal Santan <[email protected]> * DCO Remediation Commit for Sonal Santan <[email protected]> I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: a91d26b I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: d384c9f I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: 5076b02 I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: a394207 I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: ab75f5c I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: 18de09c Signed-off-by: Sonal Santan <[email protected]> * Improve the cmake handling of HIP for XRT to reduce warning messages Enable building of HIP tests for XRT along with xrt and unit_test * Remove redundant directory for vadd * Code updates to address style issues Add CMake based build of hip testcases Signed-off-by: Sonal Santan <[email protected]> * DCO Remediation Commit for Sonal Santan <[email protected]> I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: 747b2f3 I, Sonal Santan <[email protected]>, hereby add my Signed-off-by to this commit: dc9eabf Signed-off-by: Sonal Santan <[email protected]> * Drop usage of boost in hip testcases Signed-off-by: Sonal Santan <[email protected]> * Change the PASS/FAIL string to XRT standard Signed-off-by: Sonal Santan <[email protected]> --------- Signed-off-by: Sonal Santan <[email protected]>
1 parent 95db0f3 commit d41edca

File tree

21 files changed

+579
-43
lines changed

21 files changed

+579
-43
lines changed

src/CMake/nativeLnx.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ set(XRT_BOOST_VERSION ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBM
123123
include_directories(${Boost_INCLUDE_DIRS})
124124
add_compile_options("-DBOOST_LOCALE_HIDE_AUTO_PTR")
125125

126-
# -- Cursers ---
126+
# --- Curses ---
127127
INCLUDE (FindCurses)
128128
find_package(Curses REQUIRED)
129129

130+
# --- Optional HIP bindings ---
131+
if (XRT_ENABLE_HIP)
132+
message("-- Looking for HIP include files...")
133+
# We should find HIP cmake either in standard cmake locations or in the /opt/rocm location
134+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};/opt/rocm/lib/cmake/hip")
135+
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/opt/rocm/lib/cmake/amd_comgr;/opt/rocm/lib/cmake/hsa-runtime64")
136+
include(hip-config)
137+
message("-- Found at ${HIP_INCLUDE_DIR}")
138+
endif()
139+
130140
# --- XRT Variables ---
131141
set (XRT_INSTALL_DIR "xrt")
132142
set (XRT_INSTALL_BIN_DIR "${XRT_INSTALL_DIR}/bin")

src/runtime_src/hip/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ install(TARGETS xrt_hip
3737

3838
# Release headers
3939
install (FILES
40-
hip.h
4140
config.h
4241
DESTINATION ${XRT_INSTALL_INCLUDE_DIR}/hip
4342
COMPONENT ${XRT_DEV_COMPONENT}

src/runtime_src/hip/api/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ add_library(hip_api_library_objects OBJECT
77
target_include_directories(hip_api_library_objects
88
PRIVATE
99
${XRT_SOURCE_DIR}/runtime_src
10+
${HIP_INCLUDE_DIRS}
1011
)
11-

src/runtime_src/hip/api/hipDeviceGet.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2023 Advanced Micro Device, Inc. All rights reserved.
3-
#include "hip/hip.h"
3+
4+
#include "hip/config.h"
5+
#include "hip/hip_runtime_api.h"
46
#include "hip/core/device.h"
57

68
#include "core/common/error.h"
@@ -14,7 +16,7 @@ hipDeviceGet(hipDevice_t* device, int ordinal)
1416
{
1517
throw std::runtime_error("Not implemented");
1618
}
17-
19+
1820
} // xrt::core::hip
1921

2022

src/runtime_src/hip/config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
//------------------Enable dynamic linking on windows-------------------------//
77

8+
// We need to define either __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA for HIP header
9+
// files to stand; see hip/hip_runtime_api.h
10+
11+
#define __HIP_PLATFORM_AMD__
12+
13+
// Currently the following are not used since we are using HIP header files from standard
14+
// HIP install area
15+
816
#ifdef _WIN32
917
# ifdef XRTHIP_SOURCE
1018
# define XRTHIP_EXPORT __declspec(dllexport)

src/runtime_src/hip/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ add_library(hip_core_library_objects OBJECT
77
target_include_directories(hip_core_library_objects
88
PRIVATE
99
${XRT_SOURCE_DIR}/runtime_src
10+
${HIP_INCLUDE_DIRS}
1011
)
11-
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2023 Advanced Micro Device, Inc. All rights reserved.
3+
34
#include "device.h"
45

56
namespace xrt::core::hip {
67

7-
// Implementation
8-
8+
// Implementation
9+
910
}

src/runtime_src/hip/hip.h

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

src/runtime_src/tools/scripts/xrtdeps.sh

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,57 @@ prep_alma()
641641
fi
642642
}
643643

644+
install_pybind11()
645+
{
646+
echo "Installing pybind11..."
647+
if [ $FLAVOR == "mariner" ]; then
648+
sudo dnf install -y pybind11-devel python3-pybind11
649+
elif [ $FLAVOR == "ubuntu" ] && [ $MAJOR -ge 23 ]; then
650+
apt-get install -y pybind11-dev
651+
else
652+
# Install/upgrade pybind11 for building the XRT python bindings
653+
# We need 2.6.0 minimum version
654+
pip3 install -U pybind11
655+
fi
656+
}
657+
658+
install_hip()
659+
{
660+
# For building HIP bindings for XRT an install of ROCm HIP is required; install HIP if
661+
# supported by the Linux distribution
662+
if [ $FLAVOR == "ubuntu" ]; then
663+
# Check if ROCm has already been manually installed by the user
664+
dpkg-query -s hip-dev
665+
if [ $? == 0 ]; then
666+
echo "hip-dev already installed..."
667+
dpkg-query -L hip-dev | grep hip/hip_runtime_api.h
668+
elif [ $MAJOR -ge 23 ]; then
669+
# From Ubuntu 23.04 (lunar) onwards, a version of HIP devel tools is bundled--
670+
# https://packages.ubuntu.com/
671+
apt-get install -y libamdhip64-dev
672+
else
673+
echo "Manual installation of HIP is required, please follow instructions on ROCm website--"
674+
echo "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/install-overview.html"
675+
fi
676+
elif [ $FLAVOR == "fedora" ]; then
677+
rpm -q hip-devel
678+
if [ $? == 0 ]; then
679+
echo "hip-devel already installed..."
680+
rpm -q -l hip-devel | grep hip/hip_runtime_api.h
681+
elif [ $MAJOR -ge 38 ]; then
682+
# From version 38 onwards, a version of HIP devel tools is bundled--
683+
# https://packages.fedoraproject.org/pkgs/rocclr/hip-devel/
684+
yum install -y hip-devel
685+
else
686+
echo "Manual installation of HIP is required, please follow instructions on ROCm website--"
687+
echo "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/install-overview.html"
688+
fi
689+
else
690+
echo "Manual installation of HIP is required, please follow instructions on ROCm website--"
691+
echo "https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/install-overview.html"
692+
fi
693+
}
694+
644695
install()
645696
{
646697
if [ $FLAVOR == "ubuntu" ] || [ $FLAVOR == "debian" ]; then
@@ -703,14 +754,9 @@ install()
703754
dnf install -y "${MN_LIST[@]}"
704755
fi
705756

706-
if [ $FLAVOR == "mariner" ]; then
707-
echo "Installing pybind..."
708-
sudo dnf install -y pybind11-devel python3-pybind11
709-
else
710-
# Install/upgrade pybind11 for building the XRT python bindings
711-
# We need 2.6.0 minimum version
712-
pip3 install -U pybind11
713-
fi
757+
install_pybind11
758+
759+
install_hip
714760
}
715761

716762
update_package_list

tests/.clangd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CompileFlags:
2+
CompilationDatabase: build

0 commit comments

Comments
 (0)