From 4df824230ee327f11e56c660c787633721e79bcb Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Wed, 2 Apr 2025 17:15:53 +0530 Subject: [PATCH 1/6] Added kill process MLC script --- script/kill-process/customize.py | 52 ++++++++++++++++++++++++++++++++ script/kill-process/meta.yaml | 22 ++++++++++++++ script/kill-process/run.sh | 17 +++++++++++ 3 files changed, 91 insertions(+) create mode 100644 script/kill-process/customize.py create mode 100644 script/kill-process/meta.yaml create mode 100644 script/kill-process/run.sh diff --git a/script/kill-process/customize.py b/script/kill-process/customize.py new file mode 100644 index 000000000..c8311dd9e --- /dev/null +++ b/script/kill-process/customize.py @@ -0,0 +1,52 @@ +from mlc import utils +import os +import subprocess + + + +def generate_kill_command(env): + kill_cmd = "" + + if env.get("MLC_KILL_PROCESS_GROUP"): + if env.get("MLC_KILL_PROCESS_ID"): + process_id = env["MLC_KILL_PROCESS_ID"] + # Find process group and kill all processes in it + kill_cmd = f"pkill -g $(ps -o pgid= -p {process_id} | tr -d ' ')" + + elif env.get("MLC_KILL_PROCESS_NAME"): + process_name = env["MLC_KILL_PROCESS_NAME"] + # Find process group of the first matching process name and kill all in that group + kill_cmd = f"pkill -g $(pgrep -o {process_name} | xargs ps -o pgid= -p | tr -d ' ')" + + else: + if env.get("MLC_KILL_PROCESS_ID"): + process_id = env["MLC_KILL_PROCESS_ID"] + kill_cmd = f"kill {process_id}" # Kill a single process by ID + + elif env.get("MLC_KILL_PROCESS_NAME"): + process_name = env["MLC_KILL_PROCESS_NAME"] + kill_cmd = f"pkill {process_name}" # Kill all processes matching the name + + + env["MLC_RUN_CMD"] = kill_cmd if kill_cmd else "echo 'No valid input provided'" + + +def preprocess(i): + + env = i['env'] + state = i['state'] + os_info = i['os_info'] + + generate_kill_command(env) + + return {'return': 0} + + +def postprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + return {'return': 0} diff --git a/script/kill-process/meta.yaml b/script/kill-process/meta.yaml new file mode 100644 index 000000000..3c0335c27 --- /dev/null +++ b/script/kill-process/meta.yaml @@ -0,0 +1,22 @@ +alias: kill-process +automation_alias: script +automation_uid: 5b4e0237da074764 +category: MLC Script Template +deps: [] +new_env_keys: [] +new_state_keys: [] +post_deps: [] +posthook_deps: [] +prehook_deps: [] +tags: +- kill +- process +tests: + run_inputs: [] +uid: 27b5651692454cb6 +input_mapping: + group: MLC_KILL_PROCESS_GROUP + pid: MLC_KILL_PROCESS_ID + pname: MLC_KILL_PROCESS_NAME + + diff --git a/script/kill-process/run.sh b/script/kill-process/run.sh new file mode 100644 index 000000000..c4542b8c2 --- /dev/null +++ b/script/kill-process/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash +function exit_if_error() { + test $? -eq 0 || exit $? +} + +function run() { + echo "Running: " + echo "$1" + echo "" + if [[ ${MLC_FAKE_RUN} != 'yes' ]]; then + eval "$1" + exit_if_error + fi +} + +#Add your run commands here... +run "$MLC_RUN_CMD" From 80e3d98b8b50a20382d609efc970eb5113c75b75 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 2 Apr 2025 11:46:15 +0000 Subject: [PATCH 2/6] [Automated Commit] Format Codebase [skip ci] --- script/kill-process/customize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/script/kill-process/customize.py b/script/kill-process/customize.py index c8311dd9e..0c39a62eb 100644 --- a/script/kill-process/customize.py +++ b/script/kill-process/customize.py @@ -3,7 +3,6 @@ import subprocess - def generate_kill_command(env): kill_cmd = "" @@ -15,7 +14,8 @@ def generate_kill_command(env): elif env.get("MLC_KILL_PROCESS_NAME"): process_name = env["MLC_KILL_PROCESS_NAME"] - # Find process group of the first matching process name and kill all in that group + # Find process group of the first matching process name and kill + # all in that group kill_cmd = f"pkill -g $(pgrep -o {process_name} | xargs ps -o pgid= -p | tr -d ' ')" else: @@ -25,8 +25,8 @@ def generate_kill_command(env): elif env.get("MLC_KILL_PROCESS_NAME"): process_name = env["MLC_KILL_PROCESS_NAME"] - kill_cmd = f"pkill {process_name}" # Kill all processes matching the name - + # Kill all processes matching the name + kill_cmd = f"pkill {process_name}" env["MLC_RUN_CMD"] = kill_cmd if kill_cmd else "echo 'No valid input provided'" From ca5a156bb3d596d7507594b8bfbf758cc9b3332e Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 3 Apr 2025 19:21:22 +0530 Subject: [PATCH 3/6] Support base variation in dynamic variation --- automation/script/module.py | 9 ++++++--- script/install-llvm-src/meta.yaml | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index 32bfb94b2..a3ef83421 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -3146,7 +3146,7 @@ def _update_variation_meta_with_dynamic_suffix( value = variation_meta[key] if isinstance(value, list): # deps,pre_deps... - for item in value: + for i, item in enumerate(value): if isinstance(item, dict): for item_key in item: item_value = item[item_key] @@ -3163,6 +3163,9 @@ def _update_variation_meta_with_dynamic_suffix( else: item[item_key] = item[item_key].replace( "#", variation_tag_dynamic_suffix) + elif isinstance(item, str): + value[i] = value[i].replace( + "#", variation_tag_dynamic_suffix) elif isinstance(value, dict): # add_deps, env, .. for item in value: @@ -3188,8 +3191,8 @@ def _update_variation_meta_with_dynamic_suffix( value[item] = value[item].replace( "#", variation_tag_dynamic_suffix) - else: # scalar value - pass # no dynamic update for now + else: # scalar value, never used? + variation_meta[key] = variation_meta[key].replace("#", variation_tag_dynamic_suffix) ########################################################################## diff --git a/script/install-llvm-src/meta.yaml b/script/install-llvm-src/meta.yaml index 98456233a..461ca0d5a 100644 --- a/script/install-llvm-src/meta.yaml +++ b/script/install-llvm-src/meta.yaml @@ -56,6 +56,14 @@ tags: - src-llvm uid: 2af16e9a6c5f4702 variations: + version.main: + group: version + base: + - branch.main + version.#: + group: version + base: + - tag.# branch.#: env: MLC_GIT_CHECKOUT: '#' From 7c7e10d04271d935ab98b5f966520f507b1969e6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 3 Apr 2025 13:52:55 +0000 Subject: [PATCH 4/6] [Automated Commit] Format Codebase [skip ci] --- automation/script/module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index a3ef83421..28fe3e978 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -3165,7 +3165,7 @@ def _update_variation_meta_with_dynamic_suffix( "#", variation_tag_dynamic_suffix) elif isinstance(item, str): value[i] = value[i].replace( - "#", variation_tag_dynamic_suffix) + "#", variation_tag_dynamic_suffix) elif isinstance(value, dict): # add_deps, env, .. for item in value: @@ -3192,7 +3192,8 @@ def _update_variation_meta_with_dynamic_suffix( "#", variation_tag_dynamic_suffix) else: # scalar value, never used? - variation_meta[key] = variation_meta[key].replace("#", variation_tag_dynamic_suffix) + variation_meta[key] = variation_meta[key].replace( + "#", variation_tag_dynamic_suffix) ########################################################################## From 7428883959325a46e9ca91555420b9d984e92085 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 3 Apr 2025 14:57:29 +0100 Subject: [PATCH 5/6] Update build_wheels.yml --- .github/workflows/build_wheels.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 708ae35e4..86b93ac06 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -6,7 +6,6 @@ on: workflow_dispatch: {} jobs: - build_wheels: if: github.repository_owner == 'mlcommons' name: Build wheel From 554d3c3dce46423ed700cc2458949a7e0105478e Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 3 Apr 2025 19:39:05 +0530 Subject: [PATCH 6/6] Support _path.# for get-llvm --- script/get-llvm/customize.py | 13 +++++++++++++ script/get-llvm/meta.yaml | 3 +++ 2 files changed, 16 insertions(+) diff --git a/script/get-llvm/customize.py b/script/get-llvm/customize.py index 5e1eb0edf..e53a7719f 100644 --- a/script/get-llvm/customize.py +++ b/script/get-llvm/customize.py @@ -15,6 +15,19 @@ def preprocess(i): env['FILE_NAME_C'] = file_name_c if 'MLC_LLVM_CLANG_BIN_WITH_PATH' not in env: + + if env.get('MLC_LLVM_DIR_PATH', '') != '': + llvm_path = env['MLC_LLVM_DIR_PATH'] + if os.path.exists(os.path.join(llvm_path, 'bin', 'clang')): + env['MLC_TMP_PATH'] = os.path.join(llvm_path, 'bin') + else: + for l in os.listdir(aocc_path): + if os.path.exists(os.path.join( + llvm_path, l, 'bin', 'clang')): + llvm_path = os.path.join(llvm_path, l) + env['MLC_LLVM_DIR_PATH'] = llvm_path + env['MLC_TMP_PATH'] = os.path.join(llvm_path, 'bin') + r = i['automation'].find_artifact({'file_name': file_name_c, 'env': env, 'os_info': os_info, diff --git a/script/get-llvm/meta.yaml b/script/get-llvm/meta.yaml index cd6242287..8193227b7 100644 --- a/script/get-llvm/meta.yaml +++ b/script/get-llvm/meta.yaml @@ -46,3 +46,6 @@ variations: ad: llvm-install: tags: src,_clang + path.#: + env: + MLC_LLVM_DIR_PATH: '#'