Skip to content

Commit

Permalink
[PT2.6][Windows] Fix Windows Codegen (#1057)
Browse files Browse the repository at this point in the history
Running codegen on windows is running into below error recently,

`FileNotFoundError: [Errno 2] No such file or directory:
'C:/Users/sdp/ratnam-work/pytorch/third_party/torch-xpu-ops/yaml/templates\\RegisterDispatchDefinitions.ini'
`

This is caused due to this symlink command in windows not running a
shell or cmd as an administrator
https://github.com/intel/torch-xpu-ops/blob/b1582e14f9e27bcbc0666ff636389d2be61783e4/cmake/Codegen.cmake#L61

Also, when symlink is not performed due to access issues, cmake throws
such error:
`You do not have sufficient privilege to perform this operation.`

**Resolution**
Change symlink to copy templates folder and delete it once codegen is
complete.

---------

Co-authored-by: Eikan Wang <[email protected]>
Co-authored-by: Yutao Xu <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 000d343 commit eaa429f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmake/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function(GEN_XPU file_yaml)

# Codegen prepare process
if(WIN32)
string(REPLACE "/" "\\" LinkPATH "${CODEGEN_TEMPLATE}templates")
string(REPLACE "/" "\\" TargetPATH "${CMAKE_SOURCE_DIR}/aten/src/ATen/templates")
execute_process(COMMAND cmd /c mklink /D ${LinkPATH} ${TargetPATH})
string(REPLACE "/" "\\" DestPATH "${CODEGEN_TEMPLATE}templates")
string(REPLACE "/" "\\" SrcPATH "${CMAKE_SOURCE_DIR}/aten/src/ATen/templates")
execute_process(COMMAND cmd /c xcopy ${SrcPATH} ${DestPATH} /E /H /C /I /Y > nul)
string(REPLACE "/" "\\" RegisterXPU_PATH_BACKSLASH "${RegisterXPU_PATH}")
string(REPLACE "/" "\\" XPUFallback_PATH_BACKSLASH "${XPUFallback_PATH}")
set(REGISTER_FALLBACK_CMD ${FILE_DISPLAY_CMD} ${XPUFallback_PATH_BACKSLASH} ">>" ${RegisterXPU_PATH_BACKSLASH})
Expand Down Expand Up @@ -96,10 +96,20 @@ function(GEN_XPU file_yaml)
${SIMPLE_TRACE}
WORKING_DIRECTORY ${TORCH_ROOT}
DEPENDS
${depended_files}
${depended_files}
${TORCH_XPU_OPS_ROOT}/yaml/native/${file_yaml}
${XPUFallback_PATH}
)

# Post codegen delete the copied templates folder only on Windows.
if(WIN32)
add_custom_target(DELETE_TEMPLATES ALL DEPENDS ${generated_files})
add_custom_command(
TARGET DELETE_TEMPLATES
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${DestPATH}"
)
endif()
endfunction(GEN_XPU)

# GEN_BACKEND(
Expand Down

0 comments on commit eaa429f

Please sign in to comment.