Skip to content

Use IntelSYCL cmake script #1400

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

Merged
merged 14 commits into from
Oct 10, 2023
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ jobs:
run: |
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE${{ runner.os == 'Linux' && '/' || '\\' }}" >> $GITHUB_ENV
- name: Build conda package
env:
OVERRIDE_INTEL_IPO: 1 # IPO requires more resources that GH actions VM provides
run: conda build --no-test --python ${{ matrix.python }} -c intel -c conda-forge --override-channels conda-recipe
- name: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ option(DPCTL_GENERATE_COVERAGE
OFF
)

find_package(IntelDPCPP REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)
find_package(IntelSYCL REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)

add_subdirectory(libsyclinterface)

Expand Down
142 changes: 99 additions & 43 deletions cmake/IntelDPCPPConfig.cmake → cmake/IntelSYCLConfig.cmake
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Modifications, Copyright (C) 2021 Intel Corporation
# Modifications, Copyright (C) 2022 Intel Corporation
#
# This software and the related documents are Intel copyrighted materials, and
# your use of them is governed by the express license under which they were
Expand All @@ -15,19 +15,19 @@
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
IntelDPCPPConfig
IntelSYCLConfig
-------

DPCPP Library to verify DPCPP/SYCL compatability of CMAKE_CXX_COMPILER
Library to verify SYCL compatability of CMAKE_CXX_COMPILER
and passes relevant compiler flags.

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables:

``IntelDPCPP_FOUND``
True if the system has the DPCPP library.
``IntelSYCL_FOUND``
True if the system has the SYCL library.
``SYCL_LANGUAGE_VERSION``
The SYCL language spec version by Compiler.
``SYCL_INCLUDE_DIR``
Expand All @@ -37,35 +37,39 @@ This will define the following variables:
``SYCL_FLAGS``
SYCL specific flags for the compiler.

``IntelSYCL::SYCL_CXX``
Target for using Intel SYCL (DPC++). The following properties are defined
for the target: ``INTERFACE_COMPILE_OPTIONS``, ``INTERFACE_LINK_OPTIONS``,
``INTERFACE_INCLUDE_DIRECTORIES``, and ``INTERFACE_LINK_DIRECTORIES``

Cache Variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:
The following cache variable may also be set:

``SYCL_INCLUDE_DIR``
The directory containing ``sycl.hpp``.
``SYCL_LIBRARY_DIR``
The path to the SYCL library.
``SYCL_FLAGS``
SYCL specific flags for the compiler.
``SYCL_LANGUAGE_VERSION``
The SYCL language spec version by Compiler.


.. note::
.. Note::

For now, user needs to set -DCMAKE_CXX_COMPILER or environment of
1. User needs to set -DCMAKE_CXX_COMPILER or environment of
CXX pointing to SYCL compatible compiler ( eg: icx, clang++, icpx)

Note: do not set to DPCPP compiler. If set to a Compiler family
that supports dpcpp ( eg: IntelLLVM) both DPCPP and SYCL
features are enabled.

And add this package to user's Cmake config file.
2. Add this package to user's Cmake config file.

.. code-block:: cmake

find_package(IntelSYCL REQUIRED)

3. Add sources to target through add_sycl_to_target()

.. code-block:: cmake

find_package(IntelDPCPP REQUIRED)
# Compile specific sources for SYCL and build target for SYCL
add_executable(target_proj A.cpp B.cpp offload1.cpp offload2.cpp)
add_sycl_to_target(TARGET target_proj SOURCES offload1.cpp offload2.cpp)

#]=======================================================================]

Expand All @@ -83,25 +87,33 @@ endif()

string(COMPARE EQUAL "${CMAKE_CXX_COMPILER}" "" nocmplr)
if(nocmplr)
set(IntelDPCPP_FOUND False)
set(IntelSYCL_FOUND False)
set(SYCL_REASON_FAILURE "SYCL: CMAKE_CXX_COMPILER not set!!")
set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
set(IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
endif()

# Check if a Compiler ID is being set. project() should be set prior to find_package()

if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "x")
set(IntelSYCL_FOUND False)
set(SYCL_REASON_FAILURE "CMake CXX Compiler family is not set. Please make sure find_package(IntelSYCL) is called after project()!!")
set(IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
return()
endif()

# Check for known compiler family that supports SYCL

if( NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang" AND
NOT "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM")
set(IntelDPCPP_FOUND False)
set(IntelSYCL_FOUND False)
set(SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER}!!")
set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
set(IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
return()
endif()

# Assume that CXX Compiler supports SYCL and then test to verify.
set(SYCL_COMPILER ${CMAKE_CXX_COMPILER})


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

function(SYCL_FEATURE_TEST_WRITE src)
Expand Down Expand Up @@ -144,7 +156,7 @@ function(SYCL_FEATURE_TEST_BUILD TEST_SRC_FILE TEST_EXE)
OUTPUT_VARIABLE output ERROR_VARIABLE output
OUTPUT_FILE ${SYCL_TEST_DIR}/Compile.log
RESULT_VARIABLE result
TIMEOUT 20
TIMEOUT 60
)

# Verify if test case build properly.
Expand All @@ -168,12 +180,12 @@ function(SYCL_FEATURE_TEST_RUN TEST_EXE)
WORKING_DIRECTORY ${SYCL_TEST_DIR}
OUTPUT_VARIABLE output ERROR_VARIABLE output
RESULT_VARIABLE result
TIMEOUT 20
TIMEOUT 60
)

# Verify the test execution output.
if(test_result)
set(IntelDPCPP_FOUND False)
set(IntelSYCL_FOUND False)
set(SYCL_REASON_FAILURE "SYCL: feature test execution failed!!")
endif()
# TODO: what iff the result is false.. error or ignore?
Expand Down Expand Up @@ -236,14 +248,14 @@ set(SYCL_LINK_FLAGS "")
# Based on Compiler ID, add support for SYCL
if( "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang" OR
"x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntelLLVM")
set(SYCL_FLAGS "-fsycl ")
set(SYCL_LINK_FLAGS "-fsycl ")
list(APPEND SYCL_FLAGS "-fsycl")
list(APPEND SYCL_LINK_FLAGS "-fsycl")
endif()

# TODO verify if this is needed
# Windows: Add Exception handling
if(WIN32)
set(SYCL_FLAGS "${SYCL_FLAGS} /EHsc")
list(APPEND SYCL_FLAGS "/EHsc")
endif()

set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")
Expand Down Expand Up @@ -273,32 +285,76 @@ SYCL_FEATURE_TEST_EXTRACT(${test_output})
# define macro SYCL_LANGUAGE_VERSION
string(COMPARE EQUAL "${SYCL_LANGUAGE_VERSION}" "" nosycllang)
if(nosycllang)
set(IntelDPCPP_FOUND False)
set(IntelSYCL_FOUND False)
set(SYCL_REASON_FAILURE "SYCL: It appears that the ${CMAKE_CXX_COMPILER} does not support SYCL")
set(IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
set(IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
endif()

# Placeholder for identifying various implemenations of SYCL compilers.
# for now, set to the CMAKE_CXX_COMPILER_ID
set(SYCL_IMPLEMENTATION_ID "${CMAKE_CXX_COMPILER_ID}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS}")
message(DEBUG "The SYCL compiler is ${SYCL_COMPILER}")
message(DEBUG "The SYCL Flags are ${SYCL_FLAGS}")
message(DEBUG "The SYCL Language Version is ${SYCL_LANGUAGE_VERSION}")

message(STATUS "Echo from ${CMAKE_CURRENT_SOURCE_DIR}/IntelDPCPPConfig.cmake")
message(STATUS "The SYCL compiler is ${SYCL_COMPILER}")
message(STATUS "The SYCL Flags are ${SYCL_FLAGS}")
message(STATUS "The SYCL Language Version is ${SYCL_LANGUAGE_VERSION}")
add_library(IntelSYCL::SYCL_CXX INTERFACE IMPORTED)
set_property(TARGET IntelSYCL::SYCL_CXX PROPERTY
INTERFACE_COMPILE_OPTIONS ${SYCL_FLAGS})
set_property(TARGET IntelSYCL::SYCL_CXX PROPERTY
INTERFACE_LINK_OPTIONS ${SYCL_LINK_FLAGS})
set_property(TARGET IntelSYCL::SYCL_CXX PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${SYCL_INCLUDE_DIR})
set_property(TARGET IntelSYCL::SYCL_CXX PROPERTY
INTERFACE_LINK_DIRECTORIES ${SYCL_LIBRARY_DIR})

find_package_handle_standard_args(
IntelDPCPP
FOUND_VAR IntelDPCPP_FOUND
IntelSYCL
FOUND_VAR IntelSYCL_FOUND
REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_FLAGS
VERSION_VAR SYCL_LANGUAGE_VERSION
REASON_FAILURE_MESSAGE "${SYCL_REASON_FAILURE}")

# Include in Cache
set(SYCL_LANGUAGE_VERSION "${SYCL_LANGUAGE_VERSION}" CACHE STRING "SYCL Language version")
set(SYCL_INCLUDE_DIR "${SYCL_INCLUDE_DIR}" CACHE FILEPATH "SYCL Include directory")
set(SYCL_LIBRARY_DIR "${SYCL_LIBRARY_DIR}" CACHE FILEPATH "SYCL Library Directory")
set(SYCL_FLAGS "${SYCL_FLAGS}" CACHE STRING "SYCL flags for the compiler")

function(add_sycl_to_target)

set(one_value_args TARGET)
set(multi_value_args SOURCES)
cmake_parse_arguments(SYCL
""
"${one_value_args}"
"${multi_value_args}"
${ARGN})


get_target_property(__sycl_cxx_options IntelSYCL::SYCL_CXX INTERFACE_COMPILE_OPTIONS)
get_target_property(__sycl_cxx_include_directories IntelSYCL::SYCL_CXX INTERFACE_INCLUDE_DIRECTORIES)

if(NOT ${ARGC})
message(FATAL_ERROR " add_sycl_to_target() does not have any arguments")
elseif(${ARGC} EQUAL 1)
message(WARNING "add_sycl_to_target() have only one argument specified.. assuming the target to be ${ARGV}.
Adding sycl to all sources but that may effect compilation times")
set(SYCL_TARGET ${ARGV})
endif()

if(NOT SYCL_SOURCES)
message(WARNING "add_sycl_to_target() does not have sources specified.. Adding sycl to all sources but that may effect compilation times")
target_compile_options(${SYCL_TARGET} PUBLIC ${__sycl_cxx_options})
target_include_directories(${SYCL_TARGET} PUBLIC ${__sycl_cxx_include_directories})
endif()

foreach(source ${SYCL_SOURCES})
set_source_files_properties(${source} PROPERTIES COMPILE_OPTIONS "${__sycl_cxx_options}")
set_source_files_properties(${source} PROPERTIES INCLUDE_DIRECTORIES "${__sycl_cxx_include_directories}")
endforeach()

get_target_property(__sycl_link_options
IntelSYCL::SYCL_CXX INTERFACE_LINK_OPTIONS)
target_link_options(${SYCL_TARGET} PRIVATE "${__sycl_link_options}")
get_target_property(__sycl_link_directories
IntelSYCL::SYCL_CXX INTERFACE_LINK_DIRECTORIES)
target_link_directories(${SYCL_TARGET} PUBLIC "${__sycl_link_directories}")
endfunction(add_sycl_to_target)
5 changes: 5 additions & 0 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ set "INCLUDE=%BUILD_PREFIX%\include;%INCLUDE%"
"%PYTHON%" setup.py clean --all
set "SKBUILD_ARGS=-G Ninja -- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"

REM Overriding IPO is useful for building in resources constrained VMs (public CI)
if DEFINED OVERRIDE_INTEL_IPO (
set "SKBUILD_ARGS=%SKBUILD_ARGS% -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=FALSE"
)

FOR %%V IN (14.0.0 14 15.0.0 15 16.0.0 16 17.0.0 17) DO @(
REM set DIR_HINT if directory exists
IF EXIST "%BUILD_PREFIX%\Library\lib\clang\%%V\" (
Expand Down
1 change: 1 addition & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build:
number: {{ GIT_DESCRIBE_NUMBER }}
script_env:
- WHEELS_OUTPUT_FOLDER
- OVERRIDE_INTEL_IPO # [win]

requirements:
build:
Expand Down
16 changes: 12 additions & 4 deletions dpctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ elseif(UNIX)
string(CONCAT CXXFLAGS
"${WARNING_FLAGS}"
"${SDL_FLAGS}"
"-fsycl "
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 ${CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 ${CXXFLAGS}")
Expand Down Expand Up @@ -137,10 +136,15 @@ add_custom_target(
set(CMAKE_INSTALL_RPATH "$ORIGIN")

function(build_dpctl_ext _trgt _src _dest)
set(options SYCL)
cmake_parse_arguments(BUILD_DPCTL_EXT "${options}" "" "" ${ARGN})
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
set(_cythonize_trgt "${_trgt}_cythonize_pyx")
add_custom_target(${_cythonize_trgt} DEPENDS ${_src})
python_add_library(${_trgt} MODULE ${_generated_src})
Python_add_library(${_trgt} MODULE WITH_SOABI ${_generated_src})
if (BUILD_DPCTL_EXT_SYCL)
add_sycl_to_target(TARGET ${_trgt} SOURCES ${_generated_src})
endif()
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy ${_cythonize_trgt})
if (DPCTL_GENERATE_COVERAGE)
Expand Down Expand Up @@ -185,14 +189,18 @@ function(build_dpctl_ext _trgt _src _dest)
install(TARGETS ${_trgt} LIBRARY DESTINATION ${_dest})
endfunction()

file(GLOB _cython_sources *.pyx)
file(GLOB _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.pyx)
list(REMOVE_ITEM _cython_sources ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)
foreach(_cy_file ${_cython_sources})
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl")
endforeach()

set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_sycl_queue.pyx)
get_filename_component(_trgt ${_cy_file} NAME_WLE)
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl" SYCL)
# _sycl_queue include _host_task_util.hpp
target_include_directories(_sycl_queue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${_trgt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(program)
add_subdirectory(memory)
Expand Down
20 changes: 16 additions & 4 deletions dpctl/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ if(WIN32)
endif()
endif()

set(python_module_name _tensor_impl)
pybind11_add_module(${python_module_name} MODULE
set(_tensor_impl_sources
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/tensor_py.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/accumulators.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/simplify_iteration_space.cpp
Expand All @@ -52,16 +51,29 @@ pybind11_add_module(${python_module_name} MODULE
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/repeat.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/reduction_over_axis.cpp
)

set(python_module_name _tensor_impl)
pybind11_add_module(${python_module_name} MODULE ${_tensor_impl_sources})
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_tensor_impl_sources})
set(_clang_prefix "")
if (WIN32)
set(_clang_prefix "/clang:")
endif()
set_source_files_properties(

set(_no_fast_math_sources
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/full_ctor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/linear_sequences.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/reduction_over_axis.cpp
PROPERTIES COMPILE_OPTIONS "${_clang_prefix}-fno-fast-math")
)
foreach(_src_fn ${_no_fast_math_sources})
get_source_file_property(_cmpl_options_prop ${_src_fn} COMPILE_OPTIONS)
set(_combined_options_prop ${_cmpl_options_prop} "${_clang_prefix}-fno-fast-math")
set_source_files_properties(
${_src_fn}
PROPERTIES COMPILE_OPTIONS "${_combined_options_prop}"
)
endforeach()
if (UNIX)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions.cpp
Expand Down
4 changes: 3 additions & 1 deletion dpctl/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ add_custom_target(_dpctl4pybind11_header_ready
)

set(python_module_name _device_queries)
set(_module_src ${CMAKE_CURRENT_SOURCE_DIR}/src/device_queries.cpp)
pybind11_add_module(${python_module_name} MODULE
${CMAKE_CURRENT_SOURCE_DIR}/src/device_queries.cpp
${_module_src}
)
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
target_include_directories(${python_module_name}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
Expand Down
Loading