From 7a9c623a310c61b89e1182d4bce716fbd6d0b002 Mon Sep 17 00:00:00 2001 From: mlcommons-bot Date: Fri, 7 Mar 2025 19:13:39 +0530 Subject: [PATCH 1/5] initial commit for oneapi --- script/get-one-api/COPYRIGHT.md | 9 +++ script/get-one-api/customize.py | 99 +++++++++++++++++++++++++++++++++ script/get-one-api/meta.yaml | 27 +++++++++ script/get-one-api/run.bat | 3 + script/get-one-api/run.sh | 8 +++ 5 files changed, 146 insertions(+) create mode 100644 script/get-one-api/COPYRIGHT.md create mode 100644 script/get-one-api/customize.py create mode 100644 script/get-one-api/meta.yaml create mode 100644 script/get-one-api/run.bat create mode 100644 script/get-one-api/run.sh diff --git a/script/get-one-api/COPYRIGHT.md b/script/get-one-api/COPYRIGHT.md new file mode 100644 index 000000000..d2ceead84 --- /dev/null +++ b/script/get-one-api/COPYRIGHT.md @@ -0,0 +1,9 @@ +# Copyright Notice + +© 2025-2026 MLCommons. All Rights Reserved. + +This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License can be obtained at: + +[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + +Unless required by applicable law or agreed to in writing, software distributed under the License is provided on an "AS IS" basis, without warranties or conditions of any kind, either express or implied. Please refer to the License for the specific language governing permissions and limitations under the License. diff --git a/script/get-one-api/customize.py b/script/get-one-api/customize.py new file mode 100644 index 000000000..25a487d97 --- /dev/null +++ b/script/get-one-api/customize.py @@ -0,0 +1,99 @@ +from mlc import utils +import os + + +def preprocess(i): + + os_info = i['os_info'] + + env = i['env'] + + recursion_spaces = i['recursion_spaces'] + file_name_c = 'oneapi.exe' if os_info['platform'] == 'windows' else 'oneapi-cli' + + if 'MLC_ONEAPI_BIN_WITH_PATH' not in env: + if env.get('MLC_ONEAPI_DIR_PATH', '') != '': + oneapi_path = env['MLC_ONEAPI_DIR_PATH'] + if os.path.exists(os.path.join(oneapi_path, 'bin', 'oneapi-cli')): + env['MLC_TMP_PATH'] = os.path.join(oneapi_path, 'bin') + + if 'MLC_ONEAPI_BIN_WITH_PATH' not in env: + r = i['automation'].find_artifact({'file_name': file_name_c, + 'env': env, + 'os_info': os_info, + 'default_path_env_key': 'PATH', + 'detect_version': True, + 'env_path_key': 'MLC_ONEAPI_BIN_WITH_PATH', + 'run_script_input': i['run_script_input'], + 'recursion_spaces': recursion_spaces}) + if r['return'] > 0: + # Uncomment when MLC script for installing oneapi compiler is integrated + # Initial finding suggests that oneapi could be installed without hastle in linux using apt, but is tricky in windows + + # if r['return'] == 16: + # if env.get('MLC_TMP_FAIL_IF_NOT_FOUND','').lower() == 'yes': + # return r + # + # print (recursion_spaces+' # {}'.format(r['error'])) + # + # # Attempt to run installer + # r = {'return':0, 'skip':True, 'script':{'tags':'install,gcc,src'}} + + return r + + return {'return': 0} + + +def detect_version(i): + r = i['automation'].parse_version({'match_text': r'^.*$', + 'group_number': 1, + 'env_key': 'MLC_ONEAPI_VERSION', + 'which_env': i['env']}) + if r['return'] > 0: + if 'clang' in r['error']: + return {'return': 0, 'version': -1} + return r + version = r['version'] + + print(i['recursion_spaces'] + ' Detected version: {}'.format(version)) + + return {'return': 0, 'version': version} + + +def postprocess(i): + + env = i['env'] + r = detect_version(i) + if r['return'] > 0: + return r + + env['MLC_COMPILER_FAMILY'] = 'ONEAPI' + version = r['version'] + env['MLC_COMPILER_VERSION'] = env['MLC_ONEAPI_VERSION'] + env['MLC_GCC_CACHE_TAGS'] = 'version-' + version + env['MLC_COMPILER_CACHE_TAGS'] = 'version-' + version + ',family-oneapi' + + found_file_path = env['MLC_ONEAPI_BIN_WITH_PATH'] + + found_path = os.path.dirname(found_file_path) + + env['MLC_ONEAPI_INSTALLED_PATH'] = found_path + + file_name_c = os.path.basename(found_file_path) + + env['MLC_ONEAPI_BIN'] = file_name_c + + # General compiler for general program compilation + env['MLC_ONEAPI_COMPILER_BIN'] = file_name_c + env['MLC_ONEAPI_COMPILER_FLAG_OUTPUT'] = '' + env['MLC_ONEAPI_COMPILER_WITH_PATH'] = found_file_path + env['MLC_ONEAPI_COMPILER_FLAG_VERSION'] = 'version' + + # env['MLC_COMPILER_FLAGS_FAST'] = "-O3" + # env['MLC_LINKER_FLAGS_FAST'] = "-O3" + # env['MLC_COMPILER_FLAGS_DEBUG'] = "-O0" + # env['MLC_LINKER_FLAGS_DEBUG'] = "-O0" + # env['MLC_COMPILER_FLAGS_DEFAULT'] = "-O2" + # env['MLC_LINKER_FLAGS_DEFAULT'] = "-O2" + + return {'return': 0, 'version': version} diff --git a/script/get-one-api/meta.yaml b/script/get-one-api/meta.yaml new file mode 100644 index 000000000..edbc993b4 --- /dev/null +++ b/script/get-one-api/meta.yaml @@ -0,0 +1,27 @@ +alias: get-one-api +automation_alias: script +automation_uid: 5b4e0237da074764 +cache: true +category: Compiler automation +clean_files: [] +deps: +- tags: detect,os +name: Detect or install OneAPI compiler +new_env_keys: +- MLC_ONEAPI_* +- MLC_ONEAPI_COMPILER_* +- MLC_COMPILER_* +- MLC_LINKER_* +post_deps: +- tags: get,compiler-flags +sort: 500 +tags: +- get +- oneapi +- compiler +- get-oneapi +uid: 1af872e81ef54742 +variations: + _path.#: + env: + MLC_ONEAPI_DIR_PATH: null diff --git a/script/get-one-api/run.bat b/script/get-one-api/run.bat new file mode 100644 index 000000000..5c02e5332 --- /dev/null +++ b/script/get-one-api/run.bat @@ -0,0 +1,3 @@ +%MLC_GCC_BIN_WITH_PATH% version > tmp-ver.out +IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% + diff --git a/script/get-one-api/run.sh b/script/get-one-api/run.sh new file mode 100644 index 000000000..748c07ed3 --- /dev/null +++ b/script/get-one-api/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash +gcc_bin=${MLC_ONEAPI_BIN_WITH_PATH} +echo "${gcc_bin} version" + +${gcc_bin} version > tmp-ver.out +test $? -eq 0 || exit 1 + +cat tmp-ver.out From ad8f8e2207b1316114eecb4d23ae8a7225b8d61b Mon Sep 17 00:00:00 2001 From: mlcommons-bot Date: Fri, 7 Mar 2025 19:21:16 +0530 Subject: [PATCH 2/5] fix group number --- script/get-one-api/customize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/get-one-api/customize.py b/script/get-one-api/customize.py index 25a487d97..8cd431114 100644 --- a/script/get-one-api/customize.py +++ b/script/get-one-api/customize.py @@ -46,7 +46,7 @@ def preprocess(i): def detect_version(i): r = i['automation'].parse_version({'match_text': r'^.*$', - 'group_number': 1, + 'group_number': 0, 'env_key': 'MLC_ONEAPI_VERSION', 'which_env': i['env']}) if r['return'] > 0: From 8c66664d6592f7bc3d4fccc65d83bca5bb99ea1a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 7 Mar 2025 13:51:34 +0000 Subject: [PATCH 3/5] [Automated Commit] Format Codebase [skip ci] --- script/get-one-api/customize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/get-one-api/customize.py b/script/get-one-api/customize.py index 8cd431114..b6d279213 100644 --- a/script/get-one-api/customize.py +++ b/script/get-one-api/customize.py @@ -28,7 +28,8 @@ def preprocess(i): 'recursion_spaces': recursion_spaces}) if r['return'] > 0: # Uncomment when MLC script for installing oneapi compiler is integrated - # Initial finding suggests that oneapi could be installed without hastle in linux using apt, but is tricky in windows + # Initial finding suggests that oneapi could be installed without + # hastle in linux using apt, but is tricky in windows # if r['return'] == 16: # if env.get('MLC_TMP_FAIL_IF_NOT_FOUND','').lower() == 'yes': From 1c108347fbfeefebe0c6579ef1fe3f0e3874226b Mon Sep 17 00:00:00 2001 From: mlcommons-bot Date: Fri, 7 Mar 2025 19:25:32 +0530 Subject: [PATCH 4/5] code fixes --- script/get-one-api/customize.py | 3 +-- script/get-one-api/run.sh | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/script/get-one-api/customize.py b/script/get-one-api/customize.py index 8cd431114..5d2dadc40 100644 --- a/script/get-one-api/customize.py +++ b/script/get-one-api/customize.py @@ -50,9 +50,8 @@ def detect_version(i): 'env_key': 'MLC_ONEAPI_VERSION', 'which_env': i['env']}) if r['return'] > 0: - if 'clang' in r['error']: - return {'return': 0, 'version': -1} return r + version = r['version'] print(i['recursion_spaces'] + ' Detected version: {}'.format(version)) diff --git a/script/get-one-api/run.sh b/script/get-one-api/run.sh index 748c07ed3..5cb2fa044 100644 --- a/script/get-one-api/run.sh +++ b/script/get-one-api/run.sh @@ -1,8 +1,8 @@ #!/bin/bash -gcc_bin=${MLC_ONEAPI_BIN_WITH_PATH} -echo "${gcc_bin} version" +oneapi_bin=${MLC_ONEAPI_BIN_WITH_PATH} +echo "${oneapi_bin} version" -${gcc_bin} version > tmp-ver.out +${oneapi_bin} version > tmp-ver.out test $? -eq 0 || exit 1 cat tmp-ver.out From 5a665220c890bb2d6084bf75e41e5bc4315bb3ae Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 7 Mar 2025 13:56:34 +0000 Subject: [PATCH 5/5] [Automated Commit] Format Codebase [skip ci] --- script/get-one-api/customize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/get-one-api/customize.py b/script/get-one-api/customize.py index 458808600..1dade8a51 100644 --- a/script/get-one-api/customize.py +++ b/script/get-one-api/customize.py @@ -52,7 +52,7 @@ def detect_version(i): 'which_env': i['env']}) if r['return'] > 0: return r - + version = r['version'] print(i['recursion_spaces'] + ' Detected version: {}'.format(version))