@@ -2,29 +2,33 @@ cmake_minimum_required(VERSION 3.21)
22option (BUILD_FORTRAN_EXAMPLES "Whether to build fortran examples" ON )
33set (CMAKE_C_COMPILER icx)
44set (CMAKE_CXX_COMPILER icpx)
5+ set (_languages C CXX)
6+
57if (BUILD_FORTRAN_EXAMPLES)
8+ set (_languages ${_languages} Fortran)
69 set (CMAKE_Fortran_COMPILER ifx)
710endif ()
811
9- project (GPUOptGuide)
10- set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
1112
12- include (CheckLanguage)
13- enable_testing ()
13+ project (GPUOptGuide
14+ LANGUAGES ${_languages}
15+ DESCRIPTION "Code examples from Intel GPU Optimization guide" )
1416
15- find_package (IntelDPCPP REQUIRED )
17+ set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH )
1618
17- if (BUILD_FOTRAN_EXAMPLES)
18- check_language(Fortran)
19- if (CMAKE_Fortran_COMPILER)
20- enable_language (Fortran)
21- else ()
22- message (FATAL_ERROR "No Fortran support detected, but Fortran tests were requested. Install oneAPI HPC Toolkit." )
23- endif ()
24- endif ()
19+ find_package (IntelSYCL REQUIRED)
2520
2621set (MKL_THREADING tbb_thread)
22+ set (MKL_INTERFACE "ilp64" )
2723set (DPCPP_COMPILER ON )
24+
25+ set (MKL_VERSION_2024 FALSE )
26+ find_package (MKL QUIET )
27+ if (MKL_FOUND)
28+ if (MKL_VERSION VERSION_GREATER_EQUAL "2024.0.0" )
29+ set (MKL_VERSION_2024 TRUE )
30+ endif ()
31+ endif ()
2832find_package (MKL REQUIRED)
2933
3034string (CONCAT WARNING_CXX_FLAGS_STR
@@ -39,49 +43,77 @@ string(CONCAT WARNING_CXX_FLAGS_STR
3943string (REPLACE " " ";" COMMON_CXX_FLAGS "${WARNING_CXX_FLAGS_STR} " )
4044
4145function (add_example_with_mkl name )
42- add_executable (${name} ${name} .cpp)
46+ set (_sources ${name} .cpp)
47+ add_executable (${name} ${_sources} )
48+ add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
4349 target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
44- target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl)
45- target_link_libraries (${name} PRIVATE MKL::MKL_DPCPP)
46- target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -lOpenCL)
50+ if (MKL_VERSION_2024)
51+ target_link_libraries (${name} PUBLIC MKL::MKL_SYCL)
52+ else ()
53+ target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
54+ endif ()
4755 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
4856endfunction (add_example_with_mkl)
4957
5058function (add_fortran_example_with_mkl name )
5159 if (CMAKE_Fortran_COMPILER)
52- add_executable (${name} ${name} .f)
60+ set (_sources ${name} .f)
61+ add_executable (${name} ${_sources} )
62+ add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
5363 target_compile_options (${name} PRIVATE -warn all )
54- target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl - fpp -free)
64+ target_compile_options (${name} PRIVATE -fpp -free)
5565 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
56- target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
57- target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -lOpenCL)
66+ if (MKL_VERSION_2024)
67+ target_link_libraries (${name} PUBLIC MKL::MKL_SYCL)
68+ else ()
69+ target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
70+ endif ()
5871 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
5972 endif ()
6073endfunction (add_fortran_example_with_mkl)
6174
6275function (add_example name )
63- add_executable (${name} ${name} .cpp)
76+ set (_sources ${name} .cpp)
77+ add_executable (${name} ${_sources} )
78+ add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
6479 target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
6580 target_link_options (${name} PRIVATE -fsycl-device-code-split=per_kernel)
6681 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
6782endfunction (add_example)
6883
84+ function (add_openmp_example name )
85+ set (_sources ${name} .cpp)
86+ add_executable (${name} ${_sources} )
87+ target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
88+ add_test (NAME ${name} COMMAND ${name} ${ARGN} )
89+ endfunction (add_openmp_example)
90+
6991function (add_fortran_example name )
7092 if (CMAKE_Fortran_COMPILER)
71- add_executable (${name} ${name} .f90)
93+ set (_sources ${name} .f90)
94+ add_executable (${name} ${_sources} )
95+ add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
7296 target_compile_options (${name} PRIVATE -warn all )
73- target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64)
7497 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
75- target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64)
7698 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
7799 endif ()
78100endfunction (add_fortran_example)
79101
102+ function (add_fixed_fortran_example name )
103+ if (CMAKE_Fortran_COMPILER)
104+ set (_sources ${name} .f)
105+ add_executable (${name} ${_sources} )
106+ target_compile_options (${name} PRIVATE -warn all )
107+ set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
108+ add_test (NAME ${name} COMMAND ${name} ${ARGN} )
109+ endif ()
110+ endfunction (add_fixed_fortran_example)
111+
80112function (add_mpi_example name )
81113 if (MPI_FOUND)
82- add_executable ( ${name} ${name} .cpp)
83- target_compile_options (${name} PRIVATE -O3 -fiopenmp -fopenmp-targets=spir64 )
84- target_link_options ( ${name} PRIVATE -O3 -fiopenmp -fopenmp-targets=spir64 )
114+ set (_sources ${name} .cpp)
115+ add_executable (${name} ${_sources} )
116+ add_sycl_to_target( TARGET ${name} SOURCES ${_sources} )
85117 target_link_libraries (${name} PRIVATE MPI::MPI_CXX)
86118 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
87119 endif ()
0 commit comments