Skip to content

Add get-oneapi compiler(WIP) #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions script/get-one-api/COPYRIGHT.md
Original file line number Diff line number Diff line change
@@ -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.
99 changes: 99 additions & 0 deletions script/get-one-api/customize.py
Original file line number Diff line number Diff line change
@@ -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}
27 changes: 27 additions & 0 deletions script/get-one-api/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions script/get-one-api/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%MLC_GCC_BIN_WITH_PATH% version > tmp-ver.out
IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

8 changes: 8 additions & 0 deletions script/get-one-api/run.sh
Original file line number Diff line number Diff line change
@@ -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
Loading