1- cmake_minimum_required (VERSION 3.21)
1+ cmake_minimum_required (VERSION 3.21 FATAL_ERROR )
22option (BUILD_FORTRAN_EXAMPLES "Whether to build fortran examples" ON )
33set (CMAKE_C_COMPILER icx)
44set (CMAKE_CXX_COMPILER icpx)
@@ -13,23 +13,24 @@ enable_testing()
1313
1414project (GPUOptGuide
1515 LANGUAGES ${_languages}
16- DESCRIPTION "Code examples from Intel GPU Optimization guide " )
16+ DESCRIPTION "Examples from oneAPI GPU Optimization Guide " )
1717
1818set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
1919
2020find_package (IntelSYCL REQUIRED)
2121
22+ if (BUILD_FOTRAN_EXAMPLES)
23+ check_language(Fortran)
24+ if (CMAKE_Fortran_COMPILER)
25+ enable_language (Fortran)
26+ else ()
27+ message (FATAL_ERROR "No Fortran support detected, but Fortran tests were requested. Install oneAPI HPC Toolkit." )
28+ endif ()
29+ endif ()
30+
2231set (MKL_THREADING tbb_thread)
2332set (MKL_INTERFACE "ilp64" )
2433set (DPCPP_COMPILER ON )
25-
26- set (MKL_VERSION_2024 FALSE )
27- find_package (MKL QUIET )
28- if (MKL_FOUND)
29- if (MKL_VERSION VERSION_GREATER_EQUAL "2024.0.0" )
30- set (MKL_VERSION_2024 TRUE )
31- endif ()
32- endif ()
3334find_package (MKL REQUIRED)
3435
3536string (CONCAT WARNING_CXX_FLAGS_STR
@@ -44,116 +45,162 @@ string(CONCAT WARNING_CXX_FLAGS_STR
4445string (REPLACE " " ";" COMMON_CXX_FLAGS "${WARNING_CXX_FLAGS_STR} " )
4546
4647function (add_example_with_mkl name )
47- set (_sources ${name} .cpp)
48- add_executable (${name} ${_sources} )
49- add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
50- target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
51- if (MKL_VERSION_2024)
52- target_link_libraries (${name} PUBLIC MKL::MKL_SYCL)
48+ cmake_parse_arguments (FUNC_SRC "" "" "SOURCES" ${ARGN} )
49+ if (FUNC_SRC_SOURCES)
50+ set (_src ${FUNC_SRC_SOURCES} )
5351 else ()
54- target_link_libraries ( ${name} PUBLIC MKL::MKL_DPCPP )
52+ set (_src ${name} .cpp )
5553 endif ()
54+ add_executable (${name} ${_src} )
55+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
56+ target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
57+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl)
58+ target_link_libraries (${name} PRIVATE MKL::MKL_DPCPP)
59+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -lOpenCL)
5660 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
5761endfunction (add_example_with_mkl)
5862
5963function (add_fortran_example_with_mkl name )
6064 if (CMAKE_Fortran_COMPILER)
61- set (_sources ${name} .f)
62- add_executable (${name} ${_sources } )
63- add_sycl_to_target(TARGET ${name} SOURCES ${_sources } )
65+ set (_src ${name} .f)
66+ add_executable (${name} ${_src } )
67+ add_sycl_to_target(TARGET ${name} SOURCES ${_src } )
6468 target_compile_options (${name} PRIVATE -warn all )
65- target_compile_options (${name} PRIVATE -fpp -free -DMKL_ILP64 -i8 )
69+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -fpp -free )
6670 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
67- if (MKL_VERSION_2024)
68- target_link_libraries (${name} PUBLIC MKL::MKL_SYCL)
69- else ()
70- target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
71- endif ()
71+ target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
72+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -lOpenCL)
7273 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
7374 endif ()
7475endfunction (add_fortran_example_with_mkl)
7576
77+ function (add_fortran_example_with_mkl_i8 name )
78+ if (CMAKE_Fortran_COMPILER)
79+ set (_src ${name} .f)
80+ add_executable (${name} ${_src} )
81+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
82+ target_compile_options (${name} PRIVATE -warn all )
83+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -fpp -free -DMKL_ILP64 -i8)
84+ set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
85+ target_link_libraries (${name} PUBLIC MKL::MKL_DPCPP)
86+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -qmkl -lOpenCL)
87+ add_test (NAME ${name} COMMAND ${name} ${ARGN} )
88+ endif ()
89+ endfunction (add_fortran_example_with_mkl_i8)
90+
7691function (add_example name )
77- set (_sources ${name} .cpp)
78- add_executable (${name} ${_sources} )
79- add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
92+ cmake_parse_arguments (FUNC_SRC "" "" "SOURCES" ${ARGN} )
93+ if (FUNC_SRC_SOURCES)
94+ set (_src ${FUNC_SRC_SOURCES} )
95+ else ()
96+ set (_src ${name} .cpp)
97+ endif ()
98+ add_executable (${name} ${_src} )
99+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
80100 target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
81101 target_link_options (${name} PRIVATE -fsycl-device-code-split=per_kernel)
82102 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
83103endfunction (add_example)
84104
85105function (add_openmp_example name )
86- set (_sources ${name} .cpp)
87- add_executable (${name} ${_sources} )
106+ set (_src ${name} .cpp)
107+ add_executable (${name} ${_src} )
108+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
88109 target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
89110 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
90111endfunction (add_openmp_example)
91112
92113function (add_fortran_example name )
93114 if (CMAKE_Fortran_COMPILER)
94- set (_sources ${name} .f90)
95- add_executable (${name} ${_sources } )
96- add_sycl_to_target(TARGET ${name} SOURCES ${_sources } )
115+ set (_src ${name} .f90)
116+ add_executable (${name} ${_src } )
117+ add_sycl_to_target(TARGET ${name} SOURCES ${_src } )
97118 target_compile_options (${name} PRIVATE -warn all )
119+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64)
98120 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
121+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64)
99122 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
100123 endif ()
101124endfunction (add_fortran_example)
102125
103126function (add_fixed_fortran_example name )
104127 if (CMAKE_Fortran_COMPILER)
105- set (_sources ${name} .f)
106- add_executable (${name} ${_sources} )
128+ set (_src ${name} .f)
129+ add_executable (${name} ${_src} )
130+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
107131 target_compile_options (${name} PRIVATE -warn all )
132+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64)
108133 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran)
109134 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
110135 endif ()
111136endfunction (add_fixed_fortran_example)
112137
113138function (add_mpi_example name )
114139 if (MPI_FOUND)
115- set (_sources ${name} .cpp)
116- add_executable (${name} ${_sources} )
117- add_sycl_to_target(TARGET ${name} SOURCES ${_sources} )
140+ set (_src ${name} .cpp)
141+ add_executable (${name} ${_src} )
142+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
143+ target_compile_options (${name} PRIVATE -O3 -fiopenmp -fopenmp-targets=spir64)
144+ target_link_options (${name} PRIVATE -O3 -fiopenmp -fopenmp-targets=spir64)
118145 target_link_libraries (${name} PRIVATE MPI::MPI_CXX)
119146 add_test (NAME ${name} COMMAND ${name} ${ARGN} )
120147 endif ()
121148endfunction (add_mpi_example)
122149
150+ function (add_example_with_mkl_mpi name )
151+ if (MPI_FOUND)
152+ set (_src ${name} .cpp)
153+ add_executable (${name} ${_src} )
154+ add_sycl_to_target(TARGET ${name} SOURCES ${_src} )
155+ target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
156+ if (NOT MKL_ROOT)
157+ set (MKL_ROOT $ENV{MKLROOT} CACHE PATH "Folder contains MKL" )
158+ endif (NOT MKL_ROOT)
159+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -fsycl -DMKL_LP64 -I"${MKLROOT} /include" )
160+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 -fsycl -L${MKLROOT} /lib -lmkl_sycl_blas -lmkl_intel_ilp64 -lmkl_tbb_thread -lmkl_core -lsycl -lpthread -lm -ldl)
161+ target_link_libraries (${name} PRIVATE MPI::MPI_CXX)
162+ add_test (NAME ${name} COMMAND ${name} ${ARGN} )
163+ endif ()
164+ endfunction (add_example_with_mkl_mpi)
165+
123166include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
124167
125168add_subdirectory (atomics)
126- add_subdirectory (matrix)
169+ add_subdirectory (buffer-accessors)
170+ add_subdirectory (buffers)
171+ add_subdirectory (composite-explicit-scaling)
172+ add_subdirectory (composite-implicit-scaling)
173+ add_subdirectory (conditionals)
127174add_subdirectory (exec-model)
128- add_subdirectory (explicit-scaling)
175+ add_subdirectory (flat)
176+ add_subdirectory (fp-computations)
177+ add_subdirectory (grf-mode-selection)
178+ add_subdirectory (host-device-memory)
129179add_subdirectory (io-kernel)
130180add_subdirectory (jitting)
181+ add_subdirectory (joint-matrix)
131182add_subdirectory (kernels)
132- add_subdirectory (memory-movement)
133- add_subdirectory (restrict)
134- add_subdirectory (slm)
135- add_subdirectory (usm)
136- add_subdirectory (sub-group)
137- add_subdirectory (buffers)
138- add_subdirectory (buffer-accessors)
139- add_subdirectory (reduction)
140- add_subdirectory (conditionals)
183+ add_subdirectory (libraries-fcorr)
141184add_subdirectory (libraries-kernel)
142185add_subdirectory (libraries-stdlib)
143- add_subdirectory (libraries-fcorr)
144- add_subdirectory (multiple-queue-submission)
186+ add_subdirectory (local-global -sync)
187+ add_subdirectory (matrix)
188+ add_subdirectory (memory-movement)
189+ add_subdirectory (MPI)
145190add_subdirectory (multiple-devices)
146191add_subdirectory (multiple-kernel-execution)
147- add_subdirectory (work-group-size )
148- add_subdirectory (registers )
192+ add_subdirectory (multiple-queue-submission )
193+ add_subdirectory (onemkl-scaling )
149194add_subdirectory (OpenMP)
150195add_subdirectory (optimize-data-transfers)
151- add_subdirectory (MPI)
152- add_subdirectory (grf-mode-selection)
153- add_subdirectory (fp-computations)
154- add_subdirectory (host-device-memory)
155- add_subdirectory (joint-matrix)
156- add_subdirectory (local-global -sync)
157- #add_subdirectory(memory-sharing-with-media)
196+ add_subdirectory (overlap-data-transfers)
197+ add_subdirectory (porting-registers)
198+ add_subdirectory (prefetch)
199+ add_subdirectory (reduction)
158200add_subdirectory (redundant-queues)
159- add_subdirectory (implicit-scaling)
201+ add_subdirectory (registers)
202+ add_subdirectory (restrict)
203+ add_subdirectory (slm)
204+ add_subdirectory (sub-group)
205+ add_subdirectory (usm)
206+ add_subdirectory (work-group-size)
0 commit comments