Skip to content

Commit

Permalink
Build improvements (#30)
Browse files Browse the repository at this point in the history
* hiprtc: vs: copy additional libraries to output directory

Besides hiprtc*.dll, hiprtc-builtins*.dll and amd_comgr*.dll is also required.

In this commit, the PostBuildAction is also replaced by a Content statement. This
provides more robustness in the build system, as using this method there will be
no race conditions if two targets copy the same file to the output directory.

* Resolve "Multi-GPU error occured while hip_opengl_interop sample application is executed"

* vs: copy dynamic libraries for other examples as well

If a library links with a dynamic library, the corresponding dll file
should be placed in the output directory so that the library can be found
even if the ROCm binary path is not added to the system PATH. The solution
used is the same as that used for the HIPRTC example.

* cmake: disable static_host_library on windows

The HIP SDK does at this time not ship with a binary for CMAKE_AR, which is required
to compile this example.

* ci: do not rely on PATH

Removing the ROCm binary path from the global PATH allows us to check
that the examples do not depend on this. The CMakeFile for each example
does currently not copy the libraries to the build directory, and so
for running the tests using CTest the library path is still required.

* Resolve "cmake: windows + nvidia does not pass hip includes to include list"

* Resolve "cmake: make examples use install()"

* Resolve "hipBLAS examples' Makefiles do not work with CUDA"

* cuda dockerfile: replace ARG with GID

* Resolve "Windows CI with Nvidia"

* Fix VS copied dependencies for HIP

---------

Co-authored-by: Nara Prasetya <[email protected]>
Co-authored-by: Máté Ferenc Nagy-Egri <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2023
1 parent d20eff9 commit 9c86faa
Show file tree
Hide file tree
Showing 150 changed files with 2,673 additions and 551 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
[Rr]elease
*.vcxproj.user
[Bb]uild
*.pdb
build
174 changes: 144 additions & 30 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,8 +30,7 @@ include:
- /rules.yaml

variables:
# suppressing 186 allows us to write `assert(a && "message")`.
CUDA_FLAGS: "-Xcompiler -Wall,-Wextra,-Werror --Werror all-warnings --diag-suppress 186"
CUDA_FLAGS: "-Xcompiler -Wall,-Wextra,-Werror --Werror all-warnings"
CXX_FLAGS: "-Wall -Wextra -Werror"
HIP_FLAGS: "-Wall -Wextra -Werror"

Expand Down Expand Up @@ -148,6 +147,7 @@ build:cmake-rocm:
exit 1
fi
- cmake --build $CI_PROJECT_DIR/build
- cmake --install $CI_PROJECT_DIR/build --prefix $CI_PROJECT_DIR/install

build:cmake-cuda:
image: $DOCKER_TAG_PREFIX:cuda-ubuntu
Expand All @@ -171,6 +171,7 @@ build:cmake-cuda:
exit 1
fi
- cmake --build $CI_PROJECT_DIR/build
- cmake --install $CI_PROJECT_DIR/build --prefix $CI_PROJECT_DIR/install

.test:
stage: test
Expand Down Expand Up @@ -199,25 +200,42 @@ test:cuda:
extends:
- .rules:test
stage: test
tags:
- windows
- shell
- rx6900
needs: []
parallel:
matrix:
- BUILD_TYPE: [Debug, Release]

test:rocm-windows-vs2019:
.test:rocm-windows:
extends:
- .test:windows
tags:
- windows
- shell
- rx6900

.test:windows-vs:
script:
# MSBuild cannot properly resolve the `<Content Include=` dependencies, and will sometimes try to copy
# two or more files at once. This results in a warning before it retries, which is counted towards
# /warnAsError by default. For this reason, we disable the relevant warning (MSB3026).
- >
& "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe"
& $MSBUILD
/maxCpuCount
/warnAsError
"/p:Configuration=$BUILD_TYPE"
"$CI_PROJECT_DIR/ROCm-Examples-VS2019.sln"
/warnAsError
/warnAsMessage:MSB3026
$MSBUILD_EXTRA_OPTIONS
"$CI_PROJECT_DIR/$SOLUTION"
test:rocm-windows-vs2019:
extends:
- .test:rocm-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-VS2019.sln"
script:
- !reference [".test:windows-vs", script]
- |-
$SkippedExamples = @(
"hip_vulkan_interop_vs2019.exe" # Graphical
Expand All @@ -239,44 +257,140 @@ test:rocm-windows-vs2019:
test:rocm-windows-vs2017:
extends:
- .test:windows
script:
- >
& "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe"
/maxCpuCount
/warnAsError
"/p:Configuration=$BUILD_TYPE"
"$CI_PROJECT_DIR/ROCm-Examples-VS2017.sln"
- .test:rocm-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-VS2017.sln"
# See https://developercommunity.visualstudio.com/t/windowstargetplatformversion-makes-it-impossible-t/140294
MSBUILD_EXTRA_OPTIONS: "/p:WindowsTargetPlatformVersion=10.0.20348.0"

test:rocm-windows-vs2022:
extends:
- .test:windows
script:
- >
& "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe"
/maxCpuCount
/warnAsError
"/p:Configuration=$BUILD_TYPE"
"$CI_PROJECT_DIR/ROCm-Examples-VS2022.sln"
- .test:rocm-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-VS2022.sln"

test:rocm-windows-cmake:
extends:
- .test:windows
- .test:rocm-windows
script:
- Import-Module 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
- Enter-VsDevShell -InstallPath 'C:\Program Files\Microsoft Visual Studio\2022\Community' -SkipAutomaticLocation -DevCmdArguments '/arch=x64 /host_arch=x64 /no_logo'
- cmake
-S "$CI_PROJECT_DIR"
-B "$CI_PROJECT_DIR/build"
-G Ninja
-D CMAKE_CXX_COMPILER:PATH="${env:HIP_PATH}\bin\clang++.exe"
-D CMAKE_HIP_COMPILER:PATH="${env:HIP_PATH}\bin\clang++.exe"
-D CMAKE_HIP_LINK_EXECUTABLE:PATH="${env:HIP_PATH}\bin\lld-link.exe"
-D CMAKE_HIP_FLAGS="-fuse-ld=lld"
-D CMAKE_CXX_FLAGS="$CXX_FLAGS"
-D CMAKE_CXX_COMPILER:PATH="${env:HIP_PATH}\bin\clang++.exe"
-D CMAKE_PREFIX_PATH:PATH="${env:HIP_PATH}"
-D CMAKE_HIP_FLAGS="$HIP_FLAGS"
-D CMAKE_BUILD_TYPE="$BUILD_TYPE"
-D CMAKE_HIP_ARCHITECTURES=gfx1030
-D CMAKE_RC_COMPILER="C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x64/rc.exe"
-D CMAKE_TOOLCHAIN_FILE:PATH="C:\Tools\Microsoft\vcpkg\scripts\buildsystems\vcpkg.cmake"
2>&1 | Tee-Object -filepath cmake_log.txt
- |-
if (Select-String -Path cmake_log.txt -Pattern "could not find") {
throw "Some cmake libraries are missing"
}
- cmake --build "$CI_PROJECT_DIR/build"
# CMake does not copy the dependencies to the test folder, and there is no sufficiently concise way of doing it.
# So for now, just add the library path here.
- $env:PATH = "${env:HIP_PATH}\bin;" + $env:PATH
- cd "$CI_PROJECT_DIR/build" && ctest --output-on-failure --timeout 10
- cmake --install "$CI_PROJECT_DIR/build" --prefix "$CI_PROJECT_DIR/install"

.test:nvcc-windows:
extends:
- .test:windows
tags:
- nvcc-windows
before_script:
# To test for NVIDIA, we need to set the platform toolset to HIP_nvcc. This cannot be done with /p:PlatformToolset
# though, as some examples use the regular msvc toolchain.
- |
Foreach ($f in (Get-ChildItem -Recurse -Filter "*.vcxproj" "$CI_PROJECT_DIR").FullName) {
(Get-Content $f) |
% { $_ -replace "<PlatformToolset>HIP_clang</PlatformToolset>","<PlatformToolset>HIP_nvcc</PlatformToolset>" } |
Set-Content $f
}
test:nvcc-windows-vs2019:
extends:
- .test:nvcc-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-Portable-VS2019.sln"
script:
- !reference [".test:windows-vs", script]
- |-
$SkippedExamples = @(
"hip_vulkan_interop_vs2019.exe" # Graphical
"hip_opengl_interop_vs2019.exe" # Graphical
)
Get-ChildItem -Path "$CI_PROJECT_DIR/$BUILD_TYPE" -Filter "*_vs2019.exe" |
ForEach-Object {
if ($SkippedExamples -NotContains $_.Name) {
echo "--" $_.Name
& "$CI_PROJECT_DIR/$BUILD_TYPE/$_"
if (!$?) {
throw "{0} returned: {1}" -f $_.Name, $LASTEXITCODE
}
} else {
echo "-- SKIPPING " $_.Name
}
}
test:nvcc-windows-vs2017:
extends:
- .test:nvcc-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-Portable-VS2017.sln"
# See https://developercommunity.visualstudio.com/t/windowstargetplatformversion-makes-it-impossible-t/140294
MSBUILD_EXTRA_OPTIONS: "/p:WindowsTargetPlatformVersion=10.0.20348.0"

test:nvcc-windows-vs2022:
extends:
- .test:nvcc-windows
- .test:windows-vs
variables:
MSBUILD: "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe"
SOLUTION: "ROCm-Examples-Portable-VS2022.sln"

test:nvcc-windows-cmake:
extends:
- .test:nvcc-windows
script:
# Import the VisualStudio 2022 development environment
- |-
$vs = &"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" -version 17.0 -property InstallationPath
Import-Module (Join-Path $vs "Common7/Tools/Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $vs -SkipAutomaticLocation -DevCmdArguments "/arch=x64 /host_arch=x64 /no_logo"
# Note: The current version of the HIP SDK does not ship with CMake config files for Nvidia, so we can only test
# the HIP-Basic and Applications examples. It is expected that some dependencies will not be found for this.
- cmake
-S "$CI_PROJECT_DIR"
-B "$CI_PROJECT_DIR/build"
-G Ninja
-D CMAKE_CXX_COMPILER="cl.exe"
-D CMAKE_BUILD_TYPE="$BUILD_TYPE"
-D CMAKE_TOOLCHAIN_FILE="C:/Tools/Microsoft/vcpkg/scripts/buildsystems/vcpkg.cmake"
-D GPU_RUNTIME=CUDA
2>&1 | Tee-Object -filepath cmake_log.txt
- |-
if (Select-String -Path cmake_log.txt -Pattern "could not find") {
throw "Some cmake libraries are missing"
}
- cmake --build "$CI_PROJECT_DIR/build"
- cd "$CI_PROJECT_DIR/build" && ctest --output-on-failure
- cd "$CI_PROJECT_DIR/build"
- ctest --output-on-failure --timeout 10
- cmake --install "$CI_PROJECT_DIR/build" --prefix "$CI_PROJECT_DIR/install"
13 changes: 9 additions & 4 deletions Applications/floyd_warshall/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,11 +39,14 @@ set(CMAKE_${GPU_RUNTIME}_STANDARD 17)
set(CMAKE_${GPU_RUNTIME}_EXTENSIONS OFF)
set(CMAKE_${GPU_RUNTIME}_STANDARD_REQUIRED ON)

set(ROCM_ROOT "/opt/rocm" CACHE PATH "Root directory of the ROCm installation")
if(NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "${ROCM_ROOT}")
if(WIN32)
set(ROCM_ROOT "$ENV{HIP_PATH}" CACHE PATH "Root directory of the ROCm installation")
else()
set(ROCM_ROOT "/opt/rocm" CACHE PATH "Root directory of the ROCm installation")
endif()

list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}")

add_executable(${example_name} main.hip)
# Make example runnable using ctest
add_test(${example_name} ${example_name})
Expand All @@ -56,3 +59,5 @@ endif()

target_include_directories(${example_name} PRIVATE ${include_dirs})
set_source_files_properties(main.hip PROPERTIES LANGUAGE ${GPU_RUNTIME})

install(TARGETS ${example_name})
2 changes: 1 addition & 1 deletion Dockerfiles/hip-libraries-cuda-ubuntu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ RUN wget https://github.com/ROCmSoftwarePlatform/hipBLAS/archive/refs/tags/rocm-
ARG GID=109

# Add the render group and a user with sudo permissions for the container
RUN groupadd --system --gid ${ARG} render \
RUN groupadd --system --gid ${GID} render \
&& useradd -Um -G sudo,video,render developer \
&& echo developer ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/developer \
&& chmod 0440 /etc/sudoers.d/developer
Expand Down
14 changes: 10 additions & 4 deletions HIP-Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,9 +30,12 @@ if(NOT "${GPU_RUNTIME}" STREQUAL "CUDA")
add_subdirectory(module_api)
endif()

if(WIN32 AND NOT "${GPU_RUNTIME}" STREQUAL "CUDA")
add_subdirectory(cooperative_groups)
endif()

add_subdirectory(bandwidth)
add_subdirectory(bit_extract)
add_subdirectory(cooperative_groups)
add_subdirectory(device_query)
add_subdirectory(device_globals)
add_subdirectory(dynamic_shared)
Expand All @@ -57,9 +60,12 @@ add_subdirectory(occupancy)
add_subdirectory(runtime_compilation)
add_subdirectory(saxpy)
add_subdirectory(shared_memory)
add_subdirectory(static_host_library)
# We cannot build the static library on Windows as the HIP SDK does not include CMAKE_AR.
if(NOT WIN32 AND NOT "${GPU_RUNTIME}" STREQUAL "HIP")
add_subdirectory(static_host_library)
endif()
add_subdirectory(streams)
# temporarily exclude texture management on Windows
# temporarily exclude texture management on Windows
if(NOT WIN32)
add_subdirectory(texture_management)
endif()
Expand Down
Loading

0 comments on commit 9c86faa

Please sign in to comment.