Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL][Matrix] Add get-coord API and general query example #7964

Merged
merged 53 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9628bd0
- Remove the general query from TODO list as an example is added to t…
dkhaldi Jan 9, 2023
39875df
add an other distribution example
dkhaldi Jan 9, 2023
e42ef4a
add revision history
dkhaldi Jan 10, 2023
8bb98c1
Bader comments
dkhaldi Jan 10, 2023
48386d6
better wording
dkhaldi Jan 10, 2023
1e85155
Incorporate Greg comments and other improvements, specifically:
dkhaldi Jan 12, 2023
6f91525
Update the specification document to follow the formal template
dkhaldi Jan 30, 2023
cdcab5a
add tf32 type and conversion function
dkhaldi Jan 30, 2023
04e18fe
correct the matrix types in the appendix
dkhaldi Jan 30, 2023
9403a38
correct the matrix types in the appendix
dkhaldi Jan 30, 2023
ddb87f1
remove _t from the types
dkhaldi Jan 30, 2023
8a8e0a9
Specify in Status that joint matrix is an optional kernel feature
dkhaldi Feb 4, 2023
7e610aa
Move the iteration-style EWOps to the Intel extension and introduce j…
dkhaldi Feb 9, 2023
509056c
Address Jack's comments
dkhaldi Feb 10, 2023
805630c
Add get_info runtime query
dkhaldi Feb 13, 2023
20c09c9
reword the optional device feature checking
dkhaldi Feb 14, 2023
a7494c8
Address Greg's comments
dkhaldi Feb 28, 2023
7159591
Incorporate the last batch of Greg's comments
dkhaldi Feb 28, 2023
5b9fdfc
incorporate Greg's comments: query syntax
dkhaldi Mar 2, 2023
e0f683e
use sycl::ext::oneapi::experimental::architecture and remove scope query
dkhaldi Mar 2, 2023
008dbfc
fix the comments formatting
dkhaldi Mar 2, 2023
efb103a
- Add overloads and explanation for each of the API in the tf32 section
dkhaldi Mar 6, 2023
e69ff85
typo
dkhaldi Mar 6, 2023
6868a37
Address Greg's comments in the Intel extension
dkhaldi Mar 11, 2023
fb70d27
Add overload of joint matrix apply where row and col are provided
dkhaldi Mar 20, 2023
433e65a
Address Greg's comments: change packed name, add tf32 rounding mode, …
dkhaldi Mar 23, 2023
f5694eb
fix formatting
dkhaldi Mar 23, 2023
862880e
Address Greg's comments: remove loop-based indexing, add Td and defau…
dkhaldi Apr 24, 2023
885cf09
Incorporate Greg's suggestions
dkhaldi May 23, 2023
d0a81af
Incorporate Greg's small comments in intel-specific spec
dkhaldi May 23, 2023
cd41588
Rename folder name, add primary definition of matrix_params
dkhaldi May 25, 2023
0bf47c9
Add missing const to multi_ptr
dkhaldi May 25, 2023
15306d6
- Add copy function; - Add clarification about copy constructor and a…
dkhaldi May 30, 2023
bee344e
small typo correction
dkhaldi May 31, 2023
e5648e4
Remove default copy constructor and assign op
dkhaldi Jun 7, 2023
e22d057
fixed merge conflicts without merging and add Jack's Nvidia combinati…
dkhaldi Jun 8, 2023
0b4eecc
Remove the oneapi matrix folder that is replaced here by matrix folde…
dkhaldi Jun 8, 2023
8d80ad6
Add old folder to try to fix conflicts
dkhaldi Jun 9, 2023
1059870
Merge branch 'intel:sycl' into get-coord-doc
dkhaldi Jun 9, 2023
35c8744
remove the old folder that resulted from the merge with sycl branch
dkhaldi Jun 9, 2023
d63bdb8
address Greg's comments: change Nvidia table, minor formatting
dkhaldi Jun 29, 2023
7bfb8e5
corrected two types in the Nvidia table
dkhaldi Jun 29, 2023
08fd2db
address Greg, Jack, and Alexey comments
dkhaldi Jul 28, 2023
d7d0a70
Clarify use of must when referring to the query interface
dkhaldi Jul 31, 2023
bf8e00c
Address Greg's comments: fix 2 broken lines, const multi_ptr, line wrap
dkhaldi Aug 2, 2023
84af291
Add clarifications about joint_matrix_copy
dkhaldi Aug 2, 2023
2c2af7d
Add non const overload to tf32 load as implicit conversion for multi_…
dkhaldi Aug 7, 2023
e8bde89
minor clarification
dkhaldi Aug 9, 2023
a7f92ce
fix width of query table
dkhaldi Aug 23, 2023
789b593
fix the width for the right table
dkhaldi Aug 25, 2023
ee28250
Avoid line breaks in table by using source block
gmlueck Aug 25, 2023
2d80d16
add the conflicted file first in order to resolve the conflict
dkhaldi Aug 28, 2023
901252b
Merge branch 'intel:sycl' into get-coord-doc
dkhaldi Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
- Remove the general query from TODO list as an example is added to t…
…he llvm-test-suite

- Add get coord API and remove it from TODO list
- Remove the local memory future API looking as it is no more relevant
  • Loading branch information
dkhaldi committed Jan 9, 2023
commit 9628bd01b8ff255b8e3adef9e1f2d242dcef4fdb
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,54 @@ The table below provides a list of the combinations that `joint_matrix` implemen
| bf16 | bf16 | fp32 | +<=+ 8 | 16 | 16
|======================


## WI data to joint matrix mapping coordinates information for piece-wise operations
The indexing provided inside the `wi_data` class accesses only the portion of the matrix held by the current WI. It is not possible to know the location of this portion in the joint matrix. This coordinates mapping is implementation defined and changes from one backend to the other. For general piece-wise operations like sum of rows of a matrix, the WI data to joint matrix mapping information is needed to reason about the matrix view.
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
Within the joint matrix extension, we want to write, as much as possible, one code to run on different backends. If backend X states that a WI owns one exact row of the matrix for instance, writing the following code will work only on that backend for that version of hardware. If a different implementation is used, the same WI may own only half of the row if, for example, the SG size increased.
The following code locally calculates sum of rows of matrix `joint_matrix<sub_group, int8_t, use::a, 8, 8, layout::row_major> tA;`. In this example, we assume each WI owns 1 columns of `tA` and the sub-group size is 8. `data.length` returns 8 elements per WI.
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved

[frame="none",options="header"]
|======================
| a00 | a01 | a02 |a03 | a04 | a05|a06|a07|a08|a09|a010|a011|a012|a013|a014|a015
| a10 | a11 | a12 |a13 | a14 | a15|a16|a17|a18|a19|a110|a111|a112|a113|a114|a115
| a20 | a21 | a22 |a23 | a24 | a25|a26|a27|a28|a29|a210|a211|a212|a213|a214|a215
| a30 | a31 | a32 |a33 | a34 | a35|a36|a37|a38|a39|a310|a311|a312|a313|a314|a315
| a40 | a41 | a42 |a43 | a44 | a45|a46|a47|a48|a49|a410|a411|a412|a413|a414|a415
| a50 | a51 | a52 |a53 | a54 | a55|a56|a57|a58|a59|a510|a511|a512|a513|a514|a515
| a60 | a61 | a62 |a63 | a64 | a65|a66|a67|a68|a69|a610|a611|a612|a613|a614|a615
| a70 | a71 | a72 |a73 | a74 | a75|a76|a77|a78|a79|a710|a711|a712|a713|a714|a715
|======================


```c++
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
auto data = get_wi_data(sg, tA);
// each WI calculates local sum of rows
for (int row = 0; row < 8; row++) {
for (int i = 0; i < data.length()/8; ++i) {//WI owns 1 element per row
sum_of_local_rows[row] += data[i+row];
}
}
```
The code above assumes knowledge of the distribution of the joint matrix across the different work-items. This is different when a different distribution happens. In order to be agnostic to this distribution, instead of hard-coding this mapping, we use general backend and target-agnostic functionality. To this end, a new method is added to 'wi_element' to query this mapping.
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved

```c++
namespace sycl::ext::intel::experimental::matrix {
std::tuple<uint32_t, uint32_t> get_coord();
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
}
```

`get_coord` returns [row,col] coordinates of the current object `wi_element` of the joint matrix. The code above results into the following:


dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
```c++
auto data = get_wi_data(sg, tA);
// each WI calculates local sum of rows
for (int i = 0; i < data.length(); ++i) {
auto [row, col] = data[i].get_coord();
sum_of_local_rows[row] += data[i];
}
```


dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
## Open Questions
- Should the same class, `joint_matrix`, handle both cases where sizes are constant (GPU case) and when sizes are variable (CPU case)? Note that a Intel AMX 2d tile register permits sizes up to 1024 (16rowsx64cols) bytes that can be variable. The ability to define only one interface for both would make it possible to give the user a way to make use of the flexibility introduced by the CPU but at the same time save resources on the GPU. In a previous version of the design, we used `sycl::dynamic_extent` to differentiate between static and dynamic sizes. But since this was not implemented at all, we decided to remove it. We can revisit this design choice if this comes up as part of a customer request or if SPIRV matrix extension extends its support to dynamic sizes.
Original file line number Diff line number Diff line change
Expand Up @@ -546,43 +546,6 @@ joint_matrix<sub_group, int, use::accumulator, msize, nsize> sub_c;
//Remainder handling
gmlueck marked this conversation as resolved.
Show resolved Hide resolved
```

## Future-looking API

### Memory scope
The current experimental API uses `joint_` semantics to define the memory scope of the matrix. The long term solution is to use the proposed link:../supported/sycl_ext_oneapi_local_memory.asciidoc[`group_local_memory` extension] to allocate the matrix in local memory associated with a SYCL group as shown in the example below.


```c++
multi_ptr<matrix<T>, address_space::local_space> tA_ptr = group_local_memory<matrix<sub_group, int8_t, tM, tN, use::a>>(sg);
```
We did not utilize this extension for this matrix API version because sub-group local memory is not yet well defined in {dpcpp}. Moreover, the representation of this notion in LLVM IR and SPIR-V is not clear yet.

### WI data to joint matrix mapping coordinates information for piece-wise operations
The indexing provided inside the `wi_data` class accesses only the portion of the matrix held by the current WI. It is not possible to know the location of this portion in the original matrix. This coordinates mapping is implementation defined and changes from one backend to the other. For general piece-wise operations like sum of rows of a matrix, the WI data to joint matrix mapping information is needed to reason about the matrix view.
Within the joint matrix extension, we want to write, as much as possible, one code to run on different backends. If backend X states that a WI owns one exact row of the matrix for instance, writing the following code will work only on that backend for that version of hardware. If a different hardware and implementation is used, the same WI may own only half of the row if, for example, the SG size increased.

```c++
auto data = get_wi_data(sg, C);
for (int i = 0; i < data.length(); ++i) {
sum_of_local_rows[row] += data[i];
}
```

We want to keep backward compatibility in the joint matrix code when implementations or hardware change. To that end, instead of hard-coding this mapping, we use general backend and target-agnostic functionality, especially in the JIT compilation mode of SYCL. For this reason we would like to be able to query this mapping so that code does not have to change from one version to the other.

So for the mapping problem, since this mapping is implementation-defined, one of the proposals is to add runtime functions like:
```c++
auto data = get_wi_data(sg, C);
for (int i = 0; i < data.length; ++i) {
auto row, col = data[i].get_coord();
sum_of_local_rows[row] += data[i];
}
```

## TODO List
- Add WI data to joint matrix mapping coordinates information for piece-wise operations. This will be added as part of the query or new methods to the 'get_wi_data' class.
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved
- Add a more realistic and complete example that shows the value of the general query.
dkhaldi marked this conversation as resolved.
Show resolved Hide resolved


## Revision History

Expand Down