From c9569c880be7cd5517341832a36af62dfa196a1a Mon Sep 17 00:00:00 2001 From: zhengyang Date: Wed, 18 Jun 2025 17:28:22 +0800 Subject: [PATCH 1/2] [BUILD] Fix tsingmicro install bin and lib --- third_party/tsingmicro/CMakeLists.txt | 1 + third_party/tsingmicro/bin/CMakeLists.txt | 19 +++++++++++++++++ third_party/tsingmicro/crt/CMakeLists.txt | 25 +++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/third_party/tsingmicro/CMakeLists.txt b/third_party/tsingmicro/CMakeLists.txt index ef84b07e7..1e32c0b57 100644 --- a/third_party/tsingmicro/CMakeLists.txt +++ b/third_party/tsingmicro/CMakeLists.txt @@ -6,6 +6,7 @@ if(NOT DEFINED TX8_HOME) endif() endif() +set(TSM_BACKEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/backend) set(XUANTIE_NAME Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/third_party/tsingmicro/bin/CMakeLists.txt b/third_party/tsingmicro/bin/CMakeLists.txt index 38c4ea7b6..5dca7362a 100644 --- a/third_party/tsingmicro/bin/CMakeLists.txt +++ b/third_party/tsingmicro/bin/CMakeLists.txt @@ -5,6 +5,12 @@ get_property(triton_libs GLOBAL PROPERTY TRITON_LIBS) add_llvm_executable(tsingmicro-opt tsingmicro-opt.cpp PARTIAL_SOURCES_INTENDED) +if (DEFINED TSM_BACKEND_DIR) + set(TSM_BIN_OUT ${TSM_BACKEND_DIR}/bin) +else () + set(TSM_BIN_OUT ${CMAKE_BINARY_DIR}/bin) +endif () + # TODO: what's this? llvm_update_compile_flags(tsingmicro-opt) target_link_libraries(tsingmicro-opt PRIVATE @@ -22,6 +28,9 @@ target_link_libraries(tsingmicro-opt PRIVATE MLIRPass MLIRTransforms ) +set_target_properties(tsingmicro-opt PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${TSM_BIN_OUT} +) mlir_check_all_link_libraries(tsingmicro-opt) @@ -43,6 +52,9 @@ target_link_libraries(tsingmicro-reduce PRIVATE MLIRPass MLIRTransforms ) +set_target_properties(tsingmicro-reduce PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${TSM_BIN_OUT} +) mlir_check_all_link_libraries(tsingmicro-reduce) @@ -64,6 +76,9 @@ target_link_libraries(tsingmicro-lsp PRIVATE MLIRPass MLIRTransforms ) +set_target_properties(tsingmicro-lsp PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${TSM_BIN_OUT} +) mlir_check_all_link_libraries(tsingmicro-lsp) @@ -86,3 +101,7 @@ target_link_libraries(tsingmicro-llvm-opt PRIVATE LLVMCodeGen ) export_executable_symbols_for_plugins(tsingmicro-llvm-opt) + +set_target_properties(tsingmicro-llvm-opt PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${TSM_BIN_OUT} +) diff --git a/third_party/tsingmicro/crt/CMakeLists.txt b/third_party/tsingmicro/crt/CMakeLists.txt index f294fab8c..6cf709496 100644 --- a/third_party/tsingmicro/crt/CMakeLists.txt +++ b/third_party/tsingmicro/crt/CMakeLists.txt @@ -78,6 +78,19 @@ add_library(${VENDOR_RUNTIME_LIB} STATIC ${VENDOR_SOURCES}) target_compile_options(${VENDOR_RUNTIME_LIB} PRIVATE ${RISCV_COMPILE_OPTIONS}) target_link_options(${VENDOR_RUNTIME_LIB} PRIVATE --target=${RISCV_TRIPLE}) +if (DEFINED TSM_BACKEND_DIR) + set_target_properties(${VENDOR_RUNTIME_LIB} PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY ${TSM_BACKEND_DIR}/lib + ) +else () + # Set properties for the library + set_target_properties(${VENDOR_RUNTIME_LIB} PROPERTIES + POSITION_INDEPENDENT_CODE ON + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib + ) +endif () + # Setup compiler and environment for RISC-V compilation if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Use the existing Clang installation with target triple @@ -103,3 +116,15 @@ else() COMMAND ${CMAKE_COMMAND} -E echo "Building ${VENDOR_RUNTIME_LIB} for RISC-V target" ) endif() + +# Install targets +install(TARGETS ${VENDOR_RUNTIME_LIB} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin +) + +# Install headers (optional) +file(GLOB_RECURSE VENDOR_HEADERS Target/lib/${TARGET}/*.h) +install(FILES ${VENDOR_HEADERS} DESTINATION include/${TARGET}) +install(FILES Target/lib/${TARGET}/libkcorert.a DESTINATION lib/${TARGET}) From 4c06d04b20ace10758f2cf26c3a7a97e03390d16 Mon Sep 17 00:00:00 2001 From: zhengyang Date: Wed, 18 Jun 2025 17:45:40 +0800 Subject: [PATCH 2/2] [BUILD] Update tsingmicro build opt --- .github/workflows/tsingmicro-build-and-test.yml | 2 ++ python/setup.py | 1 + third_party/tsingmicro/crt/CMakeLists.txt | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tsingmicro-build-and-test.yml b/.github/workflows/tsingmicro-build-and-test.yml index 276f06db7..171a93e6f 100644 --- a/.github/workflows/tsingmicro-build-and-test.yml +++ b/.github/workflows/tsingmicro-build-and-test.yml @@ -58,3 +58,5 @@ jobs: run: | source ~/env.sh python3.11 -c 'import triton; print(triton.__path__)' + /usr/local/lib/python3.11/dist-packages/triton/backends/tsingmicro/bin/tsingmicro-opt --version + /usr/local/lib/python3.11/dist-packages/triton/backends/tsingmicro/bin/tsingmicro-llvm-opt --version diff --git a/python/setup.py b/python/setup.py index 999933281..ed7fc50bc 100644 --- a/python/setup.py +++ b/python/setup.py @@ -400,6 +400,7 @@ def run(self): cmake_major, cmake_minor = int(match.group("major")), int(match.group("minor")) if (cmake_major, cmake_minor) < (3, 18): raise RuntimeError("CMake >= 3.18.0 is required") + for ext in self.extensions: self.build_extension(ext) diff --git a/third_party/tsingmicro/crt/CMakeLists.txt b/third_party/tsingmicro/crt/CMakeLists.txt index 6cf709496..a373753a2 100644 --- a/third_party/tsingmicro/crt/CMakeLists.txt +++ b/third_party/tsingmicro/crt/CMakeLists.txt @@ -127,4 +127,3 @@ install(TARGETS ${VENDOR_RUNTIME_LIB} # Install headers (optional) file(GLOB_RECURSE VENDOR_HEADERS Target/lib/${TARGET}/*.h) install(FILES ${VENDOR_HEADERS} DESTINATION include/${TARGET}) -install(FILES Target/lib/${TARGET}/libkcorert.a DESTINATION lib/${TARGET})