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

Event free: Make the event free APIs compatible with different compil… #1188

Merged
merged 13 commits into from
Jan 3, 2025
3 changes: 2 additions & 1 deletion .github/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
source /opt/intel/oneapi/pytorch-gpu-dev-0.5/oneapi-vars.sh
source /opt/intel/oneapi/compiler/latest/env/vars.sh
source /opt/intel/oneapi/umf/latest/env/vars.sh
source /opt/intel/oneapi/pti/latest/env/vars.sh
4 changes: 3 additions & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
if: ${{ (github.repository_owner == 'intel') && (github.event.pull_request.draft == false) }}
uses: ./.github/workflows/_linux_ut.yml
with:
pytorch: release/2.5
ut: op_example,op_extended,op_ut
runner: linux.idc.xpu

Expand All @@ -32,6 +33,7 @@ jobs:
if: ${{ (github.repository_owner == 'intel') && (github.event.pull_request.draft == false) }}
uses: ./.github/workflows/_linux_ut.yml
with:
pytorch: release/2.5
abi: 0
ut: op_extended
runner: linux.idc.xpu
Expand All @@ -57,7 +59,7 @@ jobs:
pwd
cd ../ && rm -rf pytorch
source activate e2e_ci
git clone -b main https://github.com/pytorch/pytorch pytorch
git clone -b release/2.5 https://github.com/pytorch/pytorch pytorch
cd pytorch
# apply PRs for stock pytorch
pip install requests
Expand Down
6 changes: 6 additions & 0 deletions cmake/BuildFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
list(APPEND SYCL_HOST_FLAGS -Wno-deprecated)
list(APPEND SYCL_HOST_FLAGS -Wno-attributes)
list(APPEND SYCL_HOST_FLAGS -Wno-sign-compare)
list(APPEND SYCL_HOST_FLAGS -Wno-error=comment)
list(APPEND SYCL_HOST_FLAGS -Wno-error=terminate)
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND SYCL_HOST_FLAGS -g)
list(APPEND SYCL_HOST_FLAGS -O0)
endif(CMAKE_BUILD_TYPE MATCHES Debug)

list(APPEND SYCL_HOST_FLAGS -D__INTEL_LLVM_COMPILER_VERSION=${__INTEL_LLVM_COMPILER})
# -- Kernel flags (SYCL_KERNEL_OPTIONS)
# The fast-math will be enabled by default in SYCL compiler.
# Refer to [https://clang.llvm.org/docs/UsersManual.html#cmdoption-fno-fast-math]
Expand Down Expand Up @@ -81,10 +84,13 @@ 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)
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -Wno-error=comment)
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -Wno-error=terminate)
# 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()
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D__INTEL_LLVM_COMPILER_VERSION=${__INTEL_LLVM_COMPILER})

CHECK_SYCL_FLAG("-fsycl-fp64-conv-emu" SUPPORTS_FP64_CONV_EMU)
if(SUPPORTS_FP64_CONV_EMU)
Expand Down
56 changes: 45 additions & 11 deletions cmake/Modules/FindSYCLToolkit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ endif()

# Function to write a test case to verify SYCL features.

function(SYCL_CMPLR_TEST_WRITE src)
function(SYCL_CMPLR_TEST_WRITE src macro_name)

set(cpp_macro_if "#if")
set(cpp_macro_endif "#endif")
Expand All @@ -88,8 +88,8 @@ function(SYCL_CMPLR_TEST_WRITE src)

# Feature tests goes here

string(APPEND SYCL_CMPLR_TEST_CONTENT "${cpp_macro_if} defined(SYCL_LANGUAGE_VERSION)\n")
string(APPEND SYCL_CMPLR_TEST_CONTENT "cout << \"SYCL_LANGUAGE_VERSION=\"<<SYCL_LANGUAGE_VERSION<<endl;\n")
string(APPEND SYCL_CMPLR_TEST_CONTENT "${cpp_macro_if} defined(${macro_name})\n")
string(APPEND SYCL_CMPLR_TEST_CONTENT "cout << \"${macro_name}=\"<<${macro_name}<<endl;\n")
string(APPEND SYCL_CMPLR_TEST_CONTENT "${cpp_macro_endif}\n")

string(APPEND SYCL_CMPLR_TEST_CONTENT "return 0;}\n")
Expand All @@ -103,6 +103,7 @@ endfunction()
function(SYCL_CMPLR_TEST_BUILD error TEST_SRC_FILE TEST_EXE)

set(SYCL_CXX_FLAGS_LIST "${SYCL_CXX_FLAGS}")
string(REPLACE "-Wno-stringop-overflow" "" SYCL_CXX_FLAGS_LIST "${SYCL_CXX_FLAGS_LIST}")
separate_arguments(SYCL_CXX_FLAGS_LIST)

execute_process(
Expand Down Expand Up @@ -150,19 +151,19 @@ function(SYCL_CMPLR_TEST_RUN error TEST_EXE)

endfunction()

function(SYCL_CMPLR_TEST_EXTRACT test_output)
function(SYCL_CMPLR_TEST_EXTRACT test_output macro_name)

string(REGEX REPLACE "\n" ";" test_output_list "${test_output}")

set(SYCL_LANGUAGE_VERSION "")
set(${macro_name} "")
foreach(strl ${test_output_list})
if(${strl} MATCHES "^SYCL_LANGUAGE_VERSION=([A-Za-z0-9_]+)$")
string(REGEX REPLACE "^SYCL_LANGUAGE_VERSION=" "" extracted_sycl_lang "${strl}")
set(SYCL_LANGUAGE_VERSION ${extracted_sycl_lang})
if(${strl} MATCHES "^${macro_name}=([A-Za-z0-9_]+)$")
string(REGEX REPLACE "^${macro_name}=" "" extracted_sycl_lang "${strl}")
set(${macro_name} ${extracted_sycl_lang})
endif()
endforeach()

set(SYCL_LANGUAGE_VERSION "${SYCL_LANGUAGE_VERSION}" PARENT_SCOPE)
set(${macro_name} "${extracted_sycl_lang}" PARENT_SCOPE)
endfunction()

set(SYCL_FLAGS "")
Expand All @@ -189,7 +190,7 @@ if(${has_werror} EQUAL -1)
# Create the test source file
set(TEST_SRC_FILE "${SYCL_CMPLR_TEST_DIR}/sycl_features.cpp")
set(TEST_EXE "${TEST_SRC_FILE}.exe")
SYCL_CMPLR_TEST_WRITE(${TEST_SRC_FILE})
SYCL_CMPLR_TEST_WRITE(${TEST_SRC_FILE} "SYCL_LANGUAGE_VERSION")

# Build the test and create test executable
SYCL_CMPLR_TEST_BUILD(error ${TEST_SRC_FILE} ${TEST_EXE})
Expand All @@ -204,7 +205,7 @@ if(${has_werror} EQUAL -1)
endif()

# Extract test output for information
SYCL_CMPLR_TEST_EXTRACT(${test_output})
SYCL_CMPLR_TEST_EXTRACT(${test_output} "SYCL_LANGUAGE_VERSION")

# As per specification, all the SYCL compatible compilers should
# define macro SYCL_LANGUAGE_VERSION
Expand All @@ -221,5 +222,38 @@ if(${has_werror} EQUAL -1)
set(SYCL_LANGUAGE_VERSION "${SYCL_LANGUAGE_VERSION}" CACHE STRING "SYCL Language version")
endif()

# Create a clean working directory.
set(SYCL_CMPLR_TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/TESTSYCLCMPLR")
file(REMOVE_RECURSE ${SYCL_CMPLR_TEST_DIR})
file(MAKE_DIRECTORY ${SYCL_CMPLR_TEST_DIR})
# Create the test source file
set(TEST_SRC_FILE "${SYCL_CMPLR_TEST_DIR}/llvm_features.cpp")
set(TEST_EXE "${TEST_SRC_FILE}.exe")
SYCL_CMPLR_TEST_WRITE(${TEST_SRC_FILE} "__INTEL_LLVM_COMPILER")
# Build the test and create test executable
SYCL_CMPLR_TEST_BUILD(error ${TEST_SRC_FILE} ${TEST_EXE})
if(error)
message(FATAL_ERROR "Can not build SYCL_CMPLR_TEST")
endif()
# Execute the test to extract information
SYCL_CMPLR_TEST_RUN(error ${TEST_EXE})
if(error)
message(FATAL_ERROR "Can not run SYCL_CMPLR_TEST")
endif()
# Extract test output for information
SYCL_CMPLR_TEST_EXTRACT(${test_output} "__INTEL_LLVM_COMPILER")

# Check whether the value of __INTEL_LLVM_COMPILER macro was successfully extracted
string(COMPARE EQUAL "${__INTEL_LLVM_COMPILER}" "" nosycllang)
if(nosycllang)
set(SYCLTOOLKIT_FOUND False)
set(SYCL_REASON_FAILURE "Can not find __INTEL_LLVM_COMPILER}")
set(SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
endif()


# Include in Cache
set(__INTEL_LLVM_COMPILER "${__INTEL_LLVM_COMPILER}" CACHE STRING "Intel llvm compiler")

message(DEBUG "The SYCL compiler is ${SYCL_COMPILER}")
message(DEBUG "The SYCL Flags are ${SYCL_FLAGS}")
43 changes: 43 additions & 0 deletions src/comm/SYCLHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ static inline void sycl_kernel_submit(
::sycl::range<dim> range,
::sycl::queue q,
ker_t ker) {
#if SYCL_EXT_ONEAPI_ENQUEUE_FUNCTIONS == 1
auto cgf = [&](::sycl::handler& cgh) {
::sycl::ext::oneapi::experimental::parallel_for<ker_t>(cgh, range, ker);
};
::sycl::ext::oneapi::experimental::submit(q, cgf);
#else
auto cgf = [&](::sycl::handler& cgh) { cgh.parallel_for<ker_t>(range, ker); };
q.submit(cgf);
#endif
}

// Additional convention of SYCL kernel configuration. Besides construct kernel
Expand All @@ -80,12 +85,21 @@ sycl_kernel_submit(
::sycl::range<dim> local_range,
::sycl::queue q,
ker_t ker) {
#if SYCL_EXT_ONEAPI_ENQUEUE_FUNCTIONS == 1
auto cgf = [&](::sycl::handler& cgh) {
ker.sycl_ker_config_convention(cgh);
::sycl::ext::oneapi::experimental::nd_launch<ker_t>(
cgh, ::sycl::nd_range<dim>(global_range, local_range), ker);
};
::sycl::ext::oneapi::experimental::submit(q, cgf);
#else
auto cgf = [&](::sycl::handler& cgh) {
ker.sycl_ker_config_convention(cgh);
cgh.parallel_for<ker_t>(
::sycl::nd_range<dim>(global_range, local_range), ker);
};
q.submit(cgf);
#endif
}

template <typename ker_t, int dim>
Expand All @@ -97,11 +111,19 @@ sycl_kernel_submit(
::sycl::range<dim> local_range,
::sycl::queue q,
ker_t ker) {
#if SYCL_EXT_ONEAPI_ENQUEUE_FUNCTIONS == 1
auto cgf = [&](::sycl::handler& cgh) {
::sycl::ext::oneapi::experimental::nd_launch<ker_t>(
cgh, ::sycl::nd_range<dim>(global_range, local_range), ker);
};
::sycl::ext::oneapi::experimental::submit(q, cgf);
#else
auto cgf = [&](::sycl::handler& cgh) {
cgh.parallel_for<ker_t>(
::sycl::nd_range<dim>(global_range, local_range), ker);
};
q.submit(cgf);
#endif
}

template <typename ker_t>
Expand All @@ -113,6 +135,7 @@ sycl_kernel_submit(
int64_t local_range,
::sycl::queue q,
ker_t ker) {
#if SYCL_EXT_ONEAPI_ENQUEUE_FUNCTIONS == 1
auto cgf = [&](::sycl::handler& cgh) {
ker.sycl_ker_config_convention(cgh);
::sycl::ext::oneapi::experimental::nd_launch<ker_t>(
Expand All @@ -122,6 +145,16 @@ sycl_kernel_submit(
ker);
};
::sycl::ext::oneapi::experimental::submit(q, cgf);
#else
auto cgf = [&](::sycl::handler& cgh) {
ker.sycl_ker_config_convention(cgh);
cgh.parallel_for<ker_t>(
::sycl::nd_range<1>(
::sycl::range<1>(global_range), ::sycl::range<1>(local_range)),
ker);
};
q.submit(cgf);
#endif
}

template <typename ker_t>
Expand All @@ -133,6 +166,7 @@ sycl_kernel_submit(
int64_t local_range,
::sycl::queue q,
ker_t ker) {
#if SYCL_EXT_ONEAPI_ENQUEUE_FUNCTIONS == 1
auto cgf = [&](::sycl::handler& cgh) {
::sycl::ext::oneapi::experimental::nd_launch<ker_t>(
cgh,
Expand All @@ -141,4 +175,13 @@ sycl_kernel_submit(
ker);
};
::sycl::ext::oneapi::experimental::submit(q, cgf);
#else
auto cgf = [&](::sycl::handler& cgh) {
cgh.parallel_for<ker_t>(
::sycl::nd_range<1>(
::sycl::range<1>(global_range), ::sycl::range<1>(local_range)),
ker);
};
q.submit(cgf);
#endif
}
3 changes: 3 additions & 0 deletions test/xpu/extended/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
"test_compare_cpu_nanmedian_xpu_int64",
"test_compare_cpu_nanmedian_xpu_int8",
"test_compare_cpu_nanmedian_xpu_uint8",
"test_compare_cpu_nn_functional_unfold_xpu_bool",
"test_non_standard_bool_values_nn_functional_unfold_xpu_bool",
"test_non_standard_bool_values_index_put_xpu_bool",
)


Expand Down
Loading