├── src ├── Makefile ├── License.txt └── test-amxtile.c ├── README.md ├── CONTRIBUTING.md └── CODE_OF_CONDUCT.md /src/Makefile: -------------------------------------------------------------------------------- 1 | CFLAG = -O2 -march=native -fno-strict-aliasing 2 | CC = gcc 3 | BIN = test-amxtile 4 | CFILES =test-amxtile.c 5 | 6 | all: 7 | $(CC) $(CFLAG) $(CFILES) -o $(BIN) $(LIBS) 8 | 9 | clean: 10 | -rm $(BIN) 11 | 12 | .PHONY: clean 13 | 14 | -------------------------------------------------------------------------------- /src/License.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 Intel Corporation 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DISCONTINUATION OF PROJECT # 2 | This project will no longer be maintained by Intel. 3 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 4 | Intel no longer accepts patches to this project. 5 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 6 | 7 | # AMX-TMUL-Code-Samples-Intel 8 | Code sample showing Intel® Advanced Matrix Extensions (Intel® AMX) functionality on Intel® Xeon® Scalable processor Max Series and 4th gen Intel® Xeon® Scalable processors. 9 | 10 | Intel® AMX now introduces new extensions to the x86 Instruction Set Architecture (ISA) to work on matrices and which may accelerate matrix multiplication in AI workloads. It consists of two components: 11 | 12 | 1. A set of 2-dimensional registers (tiles), which can hold sub-matrices from larger matrices in memory. 13 | 2. An accelerator called Tile Matrix Multiply (TMUL) which contains instructions that operate on tiles. 14 | 15 | This code sample demonstrates testing the new instructions using intrinsic functions. 16 | 17 | A code walk-through for this sample can be found at: 18 | https://www.intel.com/content/www/us/en/developer/articles/code-sample/advanced-matrix-extensions-intrinsics-functions.html 19 | 20 | 21 | ## Purpose 22 | 23 | The code sample will multiply matrices A and B of size 16 x 64 containing INT8 values, and accumulate the result to a 16 x 16 matrix C containing INT32 values. 24 | 25 | This code sample is simplified to highlight use of new Intel(R) AMX instructions. It shows use of instructions to configure the tiles, load data from memory into tiles, perform one matrix multiplication on tiles data and copy the result from tiles to memory. It should not be used as a basis for production code. Only for demostration purposes. 26 | 27 | ## License 28 | 29 | This code sample is licensed under MIT license. 30 | 31 | ## Building the `test-amxtile` executable 32 | 33 | ### On a Linux* System 34 | Perform the following steps: 35 | 1. Build the program. 36 | 37 | ``` 38 | cd src/ 39 | make 40 | ``` 41 | 42 | 2. Run the program 43 | 44 | ``` 45 | ./test-amxtile 46 | ``` 47 | 48 | 3. Clean the program 49 | 50 | ``` 51 | make clean 52 | ``` 53 | 54 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ### License 4 | 5 | is licensed under the terms in [LICENSE]. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. 6 | 7 | ### Sign your work 8 | 9 | Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify 10 | the below (from [developercertificate.org](http://developercertificate.org/)): 11 | 12 | ``` 13 | Developer Certificate of Origin 14 | Version 1.1 15 | 16 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 17 | 660 York Street, Suite 102, 18 | San Francisco, CA 94110 USA 19 | 20 | Everyone is permitted to copy and distribute verbatim copies of this 21 | license document, but changing it is not allowed. 22 | 23 | Developer's Certificate of Origin 1.1 24 | 25 | By making a contribution to this project, I certify that: 26 | 27 | (a) The contribution was created in whole or in part by me and I 28 | have the right to submit it under the open source license 29 | indicated in the file; or 30 | 31 | (b) The contribution is based upon previous work that, to the best 32 | of my knowledge, is covered under an appropriate open source 33 | license and I have the right under that license to submit that 34 | work with modifications, whether created in whole or in part 35 | by me, under the same open source license (unless I am 36 | permitted to submit under a different license), as indicated 37 | in the file; or 38 | 39 | (c) The contribution was provided directly to me by some other 40 | person who certified (a), (b) or (c) and I have not modified 41 | it. 42 | 43 | (d) I understand and agree that this project and the contribution 44 | are public and that a record of the contribution (including all 45 | personal information I submit with it, including my sign-off) is 46 | maintained indefinitely and may be redistributed consistent with 47 | this project or the open source license(s) involved. 48 | ``` 49 | 50 | Then you just add a line to every git commit message: 51 | 52 | Signed-off-by: Joe Smith 53 | 54 | Use your real name (sorry, no pseudonyms or anonymous contributions.) 55 | 56 | If you set your `user.name` and `user.email` git configs, you can sign your 57 | commit automatically with `git commit -s`. 58 | -------------------------------------------------------------------------------- /src/test-amxtile.c: -------------------------------------------------------------------------------- 1 | //============================================================== 2 | // Copyright © 2022 Intel Corporation 3 | // 4 | // SPDX-License-Identifier: MIT 5 | // ============================================================= 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define MAX 1024 15 | #define MAX_ROWS 16 16 | #define MAX_COLS 64 17 | #define STRIDE 64 18 | #define ARCH_GET_XCOMP_PERM 0x1022 19 | #define ARCH_REQ_XCOMP_PERM 0x1023 20 | #define XFEATURE_XTILECFG 17 21 | #define XFEATURE_XTILEDATA 18 22 | 23 | //Define tile config data structure 24 | typedef struct __tile_config 25 | { 26 | uint8_t palette_id; 27 | uint8_t start_row; 28 | uint8_t reserved_0[14]; 29 | uint16_t colsb[16]; 30 | uint8_t rows[16]; 31 | } __tilecfg; 32 | 33 | /* Initialize tile config */ 34 | static void init_tile_config (__tilecfg *tileinfo) 35 | { 36 | int i; 37 | tileinfo->palette_id = 1; 38 | tileinfo->start_row = 0; 39 | 40 | for (i = 0; i < 1; ++i) 41 | { 42 | tileinfo->colsb[i] = MAX_ROWS; 43 | tileinfo->rows[i] = MAX_ROWS; 44 | } 45 | 46 | for (i = 1; i < 4; ++i) 47 | { 48 | tileinfo->colsb[i] = MAX_COLS; 49 | tileinfo->rows[i] = MAX_ROWS; 50 | } 51 | 52 | _tile_loadconfig (tileinfo); 53 | } 54 | 55 | /* Initialize int8_t buffer */ 56 | static void init_buffer (int8_t *buf, int8_t value) 57 | { 58 | int rows, colsb, i, j; 59 | rows = MAX_ROWS; 60 | colsb = MAX_COLS; 61 | 62 | for (i = 0; i < rows; i++) 63 | for (j = 0; j < colsb; j++) 64 | { 65 | buf[i * colsb + j] = value; 66 | } 67 | } 68 | 69 | /* Initialize int32_t buffer */ 70 | static void init_buffer32 (int32_t *buf, int32_t value) 71 | { 72 | int rows, colsb, i, j; 73 | rows = MAX_ROWS; 74 | colsb = MAX_COLS; 75 | int colsb2=colsb/4; 76 | 77 | for (i = 0; i < rows; i++) 78 | for (j = 0; j < (colsb2); j++) 79 | { 80 | buf[i * colsb2 + j] = value; 81 | } 82 | } 83 | 84 | /* Set_tiledata_use() - Invoke syscall to set ARCH_SET_STATE_USE */ 85 | static bool set_tiledata_use() 86 | { 87 | if (syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA)) 88 | { 89 | printf("\n Fail to do XFEATURE_XTILEDATA \n\n"); 90 | return false; 91 | } 92 | else 93 | { 94 | printf("\n TILE DATA USE SET - OK \n\n"); 95 | return true; 96 | } 97 | 98 | return true; 99 | } 100 | 101 | /* Print int8_t buffer */ 102 | static void print_buffer(int8_t* buf, int32_t rows, int32_t colsb) 103 | { 104 | for (int i = 0; i < rows; i++) { 105 | for (int j = 0; j < (colsb); j++) 106 | { 107 | printf("%d ", buf[i * colsb + j]); 108 | } 109 | printf("\n"); 110 | } 111 | printf("\n"); 112 | } 113 | 114 | /* Print int32_t buffer */ 115 | static void print_buffer32(int32_t* buf, int32_t rows, int32_t colsb) 116 | { 117 | for (int i = 0; i < rows; i++) { 118 | for (int j = 0; j < (colsb); j++) 119 | { 120 | printf("%d ", buf[i * colsb + j]); 121 | } 122 | printf("\n"); 123 | } 124 | printf("\n"); 125 | } 126 | 127 | int main(){ 128 | 129 | __tilecfg tile_data = {0}; 130 | int8_t src1[MAX]; 131 | int8_t src2[MAX]; 132 | int32_t res[MAX/4]; 133 | int rows = MAX_ROWS; 134 | int colsb = MAX_COLS; 135 | 136 | // Request permission to linux kernel to run AMX 137 | if (!set_tiledata_use()) 138 | exit(-1); 139 | 140 | // Load tile configuration 141 | init_tile_config (&tile_data); 142 | 143 | // Init src matrix buffers with data 144 | init_buffer (src1, 2); 145 | print_buffer(src1, rows, colsb); 146 | 147 | init_buffer (src2, 2); 148 | print_buffer(src2, rows, colsb); 149 | 150 | // Init dst matrix buffers with data 151 | init_buffer32 (res, 0); 152 | 153 | // Load tile rows from memory 154 | _tile_loadd (2, src1, STRIDE); 155 | _tile_loadd (3, src2, STRIDE); 156 | _tile_loadd (1, res, STRIDE); 157 | 158 | // Compute dot-product of bytes in tiles 159 | _tile_dpbssd (1, 2, 3); 160 | 161 | // Store the tile data to memory 162 | _tile_stored (1, res, STRIDE); 163 | print_buffer32(res, rows, colsb/4); 164 | 165 | // Release the tile configuration to return to the init state, 166 | // which releases all storage it currently holds 167 | _tile_release (); 168 | } 169 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, caste, color, religion, or sexual 10 | identity and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or advances of 31 | any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email address, 35 | without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | CommunityCodeOfConduct AT intel DOT com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series of 86 | actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or permanent 93 | ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within the 113 | community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.1, available at 119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 120 | 121 | Community Impact Guidelines were inspired by 122 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 123 | 124 | For answers to common questions about this code of conduct, see the FAQ at 125 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 126 | [https://www.contributor-covenant.org/translations][translations]. 127 | 128 | [homepage]: https://www.contributor-covenant.org 129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 130 | [Mozilla CoC]: https://github.com/mozilla/diversity 131 | [FAQ]: https://www.contributor-covenant.org/faq 132 | --------------------------------------------------------------------------------