SWDEV-431345 - CMake build flow for hip samples 16,17
Change-Id: I7bfc8600511c78d8c73aa526f9846cd268651279
[ROCm/hip-tests commit: f0b5b20466]
Этот коммит содержится в:
коммит произвёл
Rakesh Roy
родитель
bf7b7e6809
Коммит
2d432c1ca6
@@ -0,0 +1,74 @@
|
||||
project(asm_to_exe)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
if(UNIX)
|
||||
if(NOT DEFINED ROCM_PATH)
|
||||
set(ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory.")
|
||||
endif()
|
||||
if(NOT DEFINED HIP_PATH)
|
||||
if(NOT DEFINED ENV{HIP_PATH})
|
||||
set(HIP_PATH ${ROCM_PATH} CACHE PATH "Path to which HIP has been installed")
|
||||
else()
|
||||
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
|
||||
endif()
|
||||
|
||||
|
||||
# Find hip
|
||||
find_package(hip REQUIRED)
|
||||
|
||||
# Set compiler and linker
|
||||
set(HIPCC ${HIP_HIPCC_EXECUTABLE})
|
||||
set(CLANG ${HIP_PATH}/llvm/bin/clang)
|
||||
set(LLVM_MC ${HIP_PATH}/llvm/bin/llvm-mc)
|
||||
set(CLANG_OFFLOAD_BUNDLER ${HIP_PATH}/llvm/bin/clang-offload-bundler)
|
||||
|
||||
set(INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../common)
|
||||
|
||||
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/square.cpp)
|
||||
set(SQ_HOST_ASM ${CMAKE_CURRENT_BINARY_DIR}/square_host.s)
|
||||
set(SQ_HOST_OBJ ${CMAKE_CURRENT_BINARY_DIR}/square_host.o)
|
||||
set(SQ_DEVICE_HIPFB ${CMAKE_CURRENT_BINARY_DIR}/offload_bundle.hipfb)
|
||||
set(SQ_DEVICE_OBJ ${CMAKE_CURRENT_BINARY_DIR}/square_device.o)
|
||||
set(SQ_ASM_EXE ${CMAKE_CURRENT_BINARY_DIR}/square_asm.out)
|
||||
|
||||
set(MCIN_OBJ_GEN ${CMAKE_CURRENT_SOURCE_DIR}/hip_obj_gen.mcin)
|
||||
|
||||
if(NOT DEFINED GPU_ARCH)
|
||||
set(GPU_ARCH gfx900 gfx906 gfx908 gfx1010 gfx1030 gfx1100 gfx1101 gfx1102 gfx1103)
|
||||
endif()
|
||||
|
||||
if(TARGET build_cookbook)
|
||||
set(ALL_OPTION )
|
||||
else()
|
||||
set(ALL_OPTION ALL )
|
||||
endif()
|
||||
|
||||
list(JOIN GPU_ARCH "," OFFLOAD_ARCH)
|
||||
add_custom_target(src_to_asm ${ALL_OPTION} COMMAND ${HIPCC} -c -S -I${INCLUDES} --cuda-host-only -target x86_64-linux-gnu -o ${SQ_HOST_ASM} ${SRCS}
|
||||
COMMAND ${HIPCC} -c -S -I${INCLUDES} --cuda-device-only --offload-arch=${OFFLOAD_ARCH} ${SRCS})
|
||||
|
||||
|
||||
add_custom_command(OUTPUT host_obj COMMAND ${HIPCC} -c ${SQ_HOST_ASM} -o ${SQ_HOST_OBJ})
|
||||
|
||||
foreach(ARCH ${GPU_ARCH})
|
||||
list(APPEND TARGETS hip-amdgcn-amd-amdhsa--${ARCH})
|
||||
list(APPEND INPUTS square-hip-amdgcn-amd-amdhsa-${ARCH}.o)
|
||||
set(arch_obj ${ARCH}_obj)
|
||||
add_custom_command(OUTPUT ${arch_obj} COMMAND ${CLANG} -target amdgcn-amd-amdhsa -mcpu=${ARCH} square-hip-amdgcn-amd-amdhsa-${ARCH}.s -o square-hip-amdgcn-amd-amdhsa-${ARCH}.o)
|
||||
list(APPEND arch_obj_targets ${arch_obj})
|
||||
endforeach()
|
||||
|
||||
list(JOIN TARGETS "," TARGET_STR)
|
||||
list(TRANSFORM INPUTS PREPEND "-input=")
|
||||
add_custom_target(asm_to_exec ${ALL_OPTION} DEPENDS src_to_asm host_obj ${arch_obj_targets}
|
||||
COMMAND ${CLANG_OFFLOAD_BUNDLER} -type=o -bundle-align=4096 -targets=host-x86_64-unknown--linux,${TARGET_STR} -input=/dev/null ${INPUTS} -output=${SQ_DEVICE_HIPFB}
|
||||
COMMAND ${LLVM_MC} ${MCIN_OBJ_GEN} -o ${SQ_DEVICE_OBJ} --filetype=obj
|
||||
COMMAND ${HIPCC} ${SQ_HOST_OBJ} ${SQ_DEVICE_OBJ} -o ${SQ_ASM_EXE})
|
||||
|
||||
if(TARGET build_cookbook)
|
||||
add_dependencies(build_cookbook src_to_asm asm_to_exec)
|
||||
endif()
|
||||
@@ -1,88 +0,0 @@
|
||||
# Copyright (c) 2020 - 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
|
||||
# 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.
|
||||
ifeq ($(OS),Windows_NT)
|
||||
$(error Makefile is not supported on windows platform. Please use cmake instead to build sample.)
|
||||
endif
|
||||
ROCM_PATH?= $(wildcard /opt/rocm/)
|
||||
HIP_PATH?= $(ROCM_PATH)
|
||||
|
||||
HIPCC=$(HIP_PATH)/bin/hipcc
|
||||
CLANG=$(HIP_PATH)/llvm/bin/clang
|
||||
LLVM_MC=$(HIP_PATH)/llvm/bin/llvm-mc
|
||||
CLANG_OFFLOAD_BUNDLER=$(HIP_PATH)/llvm/bin/clang-offload-bundler
|
||||
INCLUDES := -I../../common
|
||||
|
||||
SRCS=square.cpp
|
||||
|
||||
# Extracting ASM code, then creating an executable with the modified asm.
|
||||
|
||||
SQ_HOST_ASM=square_host.s
|
||||
SQ_HOST_OBJ=square_host.o
|
||||
SQ_DEVICE_HIPFB=offload_bundle.hipfb
|
||||
SQ_DEVICE_OBJ=square_device.o
|
||||
SQ_ASM_EXE=square_asm.out
|
||||
|
||||
MCIN_OBJ_GEN=hip_obj_gen.mcin
|
||||
GPU_ARCH1=gfx900
|
||||
GPU_ARCH2=gfx906
|
||||
GPU_ARCH3=gfx908
|
||||
GPU_ARCH4=gfx1010
|
||||
GPU_ARCH5=gfx1030
|
||||
GPU_ARCH6=gfx1100
|
||||
GPU_ARCH7=gfx1101
|
||||
GPU_ARCH8=gfx1102
|
||||
GPU_ARCH9=gfx1103
|
||||
|
||||
.PHONY: test
|
||||
|
||||
all: src_to_asm asm_to_exec
|
||||
|
||||
src_to_asm:
|
||||
$(HIPCC) -c -S $(INCLUDES) --cuda-host-only -target x86_64-linux-gnu -o $(SQ_HOST_ASM) $(SRCS)
|
||||
$(HIPCC) -c -S $(INCLUDES) --cuda-device-only --offload-arch=$(GPU_ARCH1) --offload-arch=$(GPU_ARCH2) --offload-arch=$(GPU_ARCH3) --offload-arch=$(GPU_ARCH4) --offload-arch=$(GPU_ARCH5) --offload-arch=$(GPU_ARCH6) --offload-arch=$(GPU_ARCH7) --offload-arch=$(GPU_ARCH8) --offload-arch=$(GPU_ARCH9) $(SRCS)
|
||||
|
||||
# You may modify the .s assembly files before the next step
|
||||
# By default, their names will be:
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx900.s
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx906.s
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx908.s
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx1010.s
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx1030.s
|
||||
#
|
||||
# Note: hipcc does not work to convert .s to .o, use clang instead.
|
||||
|
||||
asm_to_exec:
|
||||
$(HIPCC) -c $(SQ_HOST_ASM) -o $(SQ_HOST_OBJ)
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH1) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH2) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH3) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH4) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH5) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH6) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH7) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH8) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH9) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).s -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).o
|
||||
$(CLANG_OFFLOAD_BUNDLER) -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa-$(GPU_ARCH1),hip-amdgcn-amd-amdhsa-$(GPU_ARCH2),hip-amdgcn-amd-amdhsa-$(GPU_ARCH3),hip-amdgcn-amd-amdhsa-$(GPU_ARCH4),hip-amdgcn-amd-amdhsa-$(GPU_ARCH5),hip-amdgcn-amd-amdhsa-$(GPU_ARCH6),hip-amdgcn-amd-amdhsa-$(GPU_ARCH7),hip-amdgcn-amd-amdhsa-$(GPU_ARCH8),hip-amdgcn-amd-amdhsa-$(GPU_ARCH9) -inputs=/dev/null,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).o -outputs=$(SQ_DEVICE_HIPFB)
|
||||
$(LLVM_MC) $(MCIN_OBJ_GEN) -o $(SQ_DEVICE_OBJ) --filetype=obj
|
||||
$(HIPCC) $(SQ_HOST_OBJ) $(SQ_DEVICE_OBJ) -o $(SQ_ASM_EXE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.hipfb *.s *.ll *.bc
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
project(llvm_ir_to_exe)
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
if(UNIX)
|
||||
if(NOT DEFINED ROCM_PATH)
|
||||
set(ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory.")
|
||||
endif()
|
||||
if(NOT DEFINED HIP_PATH)
|
||||
if(NOT DEFINED ENV{HIP_PATH})
|
||||
set(HIP_PATH ${ROCM_PATH} CACHE PATH "Path to which HIP has been installed")
|
||||
else()
|
||||
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH})
|
||||
endif()
|
||||
|
||||
|
||||
# Find hip
|
||||
find_package(hip REQUIRED)
|
||||
|
||||
# Set compiler and linker
|
||||
set(HIPCC ${HIP_HIPCC_EXECUTABLE})
|
||||
set(CLANG ${HIP_PATH}/llvm/bin/clang)
|
||||
set(LLVM_MC ${HIP_PATH}/llvm/bin/llvm-mc)
|
||||
set(CLANG_OFFLOAD_BUNDLER ${HIP_PATH}/llvm/bin/clang-offload-bundler)
|
||||
set(LLVM_AS ${HIP_PATH}/llvm/bin/llvm-as)
|
||||
set(LLVM_DIS ${HIP_PATH}/llvm/bin/llvm-dis)
|
||||
|
||||
set(INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../../common)
|
||||
|
||||
set(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/square.cpp)
|
||||
set(SQ_HOST_BC ${CMAKE_CURRENT_BINARY_DIR}/square_host.bc)
|
||||
set(SQ_HOST_LL ${CMAKE_CURRENT_BINARY_DIR}/square_host.ll)
|
||||
set(SQ_HOST_OBJ ${CMAKE_CURRENT_BINARY_DIR}/square_host.o)
|
||||
set(SQ_DEVICE_HIPFB ${CMAKE_CURRENT_BINARY_DIR}/offload_bundle.hipfb)
|
||||
set(SQ_DEVICE_OBJ ${CMAKE_CURRENT_BINARY_DIR}/square_device.o)
|
||||
set(SQ_IR_EXE ${CMAKE_CURRENT_BINARY_DIR}/square_ir.out)
|
||||
|
||||
set(MCIN_OBJ_GEN ${CMAKE_CURRENT_SOURCE_DIR}/hip_obj_gen.mcin)
|
||||
|
||||
if(NOT DEFINED GPU_ARCH)
|
||||
set(GPU_ARCH gfx900 gfx906 gfx908 gfx1010 gfx1030 gfx1100 gfx1101 gfx1102 gfx1103)
|
||||
endif()
|
||||
|
||||
if(TARGET build_cookbook)
|
||||
set(ALL_OPTION )
|
||||
else()
|
||||
set(ALL_OPTION ALL )
|
||||
endif()
|
||||
|
||||
list(JOIN GPU_ARCH "," OFFLOAD_ARCH)
|
||||
add_custom_target(src_to_ir ${ALL_OPTION} COMMAND ${HIPCC} -c -emit-llvm -I${INCLUDES} --cuda-host-only -target x86_64-linux-gnu -o ${SQ_HOST_BC} ${SRCS}
|
||||
COMMAND ${HIPCC} -c -emit-llvm -I${INCLUDES} --cuda-device-only --offload-arch=${OFFLOAD_ARCH} ${SRCS})
|
||||
|
||||
# Target for BC to LL
|
||||
add_custom_command(OUTPUT ll_obj COMMAND ${LLVM_DIS} ${SQ_HOST_BC} -o ${SQ_HOST_LL})
|
||||
|
||||
foreach(ARCH ${GPU_ARCH})
|
||||
set(arch_obj ${ARCH}_ll_obj)
|
||||
add_custom_command(OUTPUT ${arch_obj} COMMAND ${LLVM_DIS} square-hip-amdgcn-amd-amdhsa-${ARCH}.bc -o square-hip-amdgcn-amd-amdhsa-${ARCH}.ll)
|
||||
list(APPEND arch_ll_obj ${arch_obj})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(bc_to_ll ${ALL_OPTION} DEPENDS src_to_ir ll_obj ${arch_ll_obj})
|
||||
|
||||
# Target for LL to BC
|
||||
add_custom_command(OUTPUT bc_obj COMMAND ${LLVM_AS} ${SQ_HOST_LL} -o ${SQ_HOST_BC})
|
||||
foreach(ARCH ${GPU_ARCH})
|
||||
set(arch_obj ${ARCH}_bc_obj)
|
||||
add_custom_command(OUTPUT ${arch_obj} COMMAND ${LLVM_AS} square-hip-amdgcn-amd-amdhsa-${ARCH}.ll -o square-hip-amdgcn-amd-amdhsa-${ARCH}.bc)
|
||||
list(APPEND arch_bc_obj ${arch_obj})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(ll_to_bc ${ALL_OPTION} DEPENDS bc_to_ll bc_obj ${arch_bc_obj})
|
||||
|
||||
# Target for IR to EXEC
|
||||
add_custom_command(OUTPUT host_obj COMMAND ${HIPCC} -c ${SQ_HOST_BC} -o ${SQ_HOST_OBJ})
|
||||
|
||||
foreach(ARCH ${GPU_ARCH})
|
||||
set(arch_obj ${ARCH}_obj)
|
||||
add_custom_command(OUTPUT ${arch_obj} COMMAND ${CLANG} -target amdgcn-amd-amdhsa -mcpu=${ARCH} square-hip-amdgcn-amd-amdhsa-${ARCH}.bc -o square-hip-amdgcn-amd-amdhsa-${ARCH}.o)
|
||||
list(APPEND arch_obj_list ${arch_obj})
|
||||
list(APPEND TARGETS hip-amdgcn-amd-amdhsa--${ARCH})
|
||||
list(APPEND INPUTS square-hip-amdgcn-amd-amdhsa-${ARCH}.o)
|
||||
endforeach()
|
||||
|
||||
list(JOIN TARGETS "," TARGET_STR)
|
||||
list(TRANSFORM INPUTS PREPEND "-input=")
|
||||
add_custom_target(ir_to_exec ${ALL_OPTION} DEPENDS ll_to_bc host_obj ${arch_obj_list}
|
||||
COMMAND ${CLANG_OFFLOAD_BUNDLER} -type=o -bundle-align=4096 -targets=host-x86_64-unknown--linux,${TARGET_STR} -input=/dev/null ${INPUTS} -output=${SQ_DEVICE_HIPFB}
|
||||
COMMAND ${LLVM_MC} ${MCIN_OBJ_GEN} -o ${SQ_DEVICE_OBJ} --filetype=obj
|
||||
COMMAND ${HIPCC} ${SQ_HOST_OBJ} ${SQ_DEVICE_OBJ} -o ${SQ_IR_EXE})
|
||||
|
||||
if(TARGET build_cookbook)
|
||||
add_dependencies(build_cookbook src_to_ir bc_to_ll ll_to_bc ir_to_exec)
|
||||
endif()
|
||||
@@ -1,116 +0,0 @@
|
||||
# Copyright (c) 2020 - 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
|
||||
# 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.
|
||||
ifeq ($(OS),Windows_NT)
|
||||
$(error Makefile is not supported on windows platform. Please use cmake instead to build sample.)
|
||||
endif
|
||||
ROCM_PATH?= $(wildcard /opt/rocm/)
|
||||
HIP_PATH?= $(ROCM_PATH)
|
||||
|
||||
HIPCC=$(HIP_PATH)/bin/hipcc
|
||||
CLANG=$(HIP_PATH)/llvm/bin/clang
|
||||
LLVM_MC=$(HIP_PATH)/llvm/bin/llvm-mc
|
||||
CLANG_OFFLOAD_BUNDLER=$(HIP_PATH)/llvm/bin/clang-offload-bundler
|
||||
LLVM_AS=$(HIP_PATH)/llvm/bin/llvm-as
|
||||
LLVM_DIS=$(HIP_PATH)/llvm/bin/llvm-dis
|
||||
INCLUDES := -I../../common
|
||||
|
||||
SRCS=square.cpp
|
||||
|
||||
# Extracting the IR code, then creating an executable with the modified IR.
|
||||
|
||||
SQ_HOST_BC=square_host.bc
|
||||
SQ_HOST_LL=square_host.ll
|
||||
SQ_HOST_OBJ=square_host.o
|
||||
SQ_DEVICE_OBJ=square_device.o
|
||||
SQ_DEVICE_HIPFB=offload_bundle.hipfb
|
||||
SQ_IR_EXE=square_ir.out
|
||||
|
||||
MCIN_OBJ_GEN=hip_obj_gen.mcin
|
||||
GPU_ARCH1=gfx900
|
||||
GPU_ARCH2=gfx906
|
||||
GPU_ARCH3=gfx908
|
||||
GPU_ARCH4=gfx1010
|
||||
GPU_ARCH5=gfx1030
|
||||
GPU_ARCH6=gfx1100
|
||||
GPU_ARCH7=gfx1101
|
||||
GPU_ARCH8=gfx1102
|
||||
GPU_ARCH9=gfx1103
|
||||
|
||||
.PHONY: test
|
||||
|
||||
all: src_to_ir bc_to_ll ll_to_bc ir_to_exec
|
||||
|
||||
src_to_ir:
|
||||
$(HIPCC) $(INCLUDES) -c -emit-llvm --cuda-host-only -target x86_64-linux-gnu -o $(SQ_HOST_BC) $(SRCS)
|
||||
$(HIPCC) $(INCLUDES) -c -emit-llvm --cuda-device-only --offload-arch=$(GPU_ARCH1) --offload-arch=$(GPU_ARCH2) --offload-arch=$(GPU_ARCH3) --offload-arch=$(GPU_ARCH4) --offload-arch=$(GPU_ARCH5) --offload-arch=$(GPU_ARCH6) --offload-arch=$(GPU_ARCH7) --offload-arch=$(GPU_ARCH8) --offload-arch=$(GPU_ARCH9) $(SRCS)
|
||||
|
||||
# By default, the LLVM IR Bitcode file names will be:
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx900.bc
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx906.bc
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx908.bc
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx1010.bc
|
||||
# square-hip-amdgcn-amd-amdhsa-gfx1030.bc
|
||||
|
||||
bc_to_ll:
|
||||
$(LLVM_DIS) $(SQ_HOST_BC) -o $(SQ_HOST_LL)
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).ll
|
||||
$(LLVM_DIS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).ll
|
||||
|
||||
# You may modify the .ll LLVM IR files before the next step
|
||||
#
|
||||
# Note: hipcc does not work to convert .bc to .o, use clang instead.
|
||||
|
||||
ll_to_bc:
|
||||
$(LLVM_AS) $(SQ_HOST_LL) -o $(SQ_HOST_BC)
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).bc
|
||||
$(LLVM_AS) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).ll -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).bc
|
||||
|
||||
ir_to_exec:
|
||||
$(HIPCC) -c $(SQ_HOST_BC) -o $(SQ_HOST_OBJ)
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH1) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH2) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH3) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH4) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH5) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH6) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH7) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH8) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).o
|
||||
$(CLANG) -target amdgcn-amd-amdhsa -mcpu=$(GPU_ARCH9) square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).bc -o square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).o
|
||||
$(CLANG_OFFLOAD_BUNDLER) -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa-$(GPU_ARCH1),hip-amdgcn-amd-amdhsa-$(GPU_ARCH2),hip-amdgcn-amd-amdhsa-$(GPU_ARCH3),hip-amdgcn-amd-amdhsa-$(GPU_ARCH4),hip-amdgcn-amd-amdhsa-$(GPU_ARCH5),hip-amdgcn-amd-amdhsa-$(GPU_ARCH6),hip-amdgcn-amd-amdhsa-$(GPU_ARCH7),hip-amdgcn-amd-amdhsa-$(GPU_ARCH8),hip-amdgcn-amd-amdhsa-$(GPU_ARCH9) -inputs=/dev/null,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH1).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH2).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH3).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH4).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH5).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH6).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH7).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH8).o,square-hip-amdgcn-amd-amdhsa-$(GPU_ARCH9).o -outputs=$(SQ_DEVICE_HIPFB)
|
||||
$(LLVM_MC) $(MCIN_OBJ_GEN) -o $(SQ_DEVICE_OBJ) --filetype=obj
|
||||
$(HIPCC) $(SQ_HOST_OBJ) $(SQ_DEVICE_OBJ) -o $(SQ_IR_EXE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.hipfb *.s *.ll *.bc
|
||||
|
||||
@@ -34,8 +34,8 @@ add_subdirectory(13_occupancy)
|
||||
add_subdirectory(14_gpu_arch)
|
||||
add_subdirectory(15_static_library/device_functions)
|
||||
add_subdirectory(15_static_library/host_functions)
|
||||
#add_subdirectory(16_assembly_to_executable)
|
||||
#add_subdirectory(17_llvm_ir_to_executable)
|
||||
add_subdirectory(16_assembly_to_executable)
|
||||
add_subdirectory(17_llvm_ir_to_executable)
|
||||
add_subdirectory(18_cmake_hip_device)
|
||||
add_subdirectory(19_cmake_lang)
|
||||
#add_subdirectory(20_hip_vulkan)
|
||||
|
||||
Ссылка в новой задаче
Block a user