Skip to content

Commit c1c8ba8

Browse files
zhzhcookieArinaJJH
andauthored
[BACKEND] Support metax plugin (#6)
* [BACKEND] Support metax plugin * [BACKEND] [TEST] Add metax python unit test --------- Co-authored-by: ArinaJJH <jiangjh0930@163.com>
1 parent 3378570 commit c1c8ba8

File tree

115 files changed

+31435
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+31435
-4
lines changed
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: Metax-Build-And-Test
22

33
on:
4-
workflow_call:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
58

69
concurrency:
710
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -12,18 +15,46 @@ jobs:
1215
runs-on: metax
1316
if: ${{ github.repository == 'FlagTree/flagtree' }}
1417
steps:
15-
- name: Checkout code
18+
- name: Checkout code (attempt 1)
19+
id: checkout1
1620
uses: actions/checkout@v4
21+
continue-on-error: true
22+
23+
- name: Sleep before checkout2
24+
if: steps.checkout1.outcome == 'failure'
25+
run: |
26+
echo "First checkout attempt failed. Sleeping for 120 seconds before retry..."
27+
sleep 120
28+
29+
- name: Checkout code (attempt 2)
30+
id: checkout2
31+
if: steps.checkout1.outcome == 'failure'
32+
uses: actions/checkout@v4
33+
continue-on-error: true
34+
35+
- name: Sleep before final checkout
36+
if: steps.checkout1.outcome == 'failure' && steps.checkout2.outcome == 'failure'
37+
run: |
38+
echo "Second checkout attempt failed. Sleeping for 180 seconds before final retry..."
39+
sleep 180
40+
41+
- name: Checkout code (final attempt)
42+
if: steps.checkout1.outcome == 'failure' && steps.checkout2.outcome == 'failure'
43+
uses: actions/checkout@v4
44+
45+
- name: Verify checkout success
46+
if: success()
47+
run: echo "Checkout completed successfully"
1748

1849
- name: FlagTree Build on Metax
1950
shell: bash
2051
run: |
2152
source ~/env.sh
2253
export FLAGTREE_BACKEND=metax
2354
cd python
24-
MAX_JOBS=20 pip3 install . --no-build-isolation
55+
MAX_JOBS=32 python3.10 -m pip install . --no-build-isolation
2556
2657
- name: FlagTree Test on Metax
2758
shell: bash
2859
run: |
29-
pytest -s python/test/unit
60+
python3.10 -m pytest -s third_party/metax/python/test/unit

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ else()
7979
endif()
8080
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -D__STDC_FORMAT_MACROS -fPIC -std=gnu++17")
8181

82+
if(FLAGTREE_BACKEND STREQUAL "metax")
83+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_MACA -DUSE_MACA_OPAQUE_PTR -DUSE_BUILTIN -Wno-unused-result -Wno-attributes")
84+
endif()
8285

8386
# #########
8487
# LLVM
@@ -322,6 +325,33 @@ if(TRITON_BUILD_PYTHON_MODULE)
322325
LLVMXCNCodeGen
323326
LLVMXCNAsmParser
324327
)
328+
elseif(FLAGTREE_BACKEND STREQUAL "metax")
329+
set(TRITON_LIBRARIES
330+
${triton_libs}
331+
${triton_plugins}
332+
333+
# mlir
334+
MLIRMACADialect
335+
MLIRGPUToMACATransforms
336+
MLIRGPUToGPURuntimeTransforms
337+
MLIRGPUTransforms
338+
MLIRIR
339+
MLIRControlFlowToLLVM
340+
MLIRBytecodeWriter
341+
MLIRPass
342+
MLIRTransforms
343+
MLIRLLVMDialect
344+
MLIRSupport
345+
MLIRTargetLLVMIRExport
346+
MLIRMathToLLVM
347+
MLIRGPUDialect
348+
MLIRSCFToControlFlow
349+
MLIRIndexToLLVM
350+
351+
# LLVM
352+
LLVMPasses
353+
LLVMNVPTXCodeGen
354+
)
325355
endif()
326356

327357
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR # Linux arm64
@@ -352,6 +382,10 @@ if(TRITON_BUILD_PYTHON_MODULE)
352382
add_compile_definitions(TRITON_BACKENDS_TUPLE=${TRITON_BACKENDS_TUPLE})
353383
if(FLAGTREE_BACKEND STREQUAL "cambricon")
354384
add_library(triton SHARED)
385+
elseif(FLAGTREE_BACKEND STREQUAL "metax")
386+
add_library(triton SHARED ${PYTHON_SRC_PATH}/main.cc
387+
${PYTHON_SRC_PATH}/interpreter.cc
388+
${PYTHON_SRC_PATH}/llvm.cc)
355389
else()
356390
add_library(triton SHARED ${PYTHON_SRC_PATH}/main.cc
357391
${PYTHON_SRC_PATH}/ir.cc

third_party/metax/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
add_subdirectory(include)
2+
add_subdirectory(lib)
3+
4+
if(TRITON_BUILD_PYTHON_MODULE)
5+
if(FLAGTREE_PLUGIN)
6+
add_subdirectory(plugin)
7+
add_triton_plugin(TritonMetax
8+
SHARED_LIB metaxTritonPlugin
9+
)
10+
else()
11+
find_library(metaxTritonPluginLib
12+
NAMES
13+
metaxTritonPlugin.so
14+
PATHS
15+
${CMAKE_CURRENT_SOURCE_DIR}
16+
REQUIRED
17+
)
18+
add_triton_plugin(TritonMetax
19+
SHARED_LIB ${metaxTritonPluginLib}
20+
)
21+
endif()
22+
endif()
23+
24+
add_subdirectory(bin)

third_party/metax/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2018-2020 Philippe Tillet
3+
* Copyright 2020-2022 OpenAI
4+
* Copyright 2025 MetaX Integrated Circuits (Shanghai) Co., Ltd.
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files
8+
* (the "Software"), to deal in the Software without restriction,
9+
* including without limitation the rights to use, copy, modify, merge,
10+
* publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so,
12+
* subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/

third_party/metax/backend/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)