Skip to content

[rocisa] Use comgr instead of calling amdclang++ #1952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tensilelite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ cmake_minimum_required(VERSION 3.15)
# 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 -DTENSILE_BIN=Tensile -DDEVELOP_MODE=ON ..
# 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 ./
# 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 -DTENSILE_BIN=Tensile -DBIN_ARGS="config.yaml ./" .. && cmake --build .
# 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.
Expand Down Expand Up @@ -123,7 +123,7 @@ else()
message(STATUS "Script set: ${TENSILE_BIN} ${BIN_ARGS_LIST}")

# Ensure the Python script runs after the build
add_custom_target(RunPythonScript
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}"
Expand Down
4 changes: 2 additions & 2 deletions tensilelite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

** How to Rebuild Object Codes Directly from Assembly

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.
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.

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.

Expand All @@ -14,7 +14,7 @@ Assumptions:

Example:

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

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:

Expand Down
4 changes: 4 additions & 0 deletions tensilelite/rocisa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(amd_comgr REQUIRED CONFIG)

if(DEFINED Python_EXECUTABLE AND Python_EXECUTABLE)
message(STATUS "Manually set Python_EXECUTABLE to ${Python_EXECUTABLE}")
endif()
Expand Down Expand Up @@ -73,5 +75,7 @@ nanobind_add_module(rocisa NOMINSIZE NB_SUPPRESS_WARNINGS
${CMAKE_CURRENT_SOURCE_DIR}/rocisa/src/macro.cpp
${ROCISAINST_SOURCE}
${ROCISAPASS_SOURCE})

target_include_directories(rocisa PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rocisa/include)
target_link_libraries(rocisa PRIVATE amd_comgr)
set_target_properties(rocisa PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
24 changes: 10 additions & 14 deletions tensilelite/rocisa/rocisa/include/hardware_caps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,23 @@ inline bool tryAssembler(const IsaVersion& isaVersion,
if(isaVersion[0] >= 10)
options.push_back("-mwavefrontsize64");

std::string isastr = getGfxNameTuple(isaVersion);

std::vector<std::string> cmd
= {assemblerPath, "-x", "assembler", "-target", "amdgcn-amdhsa", "-mcpu=" + isastr};
for(auto o : options)
const char** optionStr = new const char*[options.size()];
std::string optionOneLineStr = "";
for(size_t i = 0; i < options.size(); i++)
{
cmd.push_back(o);
optionStr[i] = options[i].c_str();
optionOneLineStr += options[i] + " ";
}
cmd.push_back("-");
std::vector<char*> args(cmd.size());
std::transform(cmd.begin(), cmd.end(), args.begin(), [](auto& str) { return &str[0]; });
args.push_back(nullptr);
auto [rcode, result] = run(args, asmString, debug);
std::string isastr = getGfxNameTuple(isaVersion);

auto [rcode, result] = runComgr(asmString, isastr, optionStr, options.size(), debug);
delete[] optionStr;

if(debug)
{
std::string s;
for(auto c : cmd)
s += c + " ";
std::cout << "isaVersion: " << isastr << std::endl;
std::cout << "asm_cmd: " << s << std::endl;
std::cout << "options: " << optionOneLineStr << std::endl;
std::cout << "asmString: " << asmString << std::endl;
std::cout << "result: " << result << std::endl;
std::cout << "return code: " << rcode << std::endl;
Expand Down
11 changes: 7 additions & 4 deletions tensilelite/rocisa/rocisa/include/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@

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

std::pair<int, std::string>
run(const std::vector<char*>& cmd, const std::string& input, bool debug = false);
std::string demangle(const char* name);
std::pair<int, std::string> runComgr(const std::string& input,
const std::string& gfxStr,
const char** optionStr,
const size_t optionSize,
bool debug);
std::string demangle(const char* name);

inline std::string getGfxNameTuple(const IsaVersion& isaVersion)
{
/*Converts an ISA version to a gfx architecture name.

Args:
arch: An object representing the major, minor, and step version of the ISA.

Returns:
The name of the GPU architecture (e.g., 'gfx906').
*/
Expand Down
Loading