-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathCMakeLists.txt
134 lines (124 loc) · 5.82 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# ########################################################################
# Copyright (C) 2025 Advanced Micro Devices, Inc.
#
# 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.
#
# ########################################################################
cmake_minimum_required(VERSION 3.15)
# This is a CMake script for building the rocisa together with executing
# Tensile without having two steps (cmake build + Tensile run)
# This script is designed to be used with the TensileLite project
# It allows you to specify the Tensile binary to run and the arguments
# to pass to it.
# The original command for running a TensileLite script is:
# Tensile config.yaml ./
# "./" is the working directory.
# This CMakeLists.txt supports two modes with setting DEVELOP_MODE ON or OFF:
# 1. Script mode (DEVELOP_MODE=ON): It creates a script that can be run after the configuration
# When using mode, you can run it as:
# cmake -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON ..
# The script will be created in the build folder and will be named in Tensile.bat or Tensile.sh
# depending on the platform. You can then run the script as:
# Tensile.sh config.yaml ./
# or
# Tensile.bat config.yaml ./
# 2. Normal CMake mode: It sets the Python srguments at configuration stage with "BIN_ARGS"
# With this mode, you can run it as:
# cmake -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ -DTENSILE_BIN=Tensile -DBIN_ARGS="config.yaml ./" .. && cmake --build .
# The script will check if the TENSILE_BIN is valid and if the BIN_ARGS
# are provided. It will then run the specified Tensile binary with the
# provided arguments after the build step.
# Avoid creating build folder under TensileLite in this mode because tox also use this folder
# and it will cause the CMakeCache.txt to be deleted.
#
# If you want to build a Debug version of rocisa, you can add -DCMAKE_BUILD_TYPE=Debug
project(TensileLiteAutoBuild LANGUAGES HIP)
set(DEVELOP_MODE OFF CACHE BOOL "Set to ON to create a script for running the Tensile binary after the configuration.")
set(VALID_BINS
"Tensile"
"TensileBenchmarkCluster"
"TensileClientConfig"
"TensileCreateLibrary"
"TensileGenerateSummations"
"TensileLogic"
"TensileRetuneLibrary"
"TensileUpdateLibrary"
)
function(set_tensile_bin BINS)
list(FIND VALID_BINS "${BINS}" INDEX)
if(INDEX EQUAL -1)
message(FATAL_ERROR "Invalid bin name: ${BINS}. Valid options are: ${VALID_BINS}")
endif()
set("Tensile bin is set to ${BINS}")
endfunction()
if(DEFINED TENSILE_BIN)
set_tensile_bin(${TENSILE_BIN})
else()
message(FATAL_ERROR "TENSILE_BIN is not defined. Please set it to one of the valid options: ${VALID_BINS}")
endif()
# Find Python interpreter
find_package(Python COMPONENTS Interpreter REQUIRED)
# Add rocisa
add_subdirectory(rocisa)
# Set common variables
set(TENSILE_BIN_ROOT "${CMAKE_SOURCE_DIR}/Tensile/bin")
set(PYTHONPATH "${PROJECT_BINARY_DIR}/lib")
if(DEFINED DEVELOP_MODE)
include(ProcessorCount)
ProcessorCount(NPROC)
set(CMAKE_BUILD_COMMAND "cmake --build ${PROJECT_BINARY_DIR} -j ${NPROC}")
if(WIN32)
set(SCRIPT_NAME ${TENSILE_BIN}.bat)
file(WRITE "${PROJECT_BINARY_DIR}/${SCRIPT_NAME}"
"@echo off\n"
"${CMAKE_BUILD_COMMAND}\n"
"PYTHONPATH=${PYTHONPATH} ${Python_EXECUTABLE} ${TENSILE_BIN_ROOT}/${TENSILE_BIN} %*\n"
"pause\n"
)
else()
set(SCRIPT_NAME ${TENSILE_BIN}.sh)
file(WRITE "${PROJECT_BINARY_DIR}/${SCRIPT_NAME}"
"#!/bin/bash\n"
"set -euo pipefail\n"
"${CMAKE_BUILD_COMMAND}\n"
"PYTHONPATH=${PYTHONPATH} ${Python_EXECUTABLE} ${TENSILE_BIN_ROOT}/${TENSILE_BIN} \"$@\"\n"
)
execute_process(COMMAND chmod +x "${PROJECT_BINARY_DIR}/${TENSILE_BIN}.sh")
endif()
message(STATUS "Script created: ${PROJECT_BINARY_DIR}/${SCRIPT_NAME}. Please run the Tensile bin command as usual under the build folder.")
else()
# Check if BIN_ARGS_LIST is empty
if(NOT DEFINED BIN_ARGS)
message(FATAL_ERROR "BIN_ARGS is not defined. Please set it to the arguments you want to pass to the Tensile binary.")
endif()
# Retrieve the arguments
set(BIN_ARGS ${BIN_ARGS})
# Split the arguments into a list
separate_arguments(BIN_ARGS_LIST NATIVE_COMMAND "${BIN_ARGS}")
message(STATUS "Script set: ${TENSILE_BIN} ${BIN_ARGS_LIST}")
# Ensure the Python script runs after the build
add_custom_target(RunPythonScript
ALL
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${PYTHONPATH} -- ${Python_EXECUTABLE} ${TENSILE_BIN_ROOT}/${TENSILE_BIN} ${BIN_ARGS_LIST}
COMMENT "Running Python script ${TENSILE_BIN} ${BIN_ARGS_LIST}"
VERBATIM
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
add_dependencies(RunPythonScript rocisa)
endif()