Skip to content

Commit

Permalink
SWDEV-307394: Fixing Download HSA-Class Issue
Browse files Browse the repository at this point in the history
Exchanging the git clone of the hsa-class to a local downloaded version pushed to the roctracer repo

Change-Id: Id45a38b2d355102c2e0dee1e4bfde50398369047
  • Loading branch information
ammarwa committed Mar 29, 2022
1 parent bfea525 commit 7ee4f87
Show file tree
Hide file tree
Showing 28 changed files with 3,886 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
*.swp
*.Po
build
test/hsa
test/MatrixTranspose/MatrixTranspose
test/MatrixTranspose_test/MatrixTranspose
3 changes: 0 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ endif ()

## Path to HSA test
set ( HSA_TEST_DIR "${TEST_DIR}/hsa/test" )
set ( HSA_REV "f8b3870" )

## test run script
set ( RUN_SCRIPT "${TEST_DIR}/run.sh" )
Expand All @@ -70,8 +69,6 @@ add_custom_target( mytest
)

## Build HSA test
execute_process ( COMMAND sh -xc "if [ ! -e ${TEST_DIR}/hsa ] ; then git clone https://github.com/ROCmSoftwarePlatform/hsa-class.git ${TEST_DIR}/hsa; fi" )
execute_process ( COMMAND sh -xc "if [ -e ${TEST_DIR}/hsa ] ; then cd ${TEST_DIR}/hsa && git fetch origin && git checkout ${HSA_REV}; fi" )
set ( TMP ${TEST_DIR} )
set ( TEST_DIR ${HSA_TEST_DIR} )
add_subdirectory ( ${HSA_TEST_DIR} ${PROJECT_BINARY_DIR}/test/hsa )
Expand Down
20 changes: 20 additions & 0 deletions test/hsa/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
[MITx11 license]

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.
4 changes: 4 additions & 0 deletions test/hsa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# HSA-class
```
HSA high level C++ API
```
80 changes: 80 additions & 0 deletions test/hsa/script/build_kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh -x
SO_EXT="hsaco"

TEST_NAME=$1
DST_DIR=$2
ROCM_DIR=$3
TGT_LIST=$4

if [ -z "$TEST_NAME" ] ; then
echo "Usage: $0 <test name> <dst dir>"
echo " Will look for <test name>.cl and will build <test name>.$SO_EXT dynamic code object library"
exit 1
fi
OBJ_NAME=$(echo "_$(basename $TEST_NAME)" | sed -e 's/_./\U&\E/g' -e 's/_//g')

if [ -z "$DST_DIR" ] ; then
DST_DIR=$(dirname TEST_NAME)
fi

if [ -z "$ROCM_DIR" ] ; then
ROCM_DIR=/opt/rocm
fi

if [ -z "$TGT_LIST" ] ; then
TGT_LIST=`$ROCM_DIR/bin/rocminfo | grep "amdgcn-amd-amdhsa--" | head -n 1 | sed -n "s/^.*amdgcn-amd-amdhsa--\(\w*\).*$/\1/p"`
fi

if [ -z "$TGT_LIST" ] ; then
echo "Error: GPU targets not found"
exit 1
fi

OCL_VER="2.0"

if [ -e $ROCM_DIR/llvm ] ; then
LLVM_DIR=$ROCM_DIR/llvm
LIB_DIR=$ROCM_DIR/lib
else
LLVM_DIR=$ROCM_DIR/hcc
LIB_DIR=$LLVM_DIR/lib
fi

# Determine whether using new or old device-libs layout
if [ -e $LIB_DIR/bitcode/opencl.amdgcn.bc ]; then
BC_DIR=$LIB_DIR/bitcode
elif [ -e $LIB_DIR/opencl.amdgcn.bc ]; then
BC_DIR=$LIB_DIR
elif [ -e $ROCM_DIR/amdgcn/bitcode/opencl.bc ]; then
BC_DIR=$ROCM_DIR/amdgcn/bitcode
else
echo "Error: Cannot find amdgcn bitcode directory"
exit 1
fi

CLANG_ROOT=$LLVM_DIR/lib/clang
CLANG_DIR=`ls -d $CLANG_ROOT/* | head -n 1`
if [ "$CLANG_DIR" = "" ] ; then
echo "Error: LLVM clang library was not found"
exit 1
fi

BIN_DIR=$LLVM_DIR/bin
INC_DIR=$CLANG_DIR/include
if [ -e $BC_DIR/opencl.amdgcn.bc ]; then
BITCODE_OPTS="-nogpulib \
-Xclang -mlink-bitcode-file -Xclang $BC_DIR/opencl.amdgcn.bc \
-Xclang -mlink-bitcode-file -Xclang $BC_DIR/ockl.amdgcn.bc \
-Xclang -mlink-bitcode-file -Xclang $BC_DIR/ocml.amdgcn.bc"
else
BITCODE_OPTS="--hip-device-lib-path=$BC_DIR"
fi

for GFXIP in $TGT_LIST ; do
OBJ_PREF=$GFXIP
OBJ_FILE="${OBJ_PREF}_${OBJ_NAME}.$SO_EXT"
$BIN_DIR/clang -cl-std=CL$OCL_VER -include $INC_DIR/opencl-c.h $BITCODE_OPTS -target amdgcn-amd-amdhsa -mcpu=$GFXIP $TEST_NAME.cl -o $DST_DIR/$OBJ_FILE
echo "'$OBJ_FILE' generated"
done

exit 0
Loading

0 comments on commit 7ee4f87

Please sign in to comment.