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..1dade8a51 --- /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': 0, + 'env_key': 'MLC_ONEAPI_VERSION', + 'which_env': i['env']}) + if r['return'] > 0: + 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..5cb2fa044 --- /dev/null +++ b/script/get-one-api/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash +oneapi_bin=${MLC_ONEAPI_BIN_WITH_PATH} +echo "${oneapi_bin} version" + +${oneapi_bin} version > tmp-ver.out +test $? -eq 0 || exit 1 + +cat tmp-ver.out