Skip to content

Commit d5e57da

Browse files
authored
Merge pull request #2546 from zma2/sync
Sync examples with the GPU Optimization Guide repo
2 parents 066b5b2 + 7bc7b4e commit d5e57da

File tree

254 files changed

+3590
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+3590
-672
lines changed
Lines changed: 109 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.21)
1+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
22
option(BUILD_FORTRAN_EXAMPLES "Whether to build fortran examples" ON)
33
set(CMAKE_C_COMPILER icx)
44
set(CMAKE_CXX_COMPILER icpx)
@@ -13,23 +13,24 @@ enable_testing()
1313

1414
project(GPUOptGuide
1515
LANGUAGES ${_languages}
16-
DESCRIPTION "Code examples from Intel GPU Optimization guide")
16+
DESCRIPTION "Examples from oneAPI GPU Optimization Guide")
1717

1818
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
1919

2020
find_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+
2231
set(MKL_THREADING tbb_thread)
2332
set(MKL_INTERFACE "ilp64")
2433
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()
3334
find_package(MKL REQUIRED)
3435

3536
string(CONCAT WARNING_CXX_FLAGS_STR
@@ -44,116 +45,162 @@ string(CONCAT WARNING_CXX_FLAGS_STR
4445
string(REPLACE " " ";" COMMON_CXX_FLAGS "${WARNING_CXX_FLAGS_STR}")
4546

4647
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})
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})
5761
endfunction(add_example_with_mkl)
5862

5963
function(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()
7475
endfunction(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+
7691
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})
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})
83103
endfunction(add_example)
84104

85105
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})
88109
target_compile_options(${name} PRIVATE ${COMMON_CXX_FLAGS})
89110
add_test(NAME ${name} COMMAND ${name} ${ARGN})
90111
endfunction(add_openmp_example)
91112

92113
function(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()
101124
endfunction(add_fortran_example)
102125

103126
function(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()
111136
endfunction(add_fixed_fortran_example)
112137

113138
function(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()
121148
endfunction(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+
123166
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
124167

125168
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)
127174
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)
129179
add_subdirectory(io-kernel)
130180
add_subdirectory(jitting)
181+
add_subdirectory(joint-matrix)
131182
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)
141184
add_subdirectory(libraries-kernel)
142185
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)
145190
add_subdirectory(multiple-devices)
146191
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)
149194
add_subdirectory(OpenMP)
150195
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)
158200
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)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
add_mpi_example(omp_mpich)
2-
target_compile_options(omp_mpich PRIVATE -fiopenmp)
3-
target_link_options(omp_mpich PRIVATE -fiopenmp)

Publications/GPU-Opt-Guide/MPI/01_omp_mpich/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "oneAPI GPU Optimization Guide Examples",
88
"toolchain": [
99
"dpcpp",
10-
"ifort"
10+
"ifx"
1111
],
1212
"languages": [
1313
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_example_with_mkl_mpi(dgemm 8192 8192 8192)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#OMP_AFFINITIZATION = 0 to ensure affinitization through MPI environment variables, and = 1 to use OpenMP to affinitize the MPI rank
2+
OMP_AFFINITIZATION=0
3+
4+
CC=mpicxx
5+
INCLUDE=-I$(MKLROOT)/include
6+
LIB="$(MKLROOT)/lib"/libmkl_sycl.a -Wl,--start-group "$(MKLROOT)/lib"/libmkl_intel_lp64.a "$(MKLROOT)/lib"/libmkl_intel_thread.a "$(MKLROOT)/lib"/libmkl_core.a -Wl,--end-group -lsycl -lOpenCL -liomp5 -lpthread -ldl -lm -lstdc++
7+
CFLAGS=-cxx=icpx -fiopenmp -fopenmp-targets=spir64 -fsycl -DOMP_AFFINITIZATION=$(OMP_AFFINITIZATION)
8+
CFLAGS2=-cxx=icpx -fsycl-device-code-split=per_kernel -fiopenmp -fopenmp-targets=spir64 -fsycl
9+
10+
dgemm: dgemm.o Makefile
11+
$(CC) $(CFLAGS2) dgemm.o $(LIB) -o dgemm
12+
13+
dgemm.o: dgemm.cpp Makefile
14+
$(CC) $(CFLAGS) $(INCLUDE) -c dgemm.cpp -o dgemm.o
15+
16+
clean:
17+
rm -rf ./dgemm ./dgemm.o

0 commit comments

Comments
 (0)