Skip to content

Commit

Permalink
Rewrite intel-linux to support oneAPI release.
Browse files Browse the repository at this point in the history
This rewrites the inte-linux toolset to support auto detection and
oneAPI version of compiler.
  • Loading branch information
grafikrobot committed Jan 22, 2021
1 parent 2377e08 commit 5ede4e8
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 116 deletions.
4 changes: 2 additions & 2 deletions src/engine/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ case "${B2_TOOLSET}" in

intel-*)
CXX_VERSION_OPT=${CXX_VERSION_OPT:=--version}
B2_CXXFLAGS_RELEASE="-O3 -s"
B2_CXXFLAGS_DEBUG="-O0 -g -p"
B2_CXXFLAGS_RELEASE="-O3 -s -static"
B2_CXXFLAGS_DEBUG="-O0 -g -p -static"
;;

vacpp)
Expand Down
296 changes: 182 additions & 114 deletions src/tools/intel-linux.jam
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
# http://www.boost.org/LICENSE_1_0.txt)

import toolset ;
import feature ;
import toolset : flags ;

import intel ;
import gcc ;
import common ;
import errors ;
import feature ;
import gcc ;
import generators ;
import type ;
import intel ;
import numbers ;
import os ;
import path ;
import regex ;
import type ;

feature.extend-subfeature toolset intel : platform : linux ;

Expand Down Expand Up @@ -45,123 +48,191 @@ if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
.debug-configuration = true ;
}

# Initializes the intel-linux toolset
# version in mandatory
# name (default icpc) is used to invoke the specified intel-linux compiler
# compile and link options allow you to specify addition command line options for each version
.home = [ os.home-directories ] ;
.home = $(.home[1]) ;

# Intel oneAPI 2020, and onward.
.bin(oneAPI) =
[ path.join $(.home) intel/oneapi/compiler/latest/linux/bin ]
/opt/intel/oneapi/compiler/latest/linux/bin ;
# Intel C++ Composer XE 2011 for Linux, aka Intel C++ Compiler XE 12.0,
# aka intel-linux-12.0.
.bin(12.0) = /opt/intel/bin ;
# Intel C++ Compiler 11.1.
.bin(11.1) = /opt/intel_cce_11.1.064.x86_64/bin ;
# Intel C++ Compiler 11.0.
.bin(11.0) = /opt/intel_cce_11.0.074.x86_64/bin ;
# Intel C++ Compiler 10.1.
.bin(10.1) = /opt/intel_cce_10.1.013_x64/bin ;
# Intel C++ Compiler 9.1.
.bin(9.1) = /opt/intel_cc_91/bin ;
# Intel C++ Compiler 9.0.
.bin(9.0) = /opt/intel_cc_90/bin ;
# Intel C++ Compiler 8.1.
.bin(8.1) = /opt/intel_cc_81/bin ;
# Intel C++ Compiler 8.0.
.bin(8.0) = /opt/intel_cc_80/bin ;

rule init ( version ? : command * : options * )
{
local condition = [ common.check-init-parameters intel-linux
: version $(version) ] ;

if $(.debug-configuration)
{
ECHO "notice: intel-linux version is" $(version) ;
}

local default_path ;

# Intel C++ Composer XE 2011 for Linux, aka Intel C++ Compiler XE 12.0,
# aka intel-linux-12.0. In this version, Intel thankfully decides to install
# to a sane 'intel' folder in /opt.
if [ MATCH "(12[.]0|12)" : $(version) ]
{ default_path = /opt/intel/bin ; }
# Intel C++ Compiler 11.1.
else if [ MATCH "(11[.]1)" : $(version) ]
{ default_path = /opt/intel_cce_11.1.064.x86_64/bin ; }
# Intel C++ Compiler 11.0.
else if [ MATCH "(11[.]0|11)" : $(version) ]
{ default_path = /opt/intel_cce_11.0.074.x86_64/bin ; }
# Intel C++ Compiler 10.1.
else if [ MATCH "(10[.]1)" : $(version) ]
{ default_path = /opt/intel_cce_10.1.013_x64/bin ; }
# Intel C++ Compiler 9.1.
else if [ MATCH "(9[.]1)" : $(version) ]
{ default_path = /opt/intel_cc_91/bin ; }
# Intel C++ Compiler 9.0.
else if [ MATCH "(9[.]0|9)" : $(version) ]
{ default_path = /opt/intel_cc_90/bin ; }
# Intel C++ Compiler 8.1.
else if [ MATCH "(8[.]1)" : $(version) ]
{ default_path = /opt/intel_cc_81/bin ; }
# Intel C++ Compiler 8.0 - this used to be the default, so now it's the
# fallback.
else
{ default_path = /opt/intel_cc_80/bin ; }

if $(.debug-configuration)
local user_version = [ MATCH "([0-9.]+)" : $(version) ] ;
local user_command = $(command) ;
if $(user_version)
{
ECHO "notice: default search path for intel-linux is" $(default_path) ;
user_version = [ regex.split $(user_version) "[.]" ] ;
}

command = [ common.get-invocation-command intel-linux : icpc
: $(command) : $(default_path) ] ;

common.handle-options intel-linux : $(condition) : $(command) : $(options) ;

local root = [ feature.get-values <root> : $(options) ] ;
local bin ;
if $(command) || $(root)
local command_lib_path ;
local detected_version ;
local detected_command ;
if ! $(user_version) && ! $(user_command)
{
bin ?= [ common.get-absolute-tool-path $(command[-1]) ] ;
root ?= $(bin:D) ;

local command-string = $(command:J=" ") ;
local version-output = [ SHELL "$(command-string) --version" ] ;
local real-version = [ MATCH "([0-9.]+)" : $(version-output) ] ;
local major = [ MATCH "([0-9]+).*" : $(real-version) ] ;

# If we failed to determine major version, use the behaviour for
# the current compiler.
if $(major) && [ numbers.less $(major) 10 ]
# If nothing given, try and discover the latest toolset available.
if ! $(detected_command)
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-Ob0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-Ob1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-Ob2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-O1" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
local bin_paths = $(.bin(oneAPI)) ;
detected_command = [ common.find-tool icpx : $(bin_paths) : path-last ] ;
command_lib_path = $(detected_command:D)/../compiler/lib/intel64 ;
}
else if $(major) && [ numbers.less $(major) 11 ]
if ! $(detected_command)
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-inline-level=0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-inline-level=1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-inline-level=2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-O1" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
local bin_paths = $(.bin(12.0)) $(.bin(11.1)) $(.bin(11.0)) ;
detected_command = [ common.find-tool icpc : $(bin_paths) : path-last ] ;
command_lib_path = $(detected_command:D)/../lib/x86_64 ;
}
else # newer version of intel do have -Os (at least 11+, don't know about 10)
if ! $(detected_command)
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-inline-level=0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-inline-level=1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-inline-level=2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-Os" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
local bin_paths = $(.bin(10.1)) $(.bin(9.1)) $(.bin(9.0))
$(.bin(8.1)) $(.bin(8.0)) ;
detected_command = [ common.find-tool icpc : $(bin_paths) : path-last ] ;
command_lib_path = $(detected_command:D)/../lib ;
}

if $(root)
if $(detected_command)
{
local version_cmd = "LD_LIBRARY_PATH=$(command_lib_path) $(detected_command) --version" ;
local version_output = [ SHELL $(version_cmd) ] ;
detected_version = [ MATCH "([0-9.]+)" : $(version_output) ] ;
}
}
else if $(user_command)
{
# If only a command given, determine the version from the command.
# Note, we assume that the user command does everything needed to
# property execute the command.
local version_cmd = $(user_command:J=" ") ;
local version_output = [ SHELL "$(version_cmd) --version" ] ;
detected_command = $(user_command) ;
detected_version = [ MATCH "([0-9.]+)" : $(version_output) ] ;
}
else if $(user_version)
{
# Only version given, try and find the command in the location for the version.
if [ numbers.less $(user_version[1]) 2020 ]
{
# Libraries required to run the executable may be in either
# $(root)/lib (10.1 and earlier)
# or
# $(root)/lib/architecture-name (11.0 and later:
local lib_path = $(root)/lib $(root:P)/lib/$(bin:B) ;
if $(.debug-configuration)
local version_xy = $(user_version[1]) $(user_version[2]) ;
local bin_paths = $(.bin($(version_xy:J=.))) ;
if $(bin_paths)
{
detected_command = [ common.find-tool icpc : $(bin_paths) : path-last ] ;
}
if [ numbers.less $(user_version[1]) 11 ]
{
ECHO notice\: using intel libraries "::" $(condition) "::" $(lib_path) ;
command_lib_path = $(detected_command:D)/../lib ;
}
flags intel-linux.link RUN_PATH $(condition) : $(lib_path) ;
else
{
command_lib_path = $(detected_command:D)/../lib/x86_64 ;
}
}
else
{
detected_command = [ common.find-tool icpx
: [ regex.replace-list $(.bin(oneAPI)) : "latest" : $(user_version:J=.) ]
: path-last ] ;
command_lib_path = $(detected_command:D)/../compiler/lib/intel64 ;
}
if $(detected_command)
{
local version_cmd = "LD_LIBRARY_PATH=$(command_lib_path) $(detected_command) --version" ;
local version_output = [ SHELL $(version_cmd) ] ;
detected_version = [ MATCH "([0-9.]+)" : $(version_output) ] ;
}
}
}

SPACE = " " ;
if $(.debug-configuration)
{
ECHO "notice: intel-linux command is" $(command:E=$(detected_command)) ;
}

version ?= $(detected_version) ;
local condition = [ common.check-init-parameters intel-linux : version $(version) ] ;

if $(.debug-configuration)
{
ECHO "notice: intel-linux version is" $(version) ;
}

command ?= $(detected_command) ;
common.handle-options intel-linux : $(condition) : $(command) : $(options) ;

local tool_version = $(detected_version) ;
if $(tool_version)
{
tool_version = [ regex.split $(tool_version) "[.]" ] ;
}
tool_version ?= $(user_version) ;

if [ numbers.less $(tool_version[1]) 10 ]
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-Ob0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-Ob1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-Ob2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-O1" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
}
else if [ numbers.less $(tool_version[1]) 11 ]
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-inline-level=0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-inline-level=1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-inline-level=2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-O1" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
}
else # newer version of intel do have -Os (at least 11+, don't know about 10)
{
flags intel-linux.compile OPTIONS $(condition)/<inlining>off : "-inline-level=0" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>on : "-inline-level=1" ;
flags intel-linux.compile OPTIONS $(condition)/<inlining>full : "-inline-level=2" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>space : "-Os" ;
flags intel-linux.compile OPTIONS $(condition)/<optimization>speed : "-O3 -ip" ;
}
if [ numbers.less $(tool_version[1]) 2020 ]
{
flags intel-linux.compile OPTIONS <warnings>off : -w0 ;
flags intel-linux.compile OPTIONS <warnings>on : -w1 ;
flags intel-linux.compile OPTIONS <warnings>all : -w2 ;
flags intel-linux.compile OPTIONS <warnings>extra : -w3 ;
flags intel-linux.compile OPTIONS <warnings>pedantic : -w3 -Wcheck ;
flags intel-linux.compile OPTIONS <warnings-as-errors>on : -Werror-all ;
}
else
{
flags intel-linux.compile OPTIONS <warnings>off : -w ;
flags intel-linux.compile OPTIONS <warnings>on : -Wall ;
flags intel-linux.compile OPTIONS <warnings>all : -Wall ;
flags intel-linux.compile OPTIONS <warnings>extra : -Wall ;
flags intel-linux.compile OPTIONS <warnings>pedantic : -Wall ;
flags intel-linux.compile OPTIONS <warnings-as-errors>on : -Werror-all ;
}
if $(.debug-configuration)
{
ECHO notice\: using intel libraries "::" $(condition) "::" $(command_lib_path) ;
}
flags intel-linux.compile RUN_PATH $(condition) : $(command_lib_path) ;
flags intel-linux.link RUN_PATH $(condition) : $(command_lib_path) ;
}

flags intel-linux.compile OPTIONS <warnings>off : -w0 ;
flags intel-linux.compile OPTIONS <warnings>on : -w1 ;
flags intel-linux.compile OPTIONS <warnings>all : -w2 ;
flags intel-linux.compile OPTIONS <warnings>extra : -w3 ;
flags intel-linux.compile OPTIONS <warnings>pedantic : -w3 -Wcheck ;
flags intel-linux.compile OPTIONS <warnings-as-errors>on : -Werror-all ;
_ = " " ;

rule compile.c++ ( targets * : sources * : properties * )
{
Expand All @@ -170,7 +241,7 @@ rule compile.c++ ( targets * : sources * : properties * )

actions compile.c++ bind PCH_FILE
{
"$(CONFIG_COMMAND)" -c -xc++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -use-pch"$(PCH_FILE)" -c -o "$(<)" "$(>)"
LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -c -xc++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -use-pch"$(PCH_FILE)" -c -o "$(<)" "$(>)"
}

rule compile.c ( targets * : sources * : properties * )
Expand All @@ -180,7 +251,7 @@ rule compile.c ( targets * : sources * : properties * )

actions compile.c bind PCH_FILE
{
"$(CONFIG_COMMAND)" -c -xc $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -use-pch"$(PCH_FILE)" -c -o "$(<)" "$(>)"
LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -c -xc $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -use-pch"$(PCH_FILE)" -c -o "$(<)" "$(>)"
}

rule compile.c++.pch ( targets * : sources * : properties * )
Expand All @@ -193,12 +264,12 @@ rule compile.c++.pch ( targets * : sources * : properties * )
#
actions compile.c++.pch
{
rm -f "$(<)" && "$(CONFIG_COMMAND)" -x c++-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -pch-create "$(<)" "$(>)"
rm -f "$(<)" && LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -x c++-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -pch-create "$(<)" "$(>)"
}

actions compile.fortran
{
"ifort" -c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
LD_LIBRARY_PATH="$(RUN_PATH)" "ifort" -c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
}

rule compile.c.pch ( targets * : sources * : properties * )
Expand All @@ -207,29 +278,26 @@ rule compile.c.pch ( targets * : sources * : properties * )

actions compile.c.pch
{
rm -f "$(<)" && "$(CONFIG_COMMAND)" -x c-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -pch-create "$(<)" "$(>)"
rm -f "$(<)" && LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -x c-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -pch-create "$(<)" "$(>)"
}

rule link ( targets * : sources * : properties * )
{
SPACE on $(targets) = " " ;
_ on $(targets) = " " ;
}

actions link bind LIBRARIES
{
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(OPTIONS) $(USER_OPTIONS)
LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(_)-Wl,"$(RPATH)" -Wl,-rpath-link$(_)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(OPTIONS) $(USER_OPTIONS)
}

rule link.dll ( targets * : sources * : properties * )
{
SPACE on $(targets) = " " ;
_ on $(targets) = " " ;
}

# Differ from 'link' above only by -shared.
actions link.dll bind LIBRARIES
{
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-soname$(SPACE)-Wl,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(OPTIONS) $(USER_OPTIONS)
LD_LIBRARY_PATH="$(RUN_PATH)" "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(_)-Wl,"$(RPATH)" -o "$(<)" -Wl,-soname$(_)-Wl,$(<[1]:D=) -shared "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(OPTIONS) $(USER_OPTIONS)
}



0 comments on commit 5ede4e8

Please sign in to comment.