Skip to content

Commit

Permalink
Enable HIP build in windows (#8110)
Browse files Browse the repository at this point in the history
* Enable HIP build in windows

> make changes to cmake files to enable HIP build on windows
> Fix compilation errors
> Tested xrt_flow using HIP apis on phoenix using MCDM flow

Signed-off-by: rbramand <[email protected]>

* Add hip.cmake config file with hip related configs

Signed-off-by: rbramand <[email protected]>

* Add proper path for hip.cmake inclusion when XRT is submodule

Signed-off-by: rbramand <[email protected]>

* Move hip_config.cmake to hip folder

Signed-off-by: rbramand <[email protected]>

---------

Signed-off-by: rbramand <[email protected]>
Co-authored-by: rbramand <[email protected]>
  • Loading branch information
rbramand-xilinx and rbramand authored May 6, 2024
1 parent cad380f commit d9b3373
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 27 deletions.
8 changes: 6 additions & 2 deletions build/build22.bat
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ IF DEFINED MSVC_PARALLEL_JOBS ( SET LOCAL_MSVC_PARALLEL_JOBS=%MSVC_PARALLEL_JOBS
) else (
if [%1] == [-nocmake] (
set NOCMAKE=1
) else (
if [%1] == [-hip] (
set CMAKEFLAGS=%CMAKEFLAGS% -DXRT_ENABLE_HIP=ON
) else (
echo Unknown option: %1
goto Help
))))))))))))
)))))))))))))
shift
goto parseArgs

:argsParsed

set CMAKEFLAGS=-DMSVC_PARALLEL_JOBS=%LOCAL_MSVC_PARALLEL_JOBS% -DKHRONOS=%EXT_DIR% -DBOOST_ROOT=%EXT_DIR% -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
set CMAKEFLAGS=%CMAKEFLAGS% -DMSVC_PARALLEL_JOBS=%LOCAL_MSVC_PARALLEL_JOBS% -DKHRONOS=%EXT_DIR% -DBOOST_ROOT=%EXT_DIR% -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ECHO CMAKEFLAGS=%CMAKEFLAGS%

if [%DEBUG%] == [1] (
Expand Down Expand Up @@ -99,6 +102,7 @@ ECHO [-xclmgmt arg] - The directory to the xclmgmt drivers (used wit
ECHO [-xocluser arg] - The directory to the xocluser drivers (used with [-package])
ECHO [-xclmgmt2 arg] - The directory to the xclmgmt2 drivers (used with [-package])
ECHO [-xocluser2 arg] - The directory to the xocluser2 drivers (used with [-package])
ECHO [-hip] - Enable hip library build
GOTO:EOF

REM --------------------------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions src/CMake/nativeLnx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ add_compile_options("-DBOOST_LOCALE_HIDE_AUTO_PTR")
INCLUDE (FindCurses)
find_package(Curses REQUIRED)

# --- Optional HIP bindings ---
if (XRT_ENABLE_HIP)
message("-- Looking for HIP include files...")
# We should find HIP cmake either in standard cmake locations or in the /opt/rocm location
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};/usr/lib/x86_64-linux-gnu/cmake/hip;/opt/rocm/lib/cmake/hip")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/lib/x86_64-linux-gnu/cmake/amd_comgr;/usr/lib/x86_64-linux-gnu/cmake/hsa-runtime64;/opt/rocm/lib/cmake/amd_comgr;/opt/rocm/lib/cmake/hsa-runtime64")
include(hip-config)
message("-- Found at ${HIP_INCLUDE_DIR}")
endif()

# --- XRT Variables ---
set (XRT_INSTALL_DIR "xrt")
set (XRT_INSTALL_BIN_DIR "${XRT_INSTALL_DIR}/bin")
Expand Down
6 changes: 6 additions & 0 deletions src/runtime_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if (XRT_DKMS_ALVEO STREQUAL "ON")
xrt_add_subdirectory(ert)
endif()

# --- Optional HIP bindings ---
if (XRT_ENABLE_HIP)
xrt_add_subdirectory(hip)
endif(XRT_ENABLE_HIP)
Expand Down Expand Up @@ -81,4 +82,9 @@ else()
xrt_add_subdirectory(xdp)
xrt_add_subdirectory(tools/scripts)
xrt_add_subdirectory(core)

# --- Optional HIP bindings ---
if (XRT_ENABLE_HIP)
xrt_add_subdirectory(hip)
endif(XRT_ENABLE_HIP)
endif()
19 changes: 15 additions & 4 deletions src/runtime_src/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2023 Advanced Micro Device, Inc. All rights reserved.

# config file for getting hip headers
include(hip_config.cmake)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
find_program(CLANG_TIDY "clang-tidy")
if(NOT CLANG_TIDY)
Expand All @@ -14,10 +17,18 @@ endif()
add_subdirectory(core)
add_subdirectory(api)

add_library(xrt_hip SHARED
$<TARGET_OBJECTS:hip_core_library_objects>
$<TARGET_OBJECTS:hip_api_library_objects>
)
if (WIN32)
add_library(xrt_hip SHARED
$<TARGET_OBJECTS:hip_core_library_objects>
$<TARGET_OBJECTS:hip_api_library_objects>
xrt_hip.def
)
else()
add_library(xrt_hip SHARED
$<TARGET_OBJECTS:hip_core_library_objects>
$<TARGET_OBJECTS:hip_api_library_objects>
)
endif()

target_include_directories(xrt_hip
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/hip/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# else
# define XRTHIP_EXPORT __declspec(dllimport)
# endif
# pragma warning( disable : 4201 4267 4100)
#endif
#ifdef __GNUC__
# ifdef XRTHIP_SOURCE
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/hip/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#ifndef xrthip_device_h
#define xrthip_device_h

#ifdef _WIN32
#undef max
#endif

#include "core/common/api/handle.h"
#include "xrt/xrt_device.h"

Expand Down
5 changes: 4 additions & 1 deletion src/runtime_src/hip/core/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "xrt/device/hal.h"
#include "xrt/util/range.h"

#include "hip/config.h"
#include "hip/hip_runtime_api.h"

namespace xrt::core::hip
{
class error
Expand Down Expand Up @@ -45,4 +48,4 @@ namespace xrt::core::hip
hipError_t m_last_error;
}; // class error
}
#endif // xrthip_error_h
#endif // xrthip_error_h
4 changes: 2 additions & 2 deletions src/runtime_src/hip/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace xrt::core::hip
return std::pair(nullptr, 0);
}
else {
auto offset = reinterpret_cast<uint64_t>(addr) - reinterpret_cast<uint64_t>(itr->first.address);
auto offset = reinterpret_cast<uint64_t>(addr) - itr->first.address;
return {itr->second, offset};
}
}
Expand All @@ -203,7 +203,7 @@ namespace xrt::core::hip
return std::pair(nullptr, 0);
}
else {
auto offset = reinterpret_cast<uint64_t>(addr) - reinterpret_cast<uint64_t>(itr->first.address);
auto offset = reinterpret_cast<uint64_t>(addr) - itr->first.address;
return {itr->second, offset};
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/runtime_src/hip/hip_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.

message("-- Looking for HIP include files...")
if (NOT WIN32)
# We should find HIP cmake either in standard cmake locations or in the /opt/rocm location
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/lib/x86_64-linux-gnu/cmake/hip;/usr/lib/x86_64-linux-gnu/cmake/amd_comgr;/opt/rocm/lib/cmake/hip;/opt/rocm/lib/cmake/amd_comgr")
# hip-config itself requires these other directories to find its dependencies
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/lib/x86_64-linux-gnu/cmake/hip;/usr/lib/x86_64-linux-gnu/cmake/amd_comgr;/usr/lib/x86_64-linux-gnu/cmake/hsa-runtime64;/opt/rocm/lib/cmake/hip;/opt/rocm/lib/cmake/amd_comgr;/opt/rocm/lib/cmake/hsa-runtime64")
else ()
set(HIP_PLATFORM "amd")
# HIP SDK installs hip files to C:/Program Files/AMD/ROCm
# Latest version available on windows is 5.7
# Users can set HIP_DIR to location of HIP installation or default path is used
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} $ENV{HIP_DIR} "C:/Program Files/AMD/ROCm/5.7/lib/cmake/hip")
endif ()

include(hip-config)
message("-- Found at ${HIP_INCLUDE_DIR}")
50 changes: 50 additions & 0 deletions src/runtime_src/hip/xrt_hip.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
; SPDX-License-Identifier: Apache-2.0
; Copyright (C) 2023-2024 Advanced Micro Device, Inc. All rights reserved.
LIBRARY xrt_hip
EXPORTS
hipCtxCreate
hipCtxDestroy
hipCtxGetDevice
hipCtxSetCurrent
hipDevicePrimaryCtxRetain
hipDevicePrimaryCtxRelease
hipInit
hipGetDeviceCount
hipDeviceGet
hipDeviceGetName
hipGetDeviceProperties
hipDeviceGetUuid
hipDeviceGetAttribute
hipDrvGetErrorName
hipDrvGetErrorString
hipGetErrorString
hipGetErrorName
hipExtGetLastError
hipGetLastError
hipPeekAtLastError
hipEventCreate
hipEventDestroy
hipEventSynchronize
hipEventRecord
hipEventQuery
hipEventElapsedTime
hipMalloc
hipHostMalloc
hipHostFree
hipFree
hipHostRegister
hipHostUnregister
hipHostGetDevicePointer
hipMemcpy
hipMemset
hipMemcpyHtoDAsync
hipModuleLaunchKernel
hipModuleGetFunction
hipModuleLoadData
hipModuleLoadDataEx
hipModuleUnload
hipFuncSetAttribute
hipStreamCreateWithFlags
hipStreamDestroy
hipStreamSynchronize
hipStreamWaitEvent
2 changes: 1 addition & 1 deletion tests/CMake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(XILINX_VITIS $ENV{XILINX_VITIS})
if(NOT VITIS_COMPILER)
find_program(VITIS_COMPILER
NAMES v++
HINTS XILINX_VITIS}
HINTS $ENV{XILINX_VITIS}
)
if(VITIS_COMPILER)
message("Vitis Compiler is found at ${VITIS_COMPILER}")
Expand Down
9 changes: 2 additions & 7 deletions tests/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ if (NOT DEFINED ${INSTALL_DIR})
set(INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE}/${MODE}")
endif()

message("-- Looking for HIP include files...")
# We should find HIP cmake either in standard cmake locations or in the /opt/rocm location
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/lib/x86_64-linux-gnu/cmake/hip;/usr/lib/x86_64-linux-gnu/cmake/amd_comgr;/opt/rocm/lib/cmake/hip;/opt/rocm/lib/cmake/amd_comgr")
# hip-config itself requires these other directories to find its dependencies
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr/lib/x86_64-linux-gnu/cmake/hip;/usr/lib/x86_64-linux-gnu/cmake/amd_comgr;/usr/lib/x86_64-linux-gnu/cmake/hsa-runtime64;/opt/rocm/lib/cmake/hip;/opt/rocm/lib/cmake/amd_comgr;/opt/rocm/lib/cmake/hsa-runtime64")
include(hip-config)
message("-- Found at ${HIP_INCLUDE_DIR}")
# config file for getting hip headers
include(${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime_src/hip/hip_config.cmake)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
find_program(CLANG_TIDY "clang-tidy")
Expand Down

0 comments on commit d9b3373

Please sign in to comment.