Skip to content

Commit 1bd651c

Browse files
committed
[rocisa] Use comgr instead of calling amdclang++
1 parent 5d79977 commit 1bd651c

File tree

6 files changed

+150
-231
lines changed

6 files changed

+150
-231
lines changed

tensilelite/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ cmake_minimum_required(VERSION 3.15)
3232
# This CMakeLists.txt supports two modes with setting DEVELOP_MODE ON or OFF:
3333
# 1. Script mode (DEVELOP_MODE=ON): It creates a script that can be run after the configuration
3434
# When using mode, you can run it as:
35-
# cmake -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON ..
35+
# cmake -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON ..
3636
# The script will be created in the build folder and will be named in Tensile.bat or Tensile.sh
3737
# depending on the platform. You can then run the script as:
3838
# Tensile.sh config.yaml ./
3939
# or
40-
# Tensile.bat config.yaml ./
40+
# Tensile.bat config.yaml ./
4141
# 2. Normal CMake mode: It sets the Python srguments at configuration stage with "BIN_ARGS"
4242
# With this mode, you can run it as:
43-
# cmake -DTENSILE_BIN=Tensile -DBIN_ARGS="config.yaml ./" .. && cmake --build .
43+
# cmake -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ -DTENSILE_BIN=Tensile -DBIN_ARGS="config.yaml ./" .. && cmake --build .
4444
# The script will check if the TENSILE_BIN is valid and if the BIN_ARGS
4545
# are provided. It will then run the specified Tensile binary with the
4646
# provided arguments after the build step.
@@ -123,7 +123,7 @@ else()
123123
message(STATUS "Script set: ${TENSILE_BIN} ${BIN_ARGS_LIST}")
124124

125125
# Ensure the Python script runs after the build
126-
add_custom_target(RunPythonScript
126+
add_custom_target(RunPythonScript
127127
ALL
128128
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${PYTHONPATH} -- ${Python_EXECUTABLE} ${TENSILE_BIN_ROOT}/${TENSILE_BIN} ${BIN_ARGS_LIST}
129129
COMMENT "Running Python script ${TENSILE_BIN} ${BIN_ARGS_LIST}"

tensilelite/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
** How to Rebuild Object Codes Directly from Assembly
44

5-
During the tuning process, it is of interest to modify an assembly file/s and rebuild the corresponding object file/s and then relink the corresponding co file. Currently, we generate additional source files and a script to provide this workflow.
5+
During the tuning process, it is of interest to modify an assembly file/s and rebuild the corresponding object file/s and then relink the corresponding co file. Currently, we generate additional source files and a script to provide this workflow.
66

77
A new `Makefile` is added that manages rebuilding a co file during iterative development when tuning. One modifies an assembly file of interest, then runs `make` and make will detect what file/s changed and rebuild accordingly.
88

@@ -14,7 +14,7 @@ Assumptions:
1414

1515
Example:
1616

17-
```cmake -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON -S <path-to-tensilelite-root> -B <tensile-out>```
17+
```cmake -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON -S <path-to-tensilelite-root> -B <tensile-out>```
1818

1919
The script will be created in the build folder and will be named in Tensile.bat or Tensile.sh depending on the platform. Then you can then run the script under the ``tensile-out`` folder as usual:
2020

tensilelite/rocisa/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ set(CMAKE_CXX_STANDARD 20)
2626
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2727
set(CMAKE_CXX_EXTENSIONS OFF)
2828

29+
find_package(amd_comgr REQUIRED CONFIG)
30+
2931
if(DEFINED Python_EXECUTABLE AND Python_EXECUTABLE)
3032
message(STATUS "Manually set Python_EXECUTABLE to ${Python_EXECUTABLE}")
3133
endif()
@@ -73,5 +75,7 @@ nanobind_add_module(rocisa NOMINSIZE NB_SUPPRESS_WARNINGS
7375
${CMAKE_CURRENT_SOURCE_DIR}/rocisa/src/macro.cpp
7476
${ROCISAINST_SOURCE}
7577
${ROCISAPASS_SOURCE})
78+
7679
target_include_directories(rocisa PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rocisa/include)
80+
target_link_libraries(rocisa PRIVATE amd_comgr)
7781
set_target_properties(rocisa PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

tensilelite/rocisa/rocisa/include/hardware_caps.hpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,23 @@ inline bool tryAssembler(const IsaVersion& isaVersion,
3838
if(isaVersion[0] >= 10)
3939
options.push_back("-mwavefrontsize64");
4040

41-
std::string isastr = getGfxNameTuple(isaVersion);
42-
43-
std::vector<std::string> cmd
44-
= {assemblerPath, "-x", "assembler", "-target", "amdgcn-amdhsa", "-mcpu=" + isastr};
45-
for(auto o : options)
41+
const char** optionStr = new const char*[options.size()];
42+
std::string optionOneLineStr = "";
43+
for(size_t i = 0; i < options.size(); i++)
4644
{
47-
cmd.push_back(o);
45+
optionStr[i] = options[i].c_str();
46+
optionOneLineStr += options[i] + " ";
4847
}
49-
cmd.push_back("-");
50-
std::vector<char*> args(cmd.size());
51-
std::transform(cmd.begin(), cmd.end(), args.begin(), [](auto& str) { return &str[0]; });
52-
args.push_back(nullptr);
53-
auto [rcode, result] = run(args, asmString, debug);
48+
std::string isastr = getGfxNameTuple(isaVersion);
49+
50+
auto [rcode, result] = runComgr(asmString, isastr, optionStr, options.size(), debug);
51+
delete[] optionStr;
5452

5553
if(debug)
5654
{
5755
std::string s;
58-
for(auto c : cmd)
59-
s += c + " ";
6056
std::cout << "isaVersion: " << isastr << std::endl;
61-
std::cout << "asm_cmd: " << s << std::endl;
57+
std::cout << "options: " << optionOneLineStr << std::endl;
6258
std::cout << "asmString: " << asmString << std::endl;
6359
std::cout << "result: " << result << std::endl;
6460
std::cout << "return code: " << rcode << std::endl;

tensilelite/rocisa/rocisa/include/helper.hpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@
2929

3030
using IsaVersion = std::array<int, 3>;
3131

32-
std::pair<int, std::string>
33-
run(const std::vector<char*>& cmd, const std::string& input, bool debug = false);
34-
std::string demangle(const char* name);
32+
std::pair<int, std::string> runComgr(const std::string& input,
33+
const std::string& gfxStr,
34+
const char** optionStr,
35+
const size_t optionSize,
36+
bool debug);
37+
std::string demangle(const char* name);
3538

3639
inline std::string getGfxNameTuple(const IsaVersion& isaVersion)
3740
{
3841
/*Converts an ISA version to a gfx architecture name.
3942
4043
Args:
4144
arch: An object representing the major, minor, and step version of the ISA.
42-
45+
4346
Returns:
4447
The name of the GPU architecture (e.g., 'gfx906').
4548
*/

0 commit comments

Comments
 (0)