From 1ef8b2c129e32ee35646ef9fc4962a68457d802b Mon Sep 17 00:00:00 2001 From: "Liu, Kaixuan" Date: Tue, 27 Jan 2026 14:40:20 +0800 Subject: [PATCH 1/2] add support for windows xpu kernel build and install Signed-off-by: Liu, Kaixuan --- build2cmake/src/templates/xpu/preamble.cmake | 8 ++++++++ build2cmake/src/templates/xpu/torch-extension.cmake | 11 +++++++++++ build2cmake/src/torch/xpu.rs | 10 ++++++++++ scripts/windows/builder.ps1 | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/build2cmake/src/templates/xpu/preamble.cmake b/build2cmake/src/templates/xpu/preamble.cmake index 54dca570..8cf72ff5 100644 --- a/build2cmake/src/templates/xpu/preamble.cmake +++ b/build2cmake/src/templates/xpu/preamble.cmake @@ -80,3 +80,11 @@ add_compile_definitions(USE_XPU) set(sycl_link_flags "-fsycl;--offload-compress;-fsycl-targets=spir64_gen,spir64;-Xs;-device pvc,xe-lpg,ats-m150 -options ' -cl-intel-enable-auto-large-GRF-mode -cl-poison-unsupported-fp64-kernels -cl-intel-greater-than-4GB-buffer-required';") set(sycl_flags "-fsycl;-fhonor-nans;-fhonor-infinities;-fno-associative-math;-fno-approx-func;-fno-sycl-instrument-device-code;--offload-compress;-fsycl-targets=spir64_gen,spir64;") message(STATUS "Configuring for Intel XPU backend using SYCL") + +{% if platform == 'windows' %} +# Include Windows-specific functions for local_install and kernels_install targets +include(${CMAKE_CURRENT_LIST_DIR}/cmake/windows.cmake) + +# Generate build variant name for XPU (e.g., torch291-xpu-x86_64-windows) +generate_build_name(BUILD_VARIANT_NAME "${TORCH_VERSION}" "xpu" "${DPCPP_VERSION}") +{% endif %} diff --git a/build2cmake/src/templates/xpu/torch-extension.cmake b/build2cmake/src/templates/xpu/torch-extension.cmake index a359f8c7..f320170a 100644 --- a/build2cmake/src/templates/xpu/torch-extension.cmake +++ b/build2cmake/src/templates/xpu/torch-extension.cmake @@ -10,3 +10,14 @@ define_gpu_extension_target( # Add XPU/SYCL specific linker flags target_link_options({{ ops_name }} PRIVATE ${sycl_link_flags}) target_link_libraries({{ ops_name }} PRIVATE dnnl) + +{% if platform == 'windows' %} +# These methods below should be included from preamble.cmake on windows platform. + +# Add kernels_install target for huggingface/kernels library layout +add_kernels_install_target({{ ops_name }} "{{ name }}" "${BUILD_VARIANT_NAME}") + +# Add local_install target for local development with get_local_kernel() +add_local_install_target({{ ops_name }} "{{ name }}" "${BUILD_VARIANT_NAME}") + +{% endif %} diff --git a/build2cmake/src/torch/xpu.rs b/build2cmake/src/torch/xpu.rs index 126feb08..0b5f38f2 100644 --- a/build2cmake/src/torch/xpu.rs +++ b/build2cmake/src/torch/xpu.rs @@ -15,6 +15,7 @@ use crate::FileSet; static CMAKE_UTILS: &str = include_str!("../templates/utils.cmake"); static REGISTRATION_H: &str = include_str!("../templates/registration.h"); +static WINDOWS_UTILS: &str = include_str!("../templates/windows.cmake"); pub fn write_torch_ext_xpu( env: &Environment, @@ -137,6 +138,14 @@ fn write_cmake( .entry(utils_path.clone()) .extend_from_slice(CMAKE_UTILS.as_bytes()); + // Add windows.cmake for Windows-specific install targets + let mut windows_utils_path = PathBuf::new(); + windows_utils_path.push("cmake"); + windows_utils_path.push("windows.cmake"); + file_set + .entry(windows_utils_path.clone()) + .extend_from_slice(WINDOWS_UTILS.as_bytes()); + let cmake_writer = file_set.entry("CMakeLists.txt"); render_preamble( @@ -296,6 +305,7 @@ pub fn render_preamble( name => name, torch_minver => torch_minver.map(|v| v.to_string()), torch_maxver => torch_maxver.map(|v| v.to_string()), + platform => std::env::consts::OS, }, &mut *write, ) diff --git a/scripts/windows/builder.ps1 b/scripts/windows/builder.ps1 index 44a9253b..588d0867 100644 --- a/scripts/windows/builder.ps1 +++ b/scripts/windows/builder.ps1 @@ -446,11 +446,11 @@ function Invoke-CMakeBuild { # Run install target if requested if ($RunLocalInstall) { - Invoke-CMakeTarget -Target 'INSTALL' -BuildConfig $BuildConfig -DisplayName 'install target (local development layout)' + Invoke-CMakeTarget -Target 'install' -BuildConfig $BuildConfig -DisplayName 'install target (local development layout)' } if ($RunKernelsInstall) { - Invoke-CMakeTarget -Target 'INSTALL' -BuildConfig $BuildConfig -DisplayName 'install target' + Invoke-CMakeTarget -Target 'install' -BuildConfig $BuildConfig -DisplayName 'install target' } } finally { From e34e61919432a37b414af4adfb1363883018fd25 Mon Sep 17 00:00:00 2001 From: "Liu, Kaixuan" Date: Tue, 27 Jan 2026 17:37:35 +0800 Subject: [PATCH 2/2] adjust the dir of metadata.json file Signed-off-by: Liu, Kaixuan --- build2cmake/src/templates/windows.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build2cmake/src/templates/windows.cmake b/build2cmake/src/templates/windows.cmake index a052af3d..c3251450 100644 --- a/build2cmake/src/templates/windows.cmake +++ b/build2cmake/src/templates/windows.cmake @@ -140,6 +140,8 @@ endfunction() function(add_local_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME) # Define your local, folder based, installation directory set(LOCAL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}") + # Variant directory is where metadata.json should go (for kernels upload discovery) + set(VARIANT_DIR "${CMAKE_SOURCE_DIR}/build/${BUILD_VARIANT_NAME}") # Glob Python files at configure time file(GLOB PYTHON_FILES "${CMAKE_SOURCE_DIR}/torch-ext/${PACKAGE_NAME}/*.py") @@ -161,15 +163,18 @@ function(add_local_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME) ${PYTHON_FILES} ${LOCAL_INSTALL_DIR}/ - # Copy metadata.json if it exists + # Copy metadata.json to variant directory (required by kernels upload) + # kernels CLI looks for metadata.json at build//metadata.json COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/metadata.json - ${LOCAL_INSTALL_DIR}/ + ${VARIANT_DIR}/ COMMENT "Copying shared library and Python files to ${LOCAL_INSTALL_DIR}" COMMAND_EXPAND_LISTS ) + # Create both directories: variant dir for metadata.json, package dir for binaries + file(MAKE_DIRECTORY ${VARIANT_DIR}) file(MAKE_DIRECTORY ${LOCAL_INSTALL_DIR}) message(STATUS "Added install rules for ${TARGET_NAME} -> build/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}") endfunction()