Skip to content

Commit

Permalink
feat(triton-linalg): add ci for triton-linalg
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangqirui authored and sethbrin committed Jul 5, 2024
1 parent e4b0c26 commit 162315b
Show file tree
Hide file tree
Showing 17 changed files with 1,363 additions and 198 deletions.
52 changes: 52 additions & 0 deletions .github/ci_script/combine_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import time
import sys
import os
import argparse
'''
Get the result information fed back from the job server. If it is 'success' or 'failed', exit the pipeline. Otherwise, continue to monitor job information every 2 seconds.
output_path: the target file that you want to combine sub log with.
list_path: the list of sub log name. When it is updated, the correspondding file will be add to output tail.
list_dir_path: the dir path where sub logs stored.
status_path: the path of status file. When status file is written to "success" or "fail", exit script.
'''

def combine_log(output_path, list_path, list_dir_path, status_path):
# list_pos stores the last position that pointer of list file pointed to.
list_pos = 0
while True:
list_file = open(list_path, 'r')
list_file.seek(list_pos)
# read all lines starting from list_pos.
items = list_file.readlines()
# update list_pos
list_pos = list_file.tell()
# if read any line
if items is not None:
items.sort()
for item in items:
sub_path = item.strip()
if sub_path != "":
file_name = list_dir_path + '/' + sub_path
# while True:
if os.path.exists(file_name):
os.system('cat ' + file_name + ' >> ' + output_path)
# break
# check status_file, when read "success" or "fail" exit cycle, or else, sleep some seconds and start from beginning.
status_file = open(status_path)
status = status_file.readline().strip()
status_file.close()
if "fail" in status or "success" in status or "Success" in status or "Fail" in status or "error" in status or "Error" in status:
break
else:
time.sleep(2)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Monitor and concatenate files based on a list.")
parser.add_argument('output_path', type=str, help='The path to the output file.')
parser.add_argument('list_path', type=str, help='The path to the list file containing sub-paths.')
parser.add_argument('list_dir_path', type=str, help='The base directory where sub-paths are located.')
parser.add_argument('status_path', type=str, help='The path to the status file.')

args = parser.parse_args()
combine_log(args.output_path, args.list_path, args.list_dir_path, args.status_path)

37 changes: 37 additions & 0 deletions .github/ci_script/file_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import time
import sys
import os

def file_guard():
# where stores the last position that pointer pointed to.
where= 0
while True:
file = open(guard_log_file, "r")
file.seek(where)
# if read any lines, call system echo to print each line.
for line in file.readlines():
new_line = line.strip().replace("\'", "_").replace("\"", "_")
os.system('echo ' + "'%s'" % new_line)
# update where
where = file.tell()
file.close()
# check status, end process when read "success" or "fail"
status_file = open(guard_status_file, "r")
line = status_file.readline().strip()
status_file.close()
if "success" in line or "Success" in line:
print("Task success.")
break
elif "fail" in line or "Fail" in line or "error" in line or "Error" in line:
print("Task Fail.")
exit(-1)
# sleep for a while
time.sleep(2)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Monitor a log file and echo lines, check status to stop.")
parser.add_argument('guard_status_file', type=str, help='The path to the status file.')
parser.add_argument('guard_log_file', type=str, help='The path to the log file.')

args = parser.parse_args()

file_guard(args.guard_status_file, args.guard_log_file)
79 changes: 79 additions & 0 deletions .github/ci_script/triton-linalg-ci_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# /bin/bash
# Get PR id
PR_string=$(echo $GITHUB_REF | grep -Eo "/[0-9]*/")
pr_id=(${PR_string//// })

# Generate time stamp
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+10#`date "+%N"`/1000000))

# Temporally set to mlu370
card_type="MLU370-S4"

# Default repo name
repo_name="triton-linalg"
# Repo ci root path
repo_root="/home/user1/${repo_name}_ci/"
if [ ! -d $repo_root ];then
mkdir $repo_root
fi
# Repo ci requests path
requests_path="$repo_root/requests"
if [ ! -d $requests_path ];then
mkdir $requests_path
fi

# Gen name of this ci
request_name="${repo_name}_${pr_id}_${currentTimeStamp}_${card_type}.rqt"

# Gen file and dir for this request
request_root="$repo_root/$request_name/"
sub_logs_path="$request_root/sub_logs/"


if [ ! -d $request_root ];then
mkdir $request_root
fi

if [ ! -d $sub_logs_path ];then
mkdir $sub_logs_path
fi

echo "working" > "$request_root/status"
chmod o+w "$request_root/status"

if [ ! -f "$request_root/log" ];then
touch "$request_root/log"
fi

chmod o+w "$request_root/log"

if [ ! -f "$request_root/log_list" ];then
touch "$request_root/log_list"
fi

chmod o+w "$request_root/log_list"

# Gen request file.

echo "repo:${repo_name}" > "$requests_path/${request_name}"
echo "pr_id:${pr_id}" >> "$requests_path/${request_name}"
echo "timestamp:${currentTimeStamp}" >> "$requests_path/${request_name}"

# change dir group for server and client, or when server/client try to delete request, ftp may raise error.
# start script
python3 .github/ci_script/file_guard.py "$request_root/status" "$request_root/log" &
python3 .github/ci_script/combine_log.py "$request_root/log" "$request_root/log_list" "$request_root/sub_logs" "$request_root/status" &

wait

status=$( head -n +1 ${request_root}/status )

if [ "$status" != "success" ];then
echo "${status}"
exit -1
else
echo "${status}"
exit 0
fi
21 changes: 21 additions & 0 deletions .github/workflows/triton-linalg_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: triton-linalg_ci

on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
strategy:
matrix:
triton-linalg_version : [v1.1.1]
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- name: run_triton-linalg_ci
run: >
bash .github/ci_script/triton-linalg-ci_script.sh
10 changes: 5 additions & 5 deletions test/Conversion/arith-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ func.func @const_valid_int(%arg0: tensor<1x16x128x128xi32>) -> tensor<1x16x128x1
// -----
func.func @arith_addi(%arg0: tensor<128xi32>, %arg1: tensor<128xi32>) {
// CHECK: %[[INIT:.*]] = tensor.empty() : tensor<128xi32>
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.addi } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.addi {overflowFlags = #arith.overflow<none>} } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
%0 = arith.addi %arg0, %arg1 : tensor<128xi32>
return
}

// -----
func.func @arith_subi(%arg0: tensor<128xi32>, %arg1: tensor<128xi32>) {
// CHECK: %[[INIT:.*]] = tensor.empty() : tensor<128xi32>
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.subi } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.subi {overflowFlags = #arith.overflow<none>} } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
%0 = arith.subi %arg0, %arg1 : tensor<128xi32>
return
}

// -----
func.func @arith_muli(%arg0: tensor<128xi32>, %arg1: tensor<128xi32>) {
// CHECK: %[[INIT:.*]] = tensor.empty() : tensor<128xi32>
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.muli } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.muli {overflowFlags = #arith.overflow<none>} } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
%0 = arith.muli %arg0, %arg1 : tensor<128xi32>
return
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func.func @arith_xori(%arg0: tensor<128xi32>, %arg1: tensor<128xi32>) {
// -----
func.func @arith_shli(%arg0: tensor<128xi32>, %arg1: tensor<128xi32>) {
// CHECK: %[[INIT:.*]] = tensor.empty() : tensor<128xi32>
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.shli } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.shli {overflowFlags = #arith.overflow<none>} } ins(%arg0, %arg1 : tensor<128xi32>, tensor<128xi32>) outs(%[[INIT]] : tensor<128xi32>)
%0 = arith.shli %arg0, %arg1 : tensor<128xi32>
return
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func.func @arith_addi_dynamic(%arg0: tensor<128x?xi32>, %arg1: tensor<128x?xi32>
// CHECK: %[[CST:.*]] = arith.constant 1 : index
// CHECK: %[[DYNAMIC_DIM:.*]] = tensor.dim %arg0, %[[CST]] : tensor<128x?xi32>
// CHECK: %[[INIT:.*]] = tensor.empty(%[[DYNAMIC_DIM]]) : tensor<128x?xi32>
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.addi } ins(%arg0, %arg1 : tensor<128x?xi32>, tensor<128x?xi32>) outs(%[[INIT]] : tensor<128x?xi32>)
// CHECK: %[[MAPPED:.*]] = linalg.map { arith.addi {overflowFlags = #arith.overflow<none>} } ins(%arg0, %arg1 : tensor<128x?xi32>, tensor<128x?xi32>) outs(%[[INIT]] : tensor<128x?xi32>)
%0 = arith.addi %arg0, %arg1 : tensor<128x?xi32>
return
}
Expand Down
Loading

0 comments on commit 162315b

Please sign in to comment.