-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Develop Stream 2024-05-06 implementation (#115)
Develop Stream 2024-05-06 implementation * Add copyright check script based on hipCUB * Implemented minimal CMake CUDA example * Add a default case for externally controlled enumerations * ci: use build instead rocm-build and nvcc-build tags * Add consistent error code for parsing failures * ci: manually set HIP_COMPILER, HIP_PLATFORM and HIP_RUNTIME * Add git-clang-format check when installing pre-commit hook * Fix markdown linting --------- Co-authored-by: Gergely Meszaros <[email protected]> Co-authored-by: Lőrinc Serfőző <[email protected]> Co-authored-by: Jaap <[email protected]> Co-authored-by: Nara Prasetya <[email protected]>
- Loading branch information
1 parent
c707559
commit fd90d0e
Showing
31 changed files
with
487 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
|
||
cd "$(git rev-parse --git-dir)" | ||
cd hooks | ||
|
||
echo "Installing hooks..." | ||
# Install pre-commit hook if dependencies are satisfied | ||
if ! [ -x "$(command -v git-clang-format)" ]; then | ||
echo 'Error: pre-commit hook depends on git-clang-format, but is not installed.' >&2 | ||
exit 1 | ||
else | ||
ln -s ../../.githooks/pre-commit pre-commit | ||
fi | ||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
|
||
# Redirect output to stderr. | ||
exec 1>&2 | ||
|
||
check_failed=false | ||
|
||
# Do the code format check | ||
if ! "$(git rev-parse --show-toplevel)/Scripts/CodeFormat/check_format.sh" HEAD --cached 1>&2; then | ||
printf "\n\033[31mFailed\033[0m: code format check.\n" | ||
check_failed=true | ||
fi | ||
|
||
# Do the copyright check | ||
# update & apply copyright when hook config is set, otherwise just verify | ||
opts="-qc" | ||
if [ "$(git config --get --type bool --default false hooks.updateCopyright)" = "true" ]; then | ||
opts="-qca" | ||
fi | ||
|
||
if ! "$(git rev-parse --show-toplevel)/Scripts/CopyrightDate/check_copyright.sh" "$opts" 1>&2; then | ||
printf "\n\033[31mFailed\033[0m: copyright date check.\n" | ||
check_failed=true | ||
fi | ||
|
||
if $check_failed; then | ||
printf " | ||
Pre-commit check failed, please fix the reported errors. | ||
Note: Use '\033[33mgit commit --no-verify\033[0m' to bypass checks.\n" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2024 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 | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
set(example_name hip_hello_world_cuda) | ||
|
||
cmake_minimum_required(VERSION 3.21 FATAL_ERROR) | ||
|
||
# CMake's HIP language mode does not yet support compiling with CUDA, thereby we must | ||
# resort to the CUDA language mode. | ||
project(${example_name} LANGUAGES CUDA) | ||
|
||
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() | ||
|
||
add_executable(${example_name} main.hip) | ||
|
||
# Make example runnable using ctest | ||
add_test(${example_name} ${example_name}) | ||
|
||
# Make the HIP runtime headers accessible | ||
target_include_directories(${example_name} PRIVATE | ||
"${ROCM_ROOT}/include" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../../Common") | ||
|
||
# Set up the compilation language for the source file. | ||
# Usually this can be deduced from the file extension, but not in the case of .hip. | ||
set_source_files_properties(main.hip PROPERTIES LANGUAGE CUDA) | ||
|
||
install(TARGETS ${example_name}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# HIP-Basic Hello World on the CUDA platform Example | ||
|
||
## Description | ||
|
||
This example showcases a simple HIP program that is compiled on the CUDA platform using CMake. | ||
|
||
### Application flow | ||
|
||
1. A kernel is launched: the function `hello_world_kernel` is executed on the device. The kernel is executed on a single thread, and prints "Hello, World!" to the console. | ||
2. A launch error check is performed using `hipGetLastError`. | ||
3. _Synchronization_ is performed: the host program execution halts until the kernel on the device has finished executing. | ||
|
||
## Key APIs and Concepts | ||
|
||
- For introduction to the programming concepts in this example, refer to the general [hello world example](../hello_world/). | ||
- This example showcases setting up a HIP program to be compiled to the CUDA platform using CMake. | ||
- Since CMake (as of version 3.21) does not support compiling to CUDA in HIP language mode, CUDA language mode has to be used. Thereby the project language is specified as `CUDA`. | ||
- Additionally, we must "teach" CMake to compile the source file `main.hip` in CUDA language mode, because it cannot guess that from the file extension. This is done by `set_source_files_properties(main.hip PROPERTIES LANGUAGE CUDA)`. | ||
- The HIP "runtime" on the CUDA platform is header only. Thereby there is no need to link to a library, but the HIP include directory have to be added to the search paths. This is performed by `target_include_directories(${example_name} PRIVATE "${ROCM_ROOT}/include"`. | ||
|
||
## Demonstrated API Calls | ||
|
||
### HIP Runtime | ||
|
||
- `hipGetLastError` | ||
- `hipDeviceSynchronize` | ||
- `__global__` | ||
|
||
## Supported Platforms | ||
|
||
This example is only supported on the CUDA platform. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 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 | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#include <hip/hip_runtime.h> | ||
|
||
#include "example_utils.hpp" | ||
|
||
__global__ void hello_world_kernel() | ||
{ | ||
printf("Hello, World!\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
static constexpr unsigned int grid_size = 1; | ||
static constexpr unsigned int block_size = 1; | ||
hello_world_kernel<<<grid_size, block_size>>>(); | ||
HIP_CHECK(hipGetLastError()); | ||
HIP_CHECK(hipDeviceSynchronize()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.