Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI ONLY] Init MKL for Pytorch XPU and enable fft_c2c #573

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions cmake/BuildFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -fno-approx-func)
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -Wno-absolute-value)
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -no-ftz)
# Equivalent to build option -fpreview-breaking-changes for SYCL compiler.
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D__INTEL_PREVIEW_BREAKING_CHANGES)
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
endif()
# TODO: Align with PyTorch and switch to ABI=0 eventually, after
# resolving incompatible implementation in SYCL runtime.
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D_GLIBCXX_USE_CXX11_ABI=1)
set(SYCL_FLAGS ${SYCL_FLAGS} ${SYCL_KERNEL_OPTIONS})

set(TORCH_XPU_OPS_FLAGS ${SYCL_HOST_FLAGS})
Expand Down
3 changes: 1 addition & 2 deletions cmake/Modules/FindSYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ else()
endif()

set(SYCL_LIBRARIES)
find_library(SYCL_RUNTIME_LIBRARY sycl HINTS ${SYCL_LIBRARY_DIR})
find_library(SYCL_RUNTIME_LIBRARY sycl-preview HINTS ${SYCL_LIBRARY_DIR})
# On Windows, currently there's no sycl.lib. Only sycl7.lib with version suffix,
# where the current version of the SYCL runtime is 7.
# Until oneAPI adds support to sycl.lib without the version suffix,
Expand Down Expand Up @@ -427,7 +427,6 @@ macro(SYCL_LINK_DEVICE_OBJECTS output_file sycl_target)
OUTPUT ${output_file}
DEPENDS ${object_files}
COMMAND ${SYCL_EXECUTABLE}
-fsycl
${SYCL_device_link_flags}
-fsycl-link ${object_files}
-Xs "\"${SYCL_OFFLINE_COMPILER_FLAGS}\""
Expand Down
7 changes: 6 additions & 1 deletion cmake/Modules/FindSYCLToolkit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ find_file(

find_library(
SYCL_LIBRARY
NAMES sycl
NAMES sycl-preview
HINTS ${SYCL_LIBRARY_DIR}
NO_DEFAULT_PATH
)
Expand Down Expand Up @@ -202,6 +202,11 @@ set(SYCL_FLAGS "")
set(SYCL_LINK_FLAGS "")
list(APPEND SYCL_FLAGS "-fsycl")
list(APPEND SYCL_LINK_FLAGS "-fsycl")
# Workaround about XPU ABI neutral build
if(LINUX)
list(APPEND SYCL_FLAGS "-fpreview-breaking-changes")
list(APPEND SYCL_LINK_FLAGS "-fpreview-breaking-changes")
endif()

set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")

Expand Down
71 changes: 71 additions & 0 deletions cmake/Modules/FindoneMKL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
set(ONEMKL_FOUND FALSE)

set(ONEMKL_DYNAMIC_LIBRARIES)
set(ONEMKL_STATIC_LIBRARIES)

set(ONEMKL_DEFAULT_DIR "/opt/intel/oneapi/mkl/latest")
if(DEFINED ENV{MKLROOT})
set(ONEMKL_ROOT $ENV{MKLROOT})
elseif(EXISTS "${ONEMKL_DEFAULT_DIR}")
set(ONEMKL_ROOT "${ONEMKL_DEFAULT_DIR}")
endif()

if(NOT ONEMKL_ROOT)
message(WARNING "Cannot find oneMKL in ENV{MKLROOT} or default path, please setup oneMKL before building!!")
return()
endif()

find_file(
ONEMKL_INCLUDE_DIR
NAMES include
HINTS ${ONEMKL_ROOT}
NO_DEFAULT_PATH
)

find_file(
ONEMKL_LIB_DIR
NAMES lib
HINTS ${ONEMKL_ROOT}
NO_DEFAULT_PATH
)

if((NOT ONEMKL_INCLUDE_DIR) OR (NOT ONEMKL_LIB_DIR))
message(WARNING "oneMKL sdk is incomplete!!")
return()
endif()

set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH}
"${ONEMKL_INCLUDE_DIR}")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
"${ONEMKL_LIB_DIR}")

set(MKL_DYNAMIC_LIB_NAMES "mkl_sycl_dft")

foreach(LIB_NAME IN LISTS MKL_DYNAMIC_LIB_NAMES)
find_library(
${LIB_NAME}_library
NAMES ${LIB_NAME}
HINTS ${ONEMKL_LIB_DIR}
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
)
list(APPEND ONEMKL_DYNAMIC_LIBRARIES ${${LIB_NAME}_library})
endforeach()

set(MKL_STATIC_LIB_NAMES "mkl_intel_lp64" "mkl_gnu_thread" "mkl_core")

foreach(LIB_NAME IN LISTS MKL_STATIC_LIB_NAMES)
find_library(
${LIB_NAME}_library
NAMES lib${LIB_NAME}.a
HINTS ${ONEMKL_LIB_DIR}
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
)
list(APPEND ONEMKL_STATIC_LIBRARIES ${${LIB_NAME}_library})
endforeach()

list(INSERT ONEMKL_STATIC_LIBRARIES 0 "-Wl,--start-group")
list(APPEND ONEMKL_STATIC_LIBRARIES "-Wl,--end-group")

set(ONEMKL_FOUND TRUE)
2 changes: 1 addition & 1 deletion cmake/SYCL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(NOT SYCL_VERSION)
return()
endif()

find_library(SYCL_LIBRARIES sycl HINTS ${SYCL_LIBRARY_DIR})
find_library(SYCL_LIBRARIES sycl-preview HINTS ${SYCL_LIBRARY_DIR})
# On Windows, currently there's no sycl.lib. Only sycl7.lib with version suffix,
# where the current version of the SYCL runtime is 7.
# Until oneAPI adds support to sycl.lib without the version suffix,
Expand Down
3 changes: 3 additions & 0 deletions src/ATen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# ATen XPU sources

file(GLOB xpu_cpp "xpu/*.cpp", "native/xpu/*.cpp", "native/sparse/*.cpp")
file(GLOB xpu_mkl "native/xpu/mkl/*.cpp")
file(GLOB xpu_sycl "native/xpu/sycl/*.cpp")

list(APPEND ATen_XPU_CPP_SRCS ${xpu_cpp})
list(APPEND ATen_XPU_MKL_SRCS ${xpu_mkl})
list(APPEND ATen_XPU_SYCL_SRCS ${xpu_sycl})

set(ATen_XPU_CPP_SRCS ${ATen_XPU_CPP_SRCS} PARENT_SCOPE)
set(ATen_XPU_MKL_SRCS ${ATen_XPU_MKL_SRCS} PARENT_SCOPE)
set(ATen_XPU_SYCL_SRCS ${ATen_XPU_SYCL_SRCS} PARENT_SCOPE)
40 changes: 40 additions & 0 deletions src/ATen/native/xpu/SpectralOps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <ATen/ATen.h>
#include <ATen/native/xpu/mkl/SpectralOps.h>
#include <ATen/xpu/XPUNativeFunctions.h>

namespace at {

Tensor XPUNativeFunctions::_fft_c2c(
const Tensor& self,
IntArrayRef dim,
int64_t normalization,
bool forward) {
TORCH_CHECK(self.is_complex());

if (dim.empty()) {
return self.clone();
}

return native::xpu::_fft_c2c_kernel(self, dim, normalization, forward);
}

Tensor& XPUNativeFunctions::_fft_c2c_out(
const Tensor& self,
IntArrayRef dim,
int64_t normalization,
bool forward,
Tensor& out) {
TORCH_CHECK(self.is_complex());

if (dim.empty()) {
out.copy_(self);
return out;
}

Tensor result =
native::xpu::_fft_c2c_kernel(self, dim, normalization, forward);
out.copy_(result);
return out;
}

} // namespace at
1 change: 0 additions & 1 deletion src/ATen/native/xpu/XPUFallback.template
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ TORCH_LIBRARY_IMPL(aten, XPU, m) {
"exp2.out",
"expm1.out",
"exponential_",
"_fft_c2c",
"_fft_c2r",
"_fft_r2c",
"_flash_attention_forward",
Expand Down
Loading
Loading