xref: /aosp_15_r20/external/pytorch/cmake/Modules/FindSYCLToolkit.cmake (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# This will define the following variables:
2# SYCL_FOUND               : True if the system has the SYCL library.
3# SYCL_INCLUDE_DIR         : Include directories needed to use SYCL.
4# SYCL_LIBRARY_DIR         :The path to the SYCL library.
5# SYCL_LIBRARY             : SYCL library fullname.
6
7include(FindPackageHandleStandardArgs)
8
9set(SYCL_ROOT "")
10if(DEFINED ENV{SYCL_ROOT})
11  set(SYCL_ROOT $ENV{SYCL_ROOT})
12elseif(DEFINED ENV{CMPLR_ROOT})
13  set(SYCL_ROOT $ENV{CMPLR_ROOT})
14endif()
15
16string(COMPARE EQUAL "${SYCL_ROOT}" "" nosyclfound)
17if(nosyclfound)
18  set(SYCL_FOUND False)
19  set(SYCL_REASON_FAILURE "SYCL library not set!!")
20  set(SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
21  return()
22endif()
23
24# Find include path from binary.
25find_file(
26  SYCL_INCLUDE_DIR
27  NAMES include
28  HINTS ${SYCL_ROOT}
29  NO_DEFAULT_PATH
30  )
31
32# Find include/sycl path from include path.
33find_file(
34  SYCL_INCLUDE_SYCL_DIR
35  NAMES sycl
36  HINTS ${SYCL_ROOT}/include/
37  NO_DEFAULT_PATH
38  )
39
40# Due to the unrecognized compilation option `-fsycl` in other compiler.
41list(APPEND SYCL_INCLUDE_DIR ${SYCL_INCLUDE_SYCL_DIR})
42
43# Find library directory from binary.
44find_file(
45  SYCL_LIBRARY_DIR
46  NAMES lib lib64
47  HINTS ${SYCL_ROOT}
48  NO_DEFAULT_PATH
49  )
50
51# Find SYCL library fullname.
52if(LINUX)
53  find_library(
54    SYCL_LIBRARY
55    NAMES sycl-preview
56    HINTS ${SYCL_LIBRARY_DIR}
57    NO_DEFAULT_PATH
58  )
59endif()
60# On Windows, currently there's no sycl.lib. Only sycl7.lib with version suffix,
61# where the current version of the SYCL runtime is 7.
62# Until oneAPI adds support to sycl.lib without the version suffix,
63# sycl_runtime_version needs to be hardcoded and uplifted when SYCL runtime version uplifts.
64# TODO: remove this when sycl.lib is supported on Windows
65if(WIN32)
66  set(sycl_runtime_version 7)
67  find_library(
68    SYCL_LIBRARY
69    NAMES "sycl${sycl_runtime_version}"
70    HINTS ${SYCL_LIBRARY_DIR}
71    NO_DEFAULT_PATH
72  )
73  if(SYCL_LIBRARY STREQUAL "SYCL_LIBRARY-NOTFOUND")
74    message(FATAL_ERROR "Cannot find a SYCL library on Windows")
75  endif()
76endif()
77
78find_library(
79  OCL_LIBRARY
80  NAMES OpenCL
81  HINTS ${SYCL_LIBRARY_DIR}
82  NO_DEFAULT_PATH
83)
84
85if((NOT SYCL_INCLUDE_DIR) OR (NOT SYCL_LIBRARY_DIR) OR (NOT SYCL_LIBRARY))
86  set(SYCL_FOUND False)
87  set(SYCL_REASON_FAILURE "SYCL library is incomplete!!")
88  set(SYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE}")
89  return()
90endif()
91
92find_package_handle_standard_args(
93  SYCL
94  FOUND_VAR SYCL_FOUND
95  REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_LIBRARY
96  REASON_FAILURE_MESSAGE "${SYCL_REASON_FAILURE}")
97