Skip to content

Commit cc4997d

Browse files
authored
add kernel build for Intel XPU platform on windows (#306)
Signed-off-by: Liu, Kaixuan <kaixuan.liu@intel.com>
1 parent 03098ce commit cc4997d

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

build2cmake/src/templates/xpu/preamble.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ if(ICX_COMPILER AND ICPX_COMPILER)
1212
string(REGEX MATCH "[0-9]+\\.[0-9]+" DPCPP_VERSION "${ICPX_VERSION_OUTPUT}")
1313
set(DPCPP_VERSION "${DPCPP_VERSION}" CACHE STRING "DPCPP major.minor version")
1414
set(CMAKE_C_COMPILER ${ICX_COMPILER})
15-
set(CMAKE_CXX_COMPILER ${ICPX_COMPILER})
16-
message(STATUS "Using Intel SYCL C++ compiler: ${ICPX_COMPILER} and C compiler: ${ICX_COMPILER} Version: ${DPCPP_VERSION}")
15+
16+
# On Windows, use icx (MSVC-compatible) for C++ to work with Ninja generator
17+
# On Linux, use icpx (GNU-compatible) for C++
18+
if(WIN32)
19+
set(CMAKE_CXX_COMPILER ${ICX_COMPILER})
20+
message(STATUS "Using Intel SYCL C++ compiler: ${ICX_COMPILER} and C compiler: ${ICX_COMPILER} Version: ${DPCPP_VERSION} (Windows MSVC-compatible mode)")
21+
else()
22+
set(CMAKE_CXX_COMPILER ${ICPX_COMPILER})
23+
message(STATUS "Using Intel SYCL C++ compiler: ${ICPX_COMPILER} and C compiler: ${ICX_COMPILER} Version: ${DPCPP_VERSION}")
24+
endif()
1725
else()
1826
message(FATAL_ERROR "Intel SYCL C++ compiler (icpx) and/or C compiler (icx) not found. Please install Intel oneAPI toolkit.")
1927
endif()

scripts/windows/builder.ps1

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,36 @@ function Get-CMakeConfigureArgs {
319319
#>
320320
param(
321321
[bool]$ShouldInstall,
322-
[string]$InstallPrefix
322+
[string]$InstallPrefix,
323+
[string]$Backend
323324
)
324325

325-
# Detect platform architecture
326-
$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture
327-
$vsArch = if ($arch -eq 'Arm64') { 'ARM64' } else { 'x64' }
326+
# For XPU backend, use Ninja generator with Intel compilers
327+
if ($Backend -and $Backend.ToLower() -eq 'xpu') {
328+
Write-Status "Using Ninja generator for XPU backend with Intel SYCL compilers" -Type Info
329+
330+
$kwargs = @("..", "-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release")
331+
332+
# Verify Intel compilers are available (CMakeLists.txt will set them correctly)
333+
$icx = Get-Command icx -ErrorAction SilentlyContinue
334+
335+
if ($icx) {
336+
Write-Status "Found Intel compiler: $($icx.Source)" -Type Info
337+
Write-Status "CMakeLists.txt will configure icx for Windows (MSVC-compatible mode)" -Type Info
338+
} else {
339+
Write-Status "Intel compilers not found in PATH. Make sure oneAPI environment is initialized." -Type Error
340+
Write-Status "Run: & `"C:\Program Files (x86)\Intel\oneAPI\setvars.bat`"" -Type Error
341+
throw "Intel compilers (icx) are required for XPU backend but were not found in PATH. Please initialize oneAPI environment."
342+
}
343+
} else {
344+
# Use Visual Studio generator for other backends
345+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture
346+
$vsArch = if ($arch -eq 'Arm64') { 'ARM64' } else { 'x64' }
328347

329-
Write-Status "Detected platform: $arch, using Visual Studio architecture: $vsArch" -Type Info
348+
Write-Status "Detected platform: $arch, using Visual Studio architecture: $vsArch" -Type Info
330349

331-
$kwargs = @("..", "-G", "Visual Studio 17 2022", "-A", $vsArch)
350+
$kwargs = @("..", "-G", "Visual Studio 17 2022", "-A", $vsArch)
351+
}
332352

333353
# Detect Python from current environment
334354
$pythonExe = (Get-Command python -ErrorAction SilentlyContinue).Source
@@ -382,13 +402,14 @@ function Invoke-CMakeBuild {
382402
[string]$BuildConfig,
383403
[bool]$RunLocalInstall = $false,
384404
[bool]$RunKernelsInstall = $false,
385-
[string]$InstallPrefix = $null
405+
[string]$InstallPrefix = $null,
406+
[string]$Backend = $null
386407
)
387408

388409
Write-Status "Building project with CMake..." -Type Info
389410
Write-Status "Configuration: $BuildConfig" -Type Info
390411

391-
# Ensure VS environment is initialized
412+
# Ensure VS environment is initialized (needed for Ninja and MSVC)
392413
Initialize-VSEnvironment
393414

394415
# Create build directory
@@ -402,7 +423,7 @@ function Invoke-CMakeBuild {
402423
Write-Status "Configuring CMake project..." -Type Info
403424
Push-Location $buildDir
404425
try {
405-
$configureArgs = Get-CMakeConfigureArgs -ShouldInstall ($RunKernelsInstall -or $RunLocalInstall) -InstallPrefix $InstallPrefix
426+
$configureArgs = Get-CMakeConfigureArgs -ShouldInstall ($RunKernelsInstall -or $RunLocalInstall) -InstallPrefix $InstallPrefix -Backend $Backend
406427

407428
cmake @configureArgs
408429

@@ -573,7 +594,8 @@ try {
573594
-BuildConfig $BuildConfig `
574595
-RunLocalInstall $LocalInstall.IsPresent `
575596
-RunKernelsInstall $KernelsInstall.IsPresent `
576-
-InstallPrefix $InstallPrefix
597+
-InstallPrefix $InstallPrefix `
598+
-Backend $Backend
577599
}
578600
}
579601

0 commit comments

Comments
 (0)