Skip to content

Commit 9a1bdbf

Browse files
authored
Merge pull request #2472 from nawalcopty/development
Update examples in OneAPI Samples Repo to match GPU Opt Guide Repo
2 parents f8cf7d7 + 1b556cc commit 9a1bdbf

29 files changed

+913
-1054
lines changed

Publications/GPU-Opt-Guide/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ add_subdirectory(multiple-kernel-execution)
147147
add_subdirectory(work-group-size)
148148
add_subdirectory(registers)
149149
add_subdirectory(OpenMP)
150+
add_subdirectory(optimize-data-transfers)
150151
add_subdirectory(MPI)
151152
add_subdirectory(grf-mode-selection)
152153
add_subdirectory(fp-computations)

Publications/GPU-Opt-Guide/OpenMP/21_omp_target_alloc/test_target_map_f.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ program main
5555

5656
nstream_time = omp_get_wtime()
5757
do iter = 1, iterations
58-
!$omp target teams distribute parallel do &
59-
map(to: A, B) map(tofrom: C)
58+
!$omp target teams distribute parallel do map(to: A, B) map(tofrom: C)
6059
do i = 1, length
6160
C(i) = C(i) + A(i) + scalar * B(i)
6261
end do

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_batch_example_01.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -95,6 +94,7 @@ int main()
9594

9695
t_start = omp_get_wtime();
9796

97+
// Snippet begin
9898
// Call cblas_dgemm_batch
9999
#pragma omp target enter data \
100100
map(to: A1[0:m*k], B1[0:k*n], C1[0:m*n]) \
@@ -132,6 +132,7 @@ int main()
132132

133133
#pragma omp target exit data \
134134
map(from: C1[0:m*n], C2[0:m*n])
135+
// Snippet end
135136

136137
t_end = omp_get_wtime();
137138

@@ -216,4 +217,3 @@ int main()
216217

217218
return 0;
218219
}
219-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_batch_example_02.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* License.
1919
*******************************************************************************/
2020

21-
// Snippet begin
2221
#include <stdio.h>
2322
#include <omp.h>
2423
#include "mkl.h"
@@ -153,6 +152,7 @@ int main() {
153152
cblas_dgemm_batch(layout, transA, transB, m, n, k, alpha, (const double **) a_array, lda,
154153
(const double **) b_array, ldb, beta, c_ref_array, ldc, GROUP_COUNT, group_size);
155154

155+
// Snippet begin
156156
double *a, *b, *c;
157157
for (i = 0; i < total_batch_size; i++) {
158158
a = a_array[i];
@@ -182,6 +182,7 @@ int main() {
182182
c = c_array[i];
183183
#pragma omp target exit data map(from:a[0:sizea_array[i]],b[0:sizeb_array[i]],c[0:sizec_array[i]])
184184
}
185+
// Snippet end
185186

186187
double computed, reference, diff;
187188
MKL_INT l;
@@ -254,4 +255,3 @@ int main() {
254255
mkl_free(alpha); mkl_free(beta);
255256
return 0;
256257
}
257-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_dispatch_c.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -61,12 +60,14 @@ int main()
6160

6261
printf (" Computing matrix product using Intel oneMKL dgemm function via CBLAS interface \n\n");
6362

63+
// Snippet begin
6464
#pragma omp target data map(to: A[0:m*k], B[0:k*n]) map(tofrom: C[0:m*n])
6565
{
66-
#pragma omp target variant dispatch use_device_ptr(A, B, C)
66+
#pragma omp dispatch
6767
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
6868
m, n, k, alpha, A, k, B, n, beta, C, n);
6969
}
70+
// Snippet end
7071

7172
printf ("\n Top left corner of matrix C: \n");
7273
for (i=0; i<min(m,6); i++) {
@@ -115,7 +116,7 @@ int main()
115116
mkl_free(A);
116117
mkl_free(B);
117118
mkl_free(C);
119+
mkl_free(C_fl);
118120

119121
return fail;
120122
}
121-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_dispatch_f.f

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
!
44
! SPDX-License-Identifier: MIT
55
!=============================================================
6-
! Snippet begin
76
include "mkl_omp_offload.f90"
87

98
program DGEMM_MAIN
@@ -68,12 +67,14 @@ program DGEMM_MAIN
6867

6968
! Execute DGEMM on device
7069

70+
! Snippet begin
7171
!$omp target data map(to: a, b) map(tofrom: c2)
7272

7373
!$omp dispatch
7474
call DGEMM('N','N',m,n,k,alpha,a,m,b,k,beta,c2,m)
7575

7676
!$omp end target data
77+
! Snippet end
7778

7879
print *
7980
print *, 'c2 - After DGEMM device execution'
@@ -86,4 +87,3 @@ program DGEMM_MAIN
8687
110 format(7x,10(f10.2,2x))
8788

8889
end
89-
! Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_example_01.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -70,6 +69,7 @@ int main()
7069

7170
t_start = omp_get_wtime();
7271

72+
// Snippet begin
7373
#pragma omp target data \
7474
map(to: A1[0:m*k], B1[0:k*n], A2[0:m*k], B2[0:k*n]) \
7575
map(tofrom: C1[0:m*n], C2[0:m*n])
@@ -82,6 +82,7 @@ int main()
8282
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
8383
m, n, k, alpha, A2, k, B2, n, beta, C2, n);
8484
}
85+
// Snippet end
8586

8687
t_end = omp_get_wtime();
8788

@@ -166,4 +167,3 @@ int main()
166167

167168
return 0;
168169
}
169-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_example_02.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -70,6 +69,7 @@ int main()
7069

7170
t_start = omp_get_wtime();
7271

72+
// Snippet begin
7373
#pragma omp target data \
7474
map(to: A1[0:m*k], B1[0:k*n], A2[0:m*k], B2[0:k*n]) \
7575
map(tofrom: C1[0:m*n], C2[0:m*n])
@@ -90,6 +90,7 @@ int main()
9090
}
9191
}
9292
}
93+
// Snippet end
9394

9495
t_end = omp_get_wtime();
9596

@@ -174,4 +175,3 @@ int main()
174175

175176
return 0;
176177
}
177-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_example_03.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -70,6 +69,7 @@ int main()
7069

7170
t_start = omp_get_wtime();
7271

72+
// Snippet begin
7373
#pragma omp target data \
7474
map(to: A1[0:m*k], B1[0:k*n], A2[0:m*k], B2[0:k*n]) \
7575
map(tofrom: C1[0:m*n], C2[0:m*n])
@@ -84,6 +84,7 @@ int main()
8484

8585
#pragma omp taskwait
8686
}
87+
// Snippet end
8788

8889
t_end = omp_get_wtime();
8990

@@ -168,4 +169,3 @@ int main()
168169

169170
return 0;
170171
}
171-
// Snippet end

Publications/GPU-Opt-Guide/OpenMP/22_mkl_dispatch/dgemm_target_variant_dispatch_c.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
// clang-format off
7-
// Snippet begin
87
#include <stdio.h>
98
#include <stdlib.h>
109
#include <math.h>
@@ -61,6 +60,7 @@ int main()
6160

6261
printf (" Computing matrix product using Intel oneMKL dgemm function via CBLAS interface \n\n");
6362

63+
// Snippet begin
6464
#pragma omp target data map(to: A[0:m*k], B[0:k*n]) map(tofrom: C[0:m*n])
6565
{
6666
#pragma omp target variant dispatch use_device_ptr(A, B, C)
@@ -69,6 +69,7 @@ int main()
6969
m, n, k, alpha, A, k, B, n, beta, C, n);
7070
}
7171
}
72+
// Snippet end
7273

7374
printf ("\n Top left corner of matrix C: \n");
7475
for (i=0; i<min(m,6); i++) {
@@ -117,7 +118,7 @@ int main()
117118
mkl_free(A);
118119
mkl_free(B);
119120
mkl_free(C);
121+
mkl_free(C_fl);
120122

121123
return fail;
122124
}
123-
// Snippet end

0 commit comments

Comments
 (0)