Skip to content

Commit 9d22eff

Browse files
danieldkkaixuanliu
andauthored
fix bug when kernels upload (#242)
Signed-off-by: Liu, Kaixuan <kaixuan.liu@intel.com> Co-authored-by: Liu, Kaixuan <kaixuan.liu@intel.com>
1 parent fd85f38 commit 9d22eff

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

build2cmake/src/templates/windows.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ endfunction()
140140
function(add_local_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME)
141141
# Define your local, folder based, installation directory
142142
set(LOCAL_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
143+
# Variant directory is where metadata.json should go (for kernels upload discovery)
144+
set(VARIANT_DIR "${CMAKE_SOURCE_DIR}/build/${BUILD_VARIANT_NAME}")
143145

144146
# Glob Python files at configure time
145147
file(GLOB PYTHON_FILES "${CMAKE_SOURCE_DIR}/torch-ext/${PACKAGE_NAME}/*.py")
@@ -164,12 +166,14 @@ function(add_local_install_target TARGET_NAME PACKAGE_NAME BUILD_VARIANT_NAME)
164166
# Copy metadata.json if it exists
165167
COMMAND ${CMAKE_COMMAND} -E copy_if_different
166168
${CMAKE_SOURCE_DIR}/metadata.json
167-
${LOCAL_INSTALL_DIR}/
169+
${VARIANT_DIR}/
168170

169171
COMMENT "Copying shared library and Python files to ${LOCAL_INSTALL_DIR}"
170172
COMMAND_EXPAND_LISTS
171173
)
172174

175+
# Create both directories: variant dir for metadata.json, package dir for binaries
176+
file(MAKE_DIRECTORY ${VARIANT_DIR})
173177
file(MAKE_DIRECTORY ${LOCAL_INSTALL_DIR})
174178
message(STATUS "Added install rules for ${TARGET_NAME} -> build/${BUILD_VARIANT_NAME}/${PACKAGE_NAME}")
175179
endfunction()

build2cmake/src/templates/xpu/preamble.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,11 @@ add_compile_definitions(USE_XPU)
8080
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';")
8181
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;")
8282
message(STATUS "Configuring for Intel XPU backend using SYCL")
83+
84+
{% if platform == 'windows' %}
85+
# Include Windows-specific functions for local_install and kernels_install targets
86+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/windows.cmake)
87+
88+
# Generate build variant name for XPU (e.g., torch291-xpu-x86_64-windows)
89+
generate_build_name(BUILD_VARIANT_NAME "${TORCH_VERSION}" "xpu" "${DPCPP_VERSION}")
90+
{% endif %}

build2cmake/src/templates/xpu/torch-extension.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ define_gpu_extension_target(
1010
# Add XPU/SYCL specific linker flags
1111
target_link_options({{ ops_name }} PRIVATE ${sycl_link_flags})
1212
target_link_libraries({{ ops_name }} PRIVATE dnnl)
13+
14+
{% if platform == 'windows' %}
15+
# These methods below should be included from preamble.cmake on windows platform.
16+
17+
# Add kernels_install target for huggingface/kernels library layout
18+
add_kernels_install_target({{ ops_name }} "{{ name }}" "${BUILD_VARIANT_NAME}")
19+
20+
# Add local_install target for local development with get_local_kernel()
21+
add_local_install_target({{ ops_name }} "{{ name }}" "${BUILD_VARIANT_NAME}")
22+
23+
{% endif %}

build2cmake/src/torch/xpu.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::FileSet;
1515

1616
static CMAKE_UTILS: &str = include_str!("../templates/utils.cmake");
1717
static REGISTRATION_H: &str = include_str!("../templates/registration.h");
18+
static WINDOWS_UTILS: &str = include_str!("../templates/windows.cmake");
1819

1920
pub fn write_torch_ext_xpu(
2021
env: &Environment,
@@ -137,6 +138,14 @@ fn write_cmake(
137138
.entry(utils_path.clone())
138139
.extend_from_slice(CMAKE_UTILS.as_bytes());
139140

141+
// Add windows.cmake for Windows-specific install targets
142+
let mut windows_utils_path = PathBuf::new();
143+
windows_utils_path.push("cmake");
144+
windows_utils_path.push("windows.cmake");
145+
file_set
146+
.entry(windows_utils_path.clone())
147+
.extend_from_slice(WINDOWS_UTILS.as_bytes());
148+
140149
let cmake_writer = file_set.entry("CMakeLists.txt");
141150

142151
render_preamble(
@@ -296,6 +305,7 @@ pub fn render_preamble(
296305
name => name,
297306
torch_minver => torch_minver.map(|v| v.to_string()),
298307
torch_maxver => torch_maxver.map(|v| v.to_string()),
308+
platform => std::env::consts::OS,
299309
},
300310
&mut *write,
301311
)

0 commit comments

Comments
 (0)