Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build2cmake/src/templates/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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/<variant>/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()
8 changes: 8 additions & 0 deletions build2cmake/src/templates/xpu/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
11 changes: 11 additions & 0 deletions build2cmake/src/templates/xpu/torch-extension.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
10 changes: 10 additions & 0 deletions build2cmake/src/torch/xpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions scripts/windows/builder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down