Skip to content

Commit adec331

Browse files
authored
Add get-oneapi compiler(WIP) (#294)
* initial commit for oneapi * fix group number * [Automated Commit] Format Codebase [skip ci] * code fixes * [Automated Commit] Format Codebase [skip ci]
1 parent 0c16655 commit adec331

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed

script/get-one-api/COPYRIGHT.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright Notice
2+
3+
© 2025-2026 MLCommons. All Rights Reserved.
4+
5+
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:
6+
7+
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
8+
9+
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.

script/get-one-api/customize.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from mlc import utils
2+
import os
3+
4+
5+
def preprocess(i):
6+
7+
os_info = i['os_info']
8+
9+
env = i['env']
10+
11+
recursion_spaces = i['recursion_spaces']
12+
file_name_c = 'oneapi.exe' if os_info['platform'] == 'windows' else 'oneapi-cli'
13+
14+
if 'MLC_ONEAPI_BIN_WITH_PATH' not in env:
15+
if env.get('MLC_ONEAPI_DIR_PATH', '') != '':
16+
oneapi_path = env['MLC_ONEAPI_DIR_PATH']
17+
if os.path.exists(os.path.join(oneapi_path, 'bin', 'oneapi-cli')):
18+
env['MLC_TMP_PATH'] = os.path.join(oneapi_path, 'bin')
19+
20+
if 'MLC_ONEAPI_BIN_WITH_PATH' not in env:
21+
r = i['automation'].find_artifact({'file_name': file_name_c,
22+
'env': env,
23+
'os_info': os_info,
24+
'default_path_env_key': 'PATH',
25+
'detect_version': True,
26+
'env_path_key': 'MLC_ONEAPI_BIN_WITH_PATH',
27+
'run_script_input': i['run_script_input'],
28+
'recursion_spaces': recursion_spaces})
29+
if r['return'] > 0:
30+
# Uncomment when MLC script for installing oneapi compiler is integrated
31+
# Initial finding suggests that oneapi could be installed without
32+
# hastle in linux using apt, but is tricky in windows
33+
34+
# if r['return'] == 16:
35+
# if env.get('MLC_TMP_FAIL_IF_NOT_FOUND','').lower() == 'yes':
36+
# return r
37+
#
38+
# print (recursion_spaces+' # {}'.format(r['error']))
39+
#
40+
# # Attempt to run installer
41+
# r = {'return':0, 'skip':True, 'script':{'tags':'install,gcc,src'}}
42+
43+
return r
44+
45+
return {'return': 0}
46+
47+
48+
def detect_version(i):
49+
r = i['automation'].parse_version({'match_text': r'^.*$',
50+
'group_number': 0,
51+
'env_key': 'MLC_ONEAPI_VERSION',
52+
'which_env': i['env']})
53+
if r['return'] > 0:
54+
return r
55+
56+
version = r['version']
57+
58+
print(i['recursion_spaces'] + ' Detected version: {}'.format(version))
59+
60+
return {'return': 0, 'version': version}
61+
62+
63+
def postprocess(i):
64+
65+
env = i['env']
66+
r = detect_version(i)
67+
if r['return'] > 0:
68+
return r
69+
70+
env['MLC_COMPILER_FAMILY'] = 'ONEAPI'
71+
version = r['version']
72+
env['MLC_COMPILER_VERSION'] = env['MLC_ONEAPI_VERSION']
73+
env['MLC_GCC_CACHE_TAGS'] = 'version-' + version
74+
env['MLC_COMPILER_CACHE_TAGS'] = 'version-' + version + ',family-oneapi'
75+
76+
found_file_path = env['MLC_ONEAPI_BIN_WITH_PATH']
77+
78+
found_path = os.path.dirname(found_file_path)
79+
80+
env['MLC_ONEAPI_INSTALLED_PATH'] = found_path
81+
82+
file_name_c = os.path.basename(found_file_path)
83+
84+
env['MLC_ONEAPI_BIN'] = file_name_c
85+
86+
# General compiler for general program compilation
87+
env['MLC_ONEAPI_COMPILER_BIN'] = file_name_c
88+
env['MLC_ONEAPI_COMPILER_FLAG_OUTPUT'] = ''
89+
env['MLC_ONEAPI_COMPILER_WITH_PATH'] = found_file_path
90+
env['MLC_ONEAPI_COMPILER_FLAG_VERSION'] = 'version'
91+
92+
# env['MLC_COMPILER_FLAGS_FAST'] = "-O3"
93+
# env['MLC_LINKER_FLAGS_FAST'] = "-O3"
94+
# env['MLC_COMPILER_FLAGS_DEBUG'] = "-O0"
95+
# env['MLC_LINKER_FLAGS_DEBUG'] = "-O0"
96+
# env['MLC_COMPILER_FLAGS_DEFAULT'] = "-O2"
97+
# env['MLC_LINKER_FLAGS_DEFAULT'] = "-O2"
98+
99+
return {'return': 0, 'version': version}

script/get-one-api/meta.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
alias: get-one-api
2+
automation_alias: script
3+
automation_uid: 5b4e0237da074764
4+
cache: true
5+
category: Compiler automation
6+
clean_files: []
7+
deps:
8+
- tags: detect,os
9+
name: Detect or install OneAPI compiler
10+
new_env_keys:
11+
- MLC_ONEAPI_*
12+
- MLC_ONEAPI_COMPILER_*
13+
- MLC_COMPILER_*
14+
- MLC_LINKER_*
15+
post_deps:
16+
- tags: get,compiler-flags
17+
sort: 500
18+
tags:
19+
- get
20+
- oneapi
21+
- compiler
22+
- get-oneapi
23+
uid: 1af872e81ef54742
24+
variations:
25+
_path.#:
26+
env:
27+
MLC_ONEAPI_DIR_PATH: null

script/get-one-api/run.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%MLC_GCC_BIN_WITH_PATH% version > tmp-ver.out
2+
IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
3+

script/get-one-api/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
oneapi_bin=${MLC_ONEAPI_BIN_WITH_PATH}
3+
echo "${oneapi_bin} version"
4+
5+
${oneapi_bin} version > tmp-ver.out
6+
test $? -eq 0 || exit 1
7+
8+
cat tmp-ver.out

0 commit comments

Comments
 (0)