Skip to content

Commit 4e8b647

Browse files
authored
[CI] Use oneAPI for Windows postcommit builds (#16355)
Getting this working was an unbelievable amount of work. I hit so many weird issues caused by dumb Windows things (case insensitivity, cmd vs bash, bugs in cmake/ninja/sccache themselves) but finally I got something that consistently passes. You can see the funniest dumb Windows issue in the comment in the CMake file change. The basic idea is to extend the Windows build workflow to allow using `icx`, add an action to setup the oneAPI environment, call it from the build action and the test action (since we need some of the shared libs on path even for testing), and fix some oneAPI-only build issues. We need to do some Powershell magic after calling the oneAPI setup bat script because the environment variables get lost since it's run in a subprocess. We also switch to `ccache` instead of `sccache`, because `sccache` doesn't support `icx` (actually neither does `ccache`, but I added it upstream [here](ccache/ccache#1533) and we are using a local build of `ccache`, it was easier to add support to `ccache`). Manually tested it to confirmed cache reads and write are working as expected. At some point we should probably investigate why some tests fail or some compiler flags are required with `icx` only and not `cl`, but let's do that as separate work because I am done with Windows for now. I already set up all Windows runners used here to work with this change. Next I'll add oneAPI builds on Linux, which I really hope is easier. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent f0b7493 commit 4e8b647

File tree

7 files changed

+112
-38
lines changed

7 files changed

+112
-38
lines changed

.github/workflows/sycl-post-commit.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ jobs:
103103
&& success()
104104
&& github.repository == 'intel/llvm'
105105
uses: ./.github/workflows/sycl-windows-build.yml
106-
106+
with:
107+
compiler: icx
108+
build_configure_extra_args: --cmake-opt=-DCMAKE_C_FLAGS="/clang:-Wno-nonportable-include-path /clang:-Wno-cast-function-type-mismatch" --cmake-opt=-DCMAKE_CXX_FLAGS="/clang:-Wno-nonportable-include-path /clang:-Wno-cast-function-type-mismatch" --cmake-opt="-DCMAKE_EXE_LINKER_FLAGS=/manifest:no" --cmake-opt="-DCMAKE_MODULE_LINKER_FLAGS=/manifest:no" --cmake-opt="-DCMAKE_SHARED_LINKER_FLAGS=/manifest:no"
109+
build_cache_suffix: icx
110+
107111
e2e-win:
108112
needs: build-win
109113
# Continue if build was successful.
@@ -117,6 +121,7 @@ jobs:
117121
runner: '["Windows","gen12"]'
118122
sycl_toolchain_archive: ${{ needs.build-win.outputs.artifact_archive_name }}
119123
extra_lit_opts: --param gpu-intel-gen12=True
124+
compiler: icx
120125

121126
macos_default:
122127
name: macOS

.github/workflows/sycl-windows-build.yml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
build_ref:
1111
type: string
1212
required: false
13+
build_configure_extra_args:
14+
type: string
15+
required: false
1316
changes:
1417
type: string
1518
description: 'Filter matches for the changed files in the PR'
@@ -22,6 +25,10 @@ on:
2225
description: 'Artifacts retention period'
2326
type: string
2427
default: 3
28+
compiler:
29+
type: string
30+
required: false
31+
default: "cl"
2532

2633
outputs:
2734
build_conclusion:
@@ -41,6 +48,9 @@ on:
4148
type: choice
4249
options:
4350
- "default"
51+
build_configure_extra_args:
52+
type: string
53+
required: false
4454
artifact_archive_name:
4555
type: choice
4656
options:
@@ -50,6 +60,12 @@ on:
5060
type: choice
5161
options:
5262
- 3
63+
compiler:
64+
type: choice
65+
options:
66+
- cl
67+
- icx
68+
5369
permissions: read-all
5470

5571
jobs:
@@ -61,37 +77,43 @@ jobs:
6177
outputs:
6278
build_conclusion: ${{ steps.build.conclusion }}
6379
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
path: src
83+
ref: ${{ inputs.build_ref || github.sha }}
84+
fetch-depth: 1
6485
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756
6586
with:
6687
arch: amd64
88+
- name: Setup oneAPI env
89+
uses: ./src/devops/actions/setup_windows_oneapi_env
90+
if: ${{ always() && !cancelled() && inputs.compiler == 'icx' }}
6791
- name: Set env
6892
run: |
6993
git config --system core.longpaths true
7094
git config --global core.autocrlf false
7195
echo "C:\Program Files\Git\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
72-
echo "SCCACHE_DIR=D:\github\_work\cache\${{ inputs.build_cache_suffix }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
73-
- uses: actions/checkout@v4
74-
with:
75-
path: src
76-
ref: ${{ inputs.build_ref || github.sha }}
77-
fetch-depth: 1
96+
echo "CCACHE_DIR=D:\github\_work\cache\${{ inputs.build_cache_suffix }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
97+
echo "CCACHE_MAXSIZE=10G" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7898
- name: Register cleanup after job is finished
7999
uses: ./src/devops/actions/cleanup
80100
- name: Configure
81101
shell: cmd
102+
env:
103+
ARGS: ${{ inputs.build_configure_extra_args }}
82104
# TODO switch to clang-cl and lld when this is fixed https://github.com/oneapi-src/level-zero/issues/83
83105
run: |
84106
mkdir build
85107
mkdir install
86108
IF NOT EXIST D:\github\_work\cache MKDIR D:\github\_work\cache
87109
IF NOT EXIST D:\github\_work\cache\${{inputs.build_cache_suffix}} MKDIR D:\github\_work\cache\${{inputs.build_cache_suffix}}
88110
python.exe src/buildbot/configure.py -o build ^
89-
--ci-defaults ^
90-
--cmake-opt="-DCMAKE_C_COMPILER=cl" ^
91-
--cmake-opt="-DCMAKE_CXX_COMPILER=cl" ^
111+
--ci-defaults %ARGS% ^
112+
--cmake-opt="-DCMAKE_C_COMPILER=${{inputs.compiler}}" ^
113+
--cmake-opt="-DCMAKE_CXX_COMPILER=${{inputs.compiler}}" ^
92114
--cmake-opt="-DCMAKE_INSTALL_PREFIX=%GITHUB_WORKSPACE%\install" ^
93-
--cmake-opt="-DCMAKE_CXX_COMPILER_LAUNCHER=sccache" ^
94-
--cmake-opt="-DCMAKE_C_COMPILER_LAUNCHER=sccache" ^
115+
--cmake-opt="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" ^
116+
--cmake-opt="-DCMAKE_C_COMPILER_LAUNCHER=ccache" ^
95117
--cmake-opt="-DLLVM_INSTALL_UTILS=ON" ^
96118
--cmake-opt="-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV"
97119
- name: Build
@@ -101,16 +123,24 @@ jobs:
101123
cmake --build build --target sycl-toolchain
102124
- name: check-llvm
103125
if: always() && !cancelled() && contains(inputs.changes, 'llvm')
126+
shell: bash
104127
run: |
128+
if [[ ${{inputs.compiler}} == 'icx' ]]; then
129+
export LIT_FILTER="SYCL"
130+
fi
105131
cmake --build build --target check-llvm
106132
- name: check-clang
107133
if: always() && !cancelled() && contains(inputs.changes, 'clang')
108134
run: |
109135
cmake --build build --target check-clang
110136
- name: check-sycl
111137
if: always() && !cancelled() && contains(inputs.changes, 'sycl')
138+
shell: bash
112139
run: |
113-
cmake --build build --target check-sycl
140+
if [[ ${{inputs.compiler}} == 'icx' ]]; then
141+
export LIT_FILTER_OUT="host_tanpi_double_accuracy"
142+
fi
143+
cmake --build build --target check-sycl
114144
- name: check-sycl-unittests
115145
if: always() && !cancelled() && contains(inputs.changes, 'sycl')
116146
run: |

.github/workflows/sycl-windows-run-tests.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ on:
3333
default: '{}'
3434
required: False
3535

36+
compiler:
37+
type: string
38+
required: false
39+
default: "cl"
40+
3641
permissions: read-all
3742

3843
jobs:
@@ -42,20 +47,23 @@ jobs:
4247
environment: WindowsCILock
4348
env: ${{ fromJSON(inputs.env) }}
4449
steps:
50+
# TODO: use cached_checkout
51+
- uses: actions/checkout@v4
52+
with:
53+
persist-credentials: false
54+
ref: ${{ inputs.ref || github.sha }}
55+
path: llvm
4556
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756
4657
with:
4758
arch: amd64
59+
- name: Setup oneAPI env
60+
uses: ./llvm/devops/actions/setup_windows_oneapi_env
61+
if: ${{ always() && !cancelled() && inputs.compiler == 'icx' }}
4862
- name: Set env
4963
run: |
5064
git config --system core.longpaths true
5165
git config --global core.autocrlf false
5266
echo "C:\Program Files\Git\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
53-
# TODO: use cached_checkout
54-
- uses: actions/checkout@v4
55-
with:
56-
persist-credentials: false
57-
ref: ${{ inputs.ref || github.sha }}
58-
path: llvm
5967
- name: Register cleanup after job is finished
6068
uses: ./llvm/devops/actions/cleanup
6169
- name: Download compiler toolchain
@@ -84,6 +92,9 @@ jobs:
8492
shell: bash
8593
run: |
8694
# Run E2E tests.
95+
if [[ ${{inputs.compiler}} == 'icx' ]]; then
96+
export LIT_FILTER_OUT="compile_on_win_with_mdd"
97+
fi
8798
export LIT_OPTS="-v --no-progress-bar --show-unsupported --show-pass --show-xfail --max-time 3600 --time-tests ${{ inputs.extra_lit_opts }}"
8899
cmake --build build-e2e --target check-sycl-e2e
89100
- name: Detect hung tests
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Windows setup oneAPI env
2+
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Setup oneAPI env
7+
shell: powershell
8+
run: |
9+
$batchFilePath = "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
10+
11+
$githubEnvFilePath = $env:GITHUB_ENV
12+
13+
$envBefore = Get-ChildItem Env: | ForEach-Object { "$($_.Name)=$($_.Value)" }
14+
15+
$envVars = & cmd.exe /c "call `"$batchFilePath`" && set" | Out-String
16+
17+
$envAfter = $envVars -split "`r`n" | Where-Object { $_ -match "^(.*?)=(.*)$" }
18+
19+
foreach ($envVar in $envAfter) {
20+
if ($envVar -match "^(.*?)=(.*)$") {
21+
$name = $matches[1]
22+
$value = $matches[2]
23+
$envBeforeVar = $envBefore | Where-Object { $_ -like "$name=*" }
24+
if (-not $envBeforeVar -or $envBeforeVar -ne "$name=$value") {
25+
Add-Content -Path $githubEnvFilePath -Value "$name=$value"
26+
}
27+
}
28+
}

sycl/source/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
222222
target_compile_options(${LIB_OBJ_NAME} PRIVATE
223223
-Winstantiation-after-specialization)
224224
endif()
225+
226+
# When building using icx on Windows, the VERSION file
227+
# produced by cmake is used in source code
228+
# when including '<version>' because Windows is
229+
# case-insensitive and icx adds the build directory
230+
# to the system header search path.
231+
if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
232+
set(VERSION_FILE "${CMAKE_BINARY_DIR}/VERSION")
233+
if(EXISTS ${VERSION_FILE})
234+
file(REMOVE ${VERSION_FILE})
235+
endif()
236+
endif()
225237
endfunction(add_sycl_rt_library)
226238

227239
set(SYCL_COMMON_SOURCES

sycl/source/detail/windows_ur.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,6 @@ void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName) {
5656
GetProcAddress((HMODULE)Library, FunctionName.c_str()));
5757
}
5858

59-
static std::filesystem::path getCurrentDSODirPath() {
60-
wchar_t Path[MAX_PATH];
61-
auto Handle =
62-
getOSModuleHandle(reinterpret_cast<void *>(&getCurrentDSODirPath));
63-
DWORD Ret = GetModuleFileName(
64-
reinterpret_cast<HMODULE>(ExeModuleHandle == Handle ? 0 : Handle), Path,
65-
MAX_PATH);
66-
assert(Ret < MAX_PATH && "Path is longer than MAX_PATH?");
67-
assert(Ret > 0 && "GetModuleFileName failed");
68-
(void)Ret;
69-
70-
BOOL RetCode = PathRemoveFileSpec(Path);
71-
assert(RetCode && "PathRemoveFileSpec failed");
72-
(void)RetCode;
73-
74-
return std::filesystem::path(Path);
75-
}
76-
7759
void *getURLoaderLibrary() { return getPreloadedURLib(); }
7860

7961
} // namespace ur

sycl/unittests/assert/assert.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ static AssertHappened ExpectedToOutput = {
145145
};
146146

147147
static constexpr int KernelLaunchCounterBase = 0;
148-
static int KernelLaunchCounter = KernelLaunchCounterBase;
149148
static constexpr int MemoryMapCounterBase = 1000;
150149
static int MemoryMapCounter = MemoryMapCounterBase;
150+
#ifndef _WIN32
151+
static int KernelLaunchCounter = KernelLaunchCounterBase;
151152
static constexpr int PauseWaitOnIdx = KernelLaunchCounterBase + 1;
153+
#endif
152154

153155
// Mock redifinitions
154156
static ur_result_t redefinedKernelGetGroupInfoAfter(void *pParams) {
@@ -167,6 +169,7 @@ static ur_result_t redefinedKernelGetGroupInfoAfter(void *pParams) {
167169
return UR_RESULT_SUCCESS;
168170
}
169171

172+
#ifndef _WIN32
170173
static ur_result_t redefinedEnqueueKernelLaunchAfter(void *pParams) {
171174
auto params = *static_cast<ur_enqueue_kernel_launch_params_t *>(pParams);
172175
static ur_event_handle_t UserKernelEvent = **params.pphEvent;
@@ -197,6 +200,7 @@ static ur_result_t redefinedEventWaitPositive(void *pParams) {
197200
printf("Waiting for events %i, %i\n", EventIdx1, EventIdx2);
198201
return UR_RESULT_SUCCESS;
199202
}
203+
#endif
200204

201205
static ur_result_t redefinedEventWaitNegative(void *pParams) {
202206
auto params = *static_cast<ur_enqueue_events_wait_params_t *>(pParams);
@@ -223,6 +227,7 @@ static ur_result_t redefinedEnqueueMemBufferMapAfter(void *pParams) {
223227
return UR_RESULT_SUCCESS;
224228
}
225229

230+
#ifndef _WIN32
226231
static void setupMock(sycl::unittest::UrMock<> &Mock) {
227232
using namespace sycl::detail;
228233
mock::getCallbacks().set_after_callback("urKernelGetGroupInfo",
@@ -234,6 +239,7 @@ static void setupMock(sycl::unittest::UrMock<> &Mock) {
234239
mock::getCallbacks().set_before_callback("urEventWait",
235240
&redefinedEventWaitPositive);
236241
}
242+
#endif
237243

238244
namespace TestInteropKernel {
239245
const sycl::context *Context = nullptr;

0 commit comments

Comments
 (0)