1
- cmake_minimum_required (VERSION 3.21 )
1
+ cmake_minimum_required (VERSION 3.21 FATAL_ERROR )
2
2
option (BUILD_FORTRAN_EXAMPLES "Whether to build fortran examples" ON )
3
3
set (CMAKE_C_COMPILER icx )
4
4
set (CMAKE_CXX_COMPILER icpx )
@@ -13,23 +13,24 @@ enable_testing()
13
13
14
14
project (GPUOptGuide
15
15
LANGUAGES ${_languages}
16
- DESCRIPTION "Code examples from Intel GPU Optimization guide " )
16
+ DESCRIPTION "Examples from oneAPI GPU Optimization Guide " )
17
17
18
18
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH )
19
19
20
20
find_package (IntelSYCL REQUIRED )
21
21
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
+
22
31
set (MKL_THREADING tbb_thread )
23
32
set (MKL_INTERFACE "ilp64" )
24
33
set (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 ()
33
34
find_package (MKL REQUIRED )
34
35
35
36
string (CONCAT WARNING_CXX_FLAGS_STR
@@ -44,116 +45,162 @@ string(CONCAT WARNING_CXX_FLAGS_STR
44
45
string (REPLACE " " ";" COMMON_CXX_FLAGS "${WARNING_CXX_FLAGS_STR} " )
45
46
46
47
function (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} )
53
51
else ()
54
- target_link_libraries ( ${name} PUBLIC MKL::MKL_DPCPP )
52
+ set ( _src ${name} .cpp )
55
53
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 )
56
60
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
57
61
endfunction (add_example_with_mkl )
58
62
59
63
function (add_fortran_example_with_mkl name )
60
64
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 } )
64
68
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 )
66
70
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 )
72
73
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
73
74
endif ()
74
75
endfunction (add_fortran_example_with_mkl )
75
76
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
+
76
91
function (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} )
80
100
target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
81
101
target_link_options (${name} PRIVATE -fsycl-device-code-split=per_kernel )
82
102
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
83
103
endfunction (add_example )
84
104
85
105
function (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} )
88
109
target_compile_options (${name} PRIVATE ${COMMON_CXX_FLAGS} )
89
110
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
90
111
endfunction (add_openmp_example )
91
112
92
113
function (add_fortran_example name )
93
114
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 } )
97
118
target_compile_options (${name} PRIVATE -warn all )
119
+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 )
98
120
set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran )
121
+ target_link_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 )
99
122
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
100
123
endif ()
101
124
endfunction (add_fortran_example )
102
125
103
126
function (add_fixed_fortran_example name )
104
127
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} )
107
131
target_compile_options (${name} PRIVATE -warn all )
132
+ target_compile_options (${name} PRIVATE -fiopenmp -fopenmp-targets=spir64 )
108
133
set_target_properties (${name} PROPERTIES LINKER_LANGUAGE Fortran )
109
134
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
110
135
endif ()
111
136
endfunction (add_fixed_fortran_example )
112
137
113
138
function (add_mpi_example name )
114
139
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 )
118
145
target_link_libraries (${name} PRIVATE MPI::MPI_CXX )
119
146
add_test (NAME ${name} COMMAND ${name} ${ARGN} )
120
147
endif ()
121
148
endfunction (add_mpi_example )
122
149
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
+
123
166
include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
124
167
125
168
add_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 )
127
174
add_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 )
129
179
add_subdirectory (io-kernel )
130
180
add_subdirectory (jitting )
181
+ add_subdirectory (joint-matrix )
131
182
add_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 )
141
184
add_subdirectory (libraries-kernel )
142
185
add_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 )
145
190
add_subdirectory (multiple-devices )
146
191
add_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 )
149
194
add_subdirectory (OpenMP )
150
195
add_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 )
158
200
add_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