Skip to content
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

希望添加windows下Intel编译器支持(icx) #5126

Closed
Altina-oz opened this issue May 22, 2024 · 6 comments
Closed

希望添加windows下Intel编译器支持(icx) #5126

Altina-oz opened this issue May 22, 2024 · 6 comments

Comments

@Altina-oz
Copy link
Contributor

你在什么场景下需要该功能?

windows下使用oneapi icx

测试代码(抄的cppreference)
#include
#include
#include
#include
#include
#include

#ifdef PARALLEL
#include
namespace execution = std::execution;
#else
enum class execution { seq, unseq, par_unseq, par };
#endif

void measure([[maybe_unused]] auto policy, std::vectorstd::uint64_t v)
{
const auto start = std::chrono::steady_clock::now();
#ifdef PARALLEL
std::sort(policy, v.begin(), v.end());
#else
std::sort(v.begin(), v.end());
#endif
const auto finish = std::chrono::steady_clock::now();
std::cout << std::chrono::duration_caststd::chrono::milliseconds(finish - start)
<< '\n';
};

int main()
{
std::vectorstd::uint64_t v(1'000'000);
std::mt19937 gen {std::random_device{}()};
std::ranges::generate(v, gen);

measure(execution::seq, v);
measure(execution::unseq, v);
measure(execution::par_unseq, v);
measure(execution::par, v);

}

描述可能的解决方案

toolchain("myicx")
set_homepage("https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html")
set_description("Intel LLVM C/C++ Compiler")
set_kind("standalone")
local icxvars = {"path",
"lib",
"libpath",
"include",
"DevEnvdir",
"VSInstallDir",
"VCInstallDir",
"WindowsSdkDir",
"WindowsLibPath",
"WindowsSDKVersion",
"WindowsSdkBinPath",
"UniversalCRTSdkDir",
"UCRTVersion"}
on_check(function (toolchain)
import("lib.detect.find_file")
import("lib.detect.find_tool")

    local paths = {"$(env ONEAPI_ROOT)"}
    local icxvars_bat = find_file("setvars.bat",paths)

        -- load icxvars_bat
        -- make the genicxvars.bat
    opt = opt or {}
    local genicxvars_bat = os.tmpfile() .. "_genicxvars.bat"
    local genicxvars_dat = os.tmpfile() .. "_genicxvars.txt"
    local file = io.open(genicxvars_bat, "w")
    file:print("@echo off")
    file:print("call \"%s\" -arch %s > nul", icxvars_bat, "intel64")
    for idx, var in ipairs(icxvars) do
        file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", genicxvars_dat)
    end
    file:close()

    -- run genicxvars.bat
    os.run(genicxvars_bat)

    -- load all envirnoment variables
    local variables = {}
    for _, line in ipairs((io.readfile(genicxvars_dat) or ""):split("\n")) do
        local p = line:find('=', 1, true)
        if p then
            local name = line:sub(1, p - 1):trim()
            local value = line:sub(p + 1):trim()
            variables[name] = value
        end
    end
    if not variables.path then
        return
    end

    -- remove some empty entries
    for _, name in ipairs(icxvars) do
        if variables[name] and #variables[name]:trim() == 0 then
            variables[name] = nil
        end
    end

    

    -- convert path/lib/include to PATH/LIB/INCLUDE
    variables.PATH    = variables.path
    variables.LIB     = variables.lib
    variables.LIBPATH = variables.libpath
    variables.INCLUDE = variables.include
    variables.path    = nil
    variables.lib     = nil
    variables.include = nil
    variables.libpath = nil
   
    --local icxvars_x64 = _load_icxvars(icxvars_bat, "intel64", opt)
    
    --icxenv={icxvars_bat=icxvars_bat,icxvars = { x64 = variables}}

    --bindir="$(env ONEAPI_ROOT)" .. "/compiler/latest/bin"
    -- find intel c/c++ compiler environment
    local icxenv ={icxvars_bat=icxvars_bat,icxvars = { x64 = variables}}
    if icxenv and icxenv.icxvars then
        local icxvarsall = icxenv.icxvars
        local icxenv = icxvarsall[toolchain:arch()]
        if icxenv and icxenv.PATH and icxenv.INCLUDE and icxenv.LIB then
            local tool = find_tool("icx.exe", {force = true, envs = icxenv, version = true})
            if tool then
                cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
                toolchain:config_set("varsall", icxvarsall)
                toolchain:configs_save()
                
                return true
            end
        end
    end
end)
on_load(function(toolchain)
    import("core.base.option")
    import("core.project.config")
    toolchain:set("toolset", "cc", "icx-cl.exe")
    toolchain:set("toolset", "cxx", "icx-cl.exe")
    toolchain:set("toolset", "mrc", "rc.exe")
    if toolchain:is_arch("x64") then
        toolchain:set("toolset", "as",  "ml64.exe")
    else
        toolchain:set("toolset", "as",  "ml.exe")
    end
    toolchain:set("toolset", "ld",  "link.exe")
    toolchain:set("toolset", "sh",  "link.exe")
    toolchain:set("toolset", "ar",  "link.exe")
    local icxvarsall = toolchain:config("varsall")
    local arch = toolchain:arch()
    local icxenv = icxvarsall[arch] or {}
    toolchain:add("runenvs", "PATH", path.splitenv(icxenv["PATH"]))
    toolchain:add("runenvs", "LIB", path.splitenv(icxenv["LIB"]))
    toolchain:add("runenvs", "INCLUDE", path.splitenv(icxenv["INCLUDE"]))
    toolchain:add("runenvs", "LIBPATH", path.splitenv(icxenv["LIBPATH"]))
end
)

描述你认为的候选方案

No response

其他信息

似乎必须要在环境变量里增加oneapi_root不然不知道怎么找setvars.bat

cc和cxx的driver似乎"icx-cl.exe"比较和现有的兼容,直接"icx.exe"会使得有的flag进不去,虽然Intel推荐使用icx.exe。
(报错例:
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.
icx: warning: unknown argument ignored in clang-cl: '-fvisibility=hidden' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-fvisibility-inlines-hidden' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl '-std=c++20'; did you mean '-Qstd=c++20'? [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-fexceptions' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-fcxx-exceptions' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl '-MMD'; did you mean '-QMMD'? [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-fdiagnostics-color=always' [-Wunknown-argument]
)

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Hope to add Intel compiler support under windows (icx)

@Altina-oz
Copy link
Contributor Author

icxtest.zip

例子

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


There is no environment for now, you can refer to the implementation of ifort

Improve the icx implementation and submit a PR.

@waruqi
Copy link
Member

waruqi commented May 23, 2024

暂时没太多时间调这个,可以参考这个 patch 自己调下。#5132

@waruqi waruqi added this to the v2.9.2 milestone May 23, 2024
@waruqi
Copy link
Member

waruqi commented May 23, 2024

先这样吧,凑活着能用了。。#5132

剩下的有啥改进,直接来 pr

@waruqi waruqi closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants