Skip to content

Commit 093403e

Browse files
clevelsroot
andauthored
Update Buffers/Accessors according to latest coding guidelines (Matrix_multiply Advisor and VTune). (#215)
* TBB Samples Migration Signed-off-by: root <[email protected]> * Addressing PR Change Requests Signed-off-by: root <[email protected]> * Fill in "Purpose" Section of both README files. Signed-off-by: root <[email protected]> * Remove binary and build files Signed-off-by: root <[email protected]> * include dpc_common header, remove exception handler, fix json files. (all changes apply to both samples) Signed-off-by: root <[email protected]> * include dpc_common headers, remove exception handlers (both samples) Signed-off-by: root <[email protected]> * Fix README files, include header files for windows * Remove namespace, end files, use "std::iota", fix README Signed-off-by: root <[email protected]> * fix README Signed-off-by: root <[email protected]> * Fix "matrix_multiply" samples failures on Windows. * buffer/accessor updates for coding guidelines (matrix mul). Co-authored-by: root <[email protected]>
1 parent 091c9ad commit 093403e

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

Tools/Advisor/matrix_multiply_advisor/src/multiply.cpp

100644100755
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66

7+
#include <array>
8+
#include <CL/sycl.hpp>
79
// matrix multiply routines
810
#include "multiply.hpp"
911

10-
#include <CL/sycl.hpp>
11-
#include <array>
12-
1312
using namespace cl::sycl;
1413
using namespace std;
1514

16-
constexpr cl::sycl::access::mode sycl_read = cl::sycl::access::mode::read;
17-
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write;
18-
constexpr cl::sycl::access::mode sycl_read_write = cl::sycl::access::mode::read_write;
19-
2015
template <typename T>
2116
class Matrix1;
2217

@@ -39,16 +34,17 @@ void multiply1(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],
3934
range<2> matrix_range{NUM, NUM};
4035

4136
// Declare 3 buffers and Initialize them
42-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
43-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
44-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
37+
buffer bufferA((TYPE*)a, range(matrix_range));
38+
buffer bufferB((TYPE*)b, range(matrix_range));
39+
buffer bufferC((TYPE*)c, range(matrix_range));
40+
4541
// Submit our job to the queue
4642
q.submit([&](cl::sycl::handler& h) {
4743
// Declare 3 accessors to our buffers. The first 2 read and the last
48-
// read_write
49-
auto accessorA = bufferA.get_access<sycl_read>(h);
50-
auto accessorB = bufferB.get_access<sycl_read>(h);
51-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
44+
// read_write
45+
accessor accessorA(bufferA, h, read_only);
46+
accessor accessorB(bufferB, h, read_only);
47+
accessor accessorC(bufferC, h);
5248

5349
// Execute matrix multiply in parallel over our matrix_range
5450
// ind is an index into this range
@@ -76,17 +72,17 @@ void multiply1_1(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],TYP
7672
range<2> matrix_range{NUM, NUM};
7773

7874
// Declare 3 buffers and Initialize them
79-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
80-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
81-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
75+
buffer bufferA((TYPE*)a, range(matrix_range));
76+
buffer bufferB((TYPE*)b, range(matrix_range));
77+
buffer bufferC((TYPE*)c, range(matrix_range));
8278

8379
// Submit our job to the queue
8480
q.submit([&](cl::sycl::handler& h) {
8581
// Declare 3 accessors to our buffers. The first 2 read and the last
86-
// read_write
87-
auto accessorA = bufferA.get_access<sycl_read>(h);
88-
auto accessorB = bufferB.get_access<sycl_read>(h);
89-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
82+
// read_write
83+
accessor accessorA(bufferA, h, read_only);
84+
accessor accessorB(bufferB, h, read_only);
85+
accessor accessorC(bufferC, h);
9086

9187
// Execute matrix multiply in parallel over our matrix_range
9288
// ind is an index into this range
@@ -117,17 +113,17 @@ void multiply1_2(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],
117113
range<2> tile_range{MATRIXTILESIZE, MATRIXTILESIZE};
118114

119115
// Declare 3 buffers and Initialize them
120-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
121-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
122-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
116+
buffer bufferA((TYPE*)a, range(matrix_range));
117+
buffer bufferB((TYPE*)b, range(matrix_range));
118+
buffer bufferC((TYPE*)c, range(matrix_range));
123119

124120
// Submit our job to the queue
125121
q.submit([&](cl::sycl::handler& h) {
126122
// Declare 3 accessors to our buffers. The first 2 read and the last
127-
// read_write
128-
auto accessorA = bufferA.get_access<sycl_read>(h);
129-
auto accessorB = bufferB.get_access<sycl_read>(h);
130-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
123+
// read_write
124+
accessor accessorA(bufferA, h, read_only);
125+
accessor accessorB(bufferB, h, read_only);
126+
accessor accessorC(bufferC, h);
131127

132128
// Create matrix tiles
133129
accessor<TYPE, 2, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> aTile(cl::sycl::range<2>(MATRIXTILESIZE, MATRIXTILESIZE), h);

Tools/VTuneProfiler/matrix_multiply_vtune/src/multiply.cpp

100644100755
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66

7+
#include <array>
8+
#include <CL/sycl.hpp>
79
// matrix multiply routines
810
#include "multiply.hpp"
911

10-
#include <CL/sycl.hpp>
11-
#include <array>
12-
1312
using namespace cl::sycl;
1413
using namespace std;
1514

16-
constexpr cl::sycl::access::mode sycl_read = cl::sycl::access::mode::read;
17-
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write;
18-
constexpr cl::sycl::access::mode sycl_read_write = cl::sycl::access::mode::read_write;
19-
2015
template <typename T>
2116
class Matrix1;
2217

@@ -39,16 +34,17 @@ void multiply1(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],
3934
range<2> matrix_range{NUM, NUM};
4035

4136
// Declare 3 buffers and Initialize them
42-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
43-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
44-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
37+
buffer bufferA((TYPE*)a, range(matrix_range));
38+
buffer bufferB((TYPE*)b, range(matrix_range));
39+
buffer bufferC((TYPE*)c, range(matrix_range));
40+
4541
// Submit our job to the queue
4642
q.submit([&](cl::sycl::handler& h) {
4743
// Declare 3 accessors to our buffers. The first 2 read and the last
48-
// read_write
49-
auto accessorA = bufferA.get_access<sycl_read>(h);
50-
auto accessorB = bufferB.get_access<sycl_read>(h);
51-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
44+
// read_write
45+
accessor accessorA(bufferA, h, read_only);
46+
accessor accessorB(bufferB, h, read_only);
47+
accessor accessorC(bufferC, h);
5248

5349
// Execute matrix multiply in parallel over our matrix_range
5450
// ind is an index into this range
@@ -75,18 +71,18 @@ void multiply1_1(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],TYP
7571
// Declare a 2 dimensional range
7672
range<2> matrix_range{NUM, NUM};
7773

78-
// Declare 3 buffers and Initialize them
79-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
80-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
81-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
74+
// Declare 3 buffers and Initialize them
75+
buffer bufferA((TYPE*)a, range(matrix_range));
76+
buffer bufferB((TYPE*)b, range(matrix_range));
77+
buffer bufferC((TYPE*)c, range(matrix_range));
8278

8379
// Submit our job to the queue
8480
q.submit([&](cl::sycl::handler& h) {
8581
// Declare 3 accessors to our buffers. The first 2 read and the last
86-
// read_write
87-
auto accessorA = bufferA.get_access<sycl_read>(h);
88-
auto accessorB = bufferB.get_access<sycl_read>(h);
89-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
82+
// read_write
83+
accessor accessorA(bufferA, h, read_only);
84+
accessor accessorB(bufferB, h, read_only);
85+
accessor accessorC(bufferC, h);
9086

9187
// Execute matrix multiply in parallel over our matrix_range
9288
// ind is an index into this range
@@ -117,17 +113,17 @@ void multiply1_2(int msize, int tidx, int numt, TYPE a[][NUM], TYPE b[][NUM],
117113
range<2> tile_range{MATRIXTILESIZE, MATRIXTILESIZE};
118114

119115
// Declare 3 buffers and Initialize them
120-
buffer<TYPE, 2> bufferA((TYPE*)a, matrix_range);
121-
buffer<TYPE, 2> bufferB((TYPE*)b, matrix_range);
122-
buffer<TYPE, 2> bufferC((TYPE*)c, matrix_range);
116+
buffer bufferA((TYPE*)a, range(matrix_range));
117+
buffer bufferB((TYPE*)b, range(matrix_range));
118+
buffer bufferC((TYPE*)c, range(matrix_range));
123119

124120
// Submit our job to the queue
125121
q.submit([&](cl::sycl::handler& h) {
126122
// Declare 3 accessors to our buffers. The first 2 read and the last
127-
// read_write
128-
auto accessorA = bufferA.get_access<sycl_read>(h);
129-
auto accessorB = bufferB.get_access<sycl_read>(h);
130-
auto accessorC = bufferC.get_access<sycl_read_write>(h);
123+
// read_write
124+
accessor accessorA(bufferA, h, read_only);
125+
accessor accessorB(bufferB, h, read_only);
126+
accessor accessorC(bufferC, h);
131127

132128
// Create matrix tiles
133129
accessor<TYPE, 2, cl::sycl::access::mode::read_write, cl::sycl::access::target::local> aTile(cl::sycl::range<2>(MATRIXTILESIZE, MATRIXTILESIZE), h);

0 commit comments

Comments
 (0)