From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QTOvBQmF5Go2mRMAWB0awg (envelope-from ) for ; Fri, 30 Oct 2026 07:52:41 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IBEc6JJ4; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 11306378002; Fri, 30 Oct 2026 07:52:41 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 19B9C1E023 for ; Fri, 30 Oct 2026 07:52:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 360C74BA23D9 for ; Fri, 30 Oct 2026 11:52:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 360C74BA23D9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IBEc6JJ4 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by sourceware.org (Postfix) with ESMTPS id 6C7524BA9029 for ; Fri, 30 Oct 2026 11:51:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C7524BA9029 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C7524BA9029 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793361066; cv=none; b=kY093TuRB+QJXKzMCL5SJH8AmvhIgpZ4qBB0q2Otews0uuRMGXatkE1Bjkr9BV2xsO1q2UlMnwFi8apNJpikgR1AyT1AseXkG9PAbk0NgSw4X9vfUFb/rFEGmypagrNsbO2pEpQ3MUqGEF8OWhcO/8TKsFqps7QSY5vePvDAuhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793361066; c=relaxed/simple; bh=UbM8QgaeH0dvV2nVWdHSsvkCm8KR5akEyEsrdpHqYkY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ph0wgdY4YczOyd8QoW/ua3AT/simmU8Zx8/78AN0ugD0dWDJkwmuhCXXd0NQOIU+2l3v9nIgDHL/voxl+7VxC7TC5+fPgo7WCzrLJGMKPU6YtmOCgwJJ4mcHaOgOjjKGq/z+rLc59hoT5BvRfPi4Doplz34na6U3eM39T1cPseY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=IBEc6JJ4 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C7524BA9029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793361066; x=1824897066; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UbM8QgaeH0dvV2nVWdHSsvkCm8KR5akEyEsrdpHqYkY=; b=IBEc6JJ4Wfl5h5Zq698u41J+0O/J5vaVGqLnIhxv/LAOdajnXVanbU2J cs2tcTkUnaiD8X93f8yXugEbx9IfTQDzSV5toIgq41uBc5aZDOCNLl5nB /KA5U2eDG1vQYiJ48t8lUlM7yxi969V0x2FJM98F/dv2MfueXeZLomWAs GsM1wD/dghuZdmOHXnDAH2q50E/fSbsw0HV6NvE3ncSJlDPMdLIdXsI/0 AskI36g8FCUVHghp44Ln5epEXdcYgkmff6spIDGEqT1fXYqwHBwvzQxIQ dLpMHR3EjZzr6TVXmder0BXVk4po8EJBD+Vj1Q1AGjKMeuuufJDLEe5tI g==; X-CSE-ConnectionGUID: IsxZn039RfqpWOqXS9E25w== X-CSE-MsgGUID: Sng6jxhMRv2s2xy6Jbj7Ag== X-IronPort-AV: E=McAfee;i="6800,10657,11950"; a="2114109" X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="2114109" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 04:51:06 -0700 X-CSE-ConnectionGUID: LwWCKPO3Qji6Lo+mqPzknQ== X-CSE-MsgGUID: cTzGoKBvTpeHaXAbfLQfDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,186,1787036400"; d="scan'208";a="5503095" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2026 04:51:05 -0700 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: pedro@palves.net, eliz@gnu.org, jhb@FreeBSD.org, luis.machado@arm.com Subject: [PATCH v2 5/5] gdb: add Intel AMX tile registers as user registers Date: Fri, 30 Oct 2026 11:50:16 +0000 Message-ID: <20261030115016.45786-6-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261030115016.45786-1-stephan.rohr@intel.com> References: <20261030115016.45786-1-stephan.rohr@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: "Rohr, Stephan" Add the user registers $tmm0 ... $tmm7 for the raw tile registers $tmm0_raw ... $tmm7_raw. The type of a user register is resolved at runtime from the dimensions configured in TILECFG. The user registers are implemented by applying a view type on the raw tile register. The rows of the view have fixed stride. Reading and writing an element through the view accesses the same bytes in the raw tile register. The user registers are part of the "matrix" and "all" register groups, so that "info registers matrix" and "info all-registers" list them. The tilecfg pseudo register is part of the "matrix" register group as well. Remote targets are naturally supported as reading and writing goes through the raw tile registers. --- gdb/NEWS | 2 + gdb/amd64-tdep.c | 83 ++++++++++++ gdb/doc/gdb.texinfo | 13 +- gdb/i386-tdep.c | 98 +++++++++++++++ gdb/i386-tdep.h | 81 ++++++++++++ gdb/testsuite/gdb.arch/amd64-amx.c | 9 ++ gdb/testsuite/gdb.arch/amd64-amx.exp | 182 +++++++++++++++++++++++++-- 7 files changed, 458 insertions(+), 10 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 47ecba246a0..1c60f307d53 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -11,6 +11,8 @@ Support displaying and modifying Intel AMX raw registers $tmm0_raw - $tmm7_raw and the $tilecfg_raw register. The $tilecfg pseudo register provides a parsed view of the tile configuration. + The $tmm0 - $tmm7 user registers display the raw tile registers according + to the configuration in $tilecfg. * GDB now distinguishes between the GNU (MinGW) and MSVC Windows ABIs. diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index 13242e293b5..6d421c85080 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -34,8 +34,10 @@ #include "gdbcore.h" #include "objfiles.h" #include "regcache.h" +#include "reggroups.h" #include "regset.h" #include "symfile.h" +#include "user-regs.h" #include "disasm.h" #include "amd64-tdep.h" #include "i387-tdep.h" @@ -199,6 +201,25 @@ static const char *amd64_tmm_raw_names[] = { "tmm4_raw", "tmm5_raw", "tmm6_raw", "tmm7_raw" }; +/* Register names for the tmm user registers. */ + +static const char *amd64_tmm_user_names[] = { + "tmm0", "tmm1", "tmm2", "tmm3", + "tmm4", "tmm5", "tmm6", "tmm7" +}; + +/* Batons for the tmm user registers. */ + +static const int amd64_tmm_user_batons[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + +/* Register groups for the tmm user registers. */ + +static const reggroup *const amd64_tmm_groups[] = { + matrix_reggroup, + all_reggroup +}; + + /* DWARF Register Number Mapping as defined in the System V psABI, section 3.6. */ @@ -632,6 +653,62 @@ amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch, + +/* Read ROWS and COLSB from TILECFG for tile TMMNUM. Return the maximum number + of rows and the maximum number of bytes respectively for an unconfigured + tile. */ + +static void +amd64_tmm_dimensions (const tilecfg_reg &tilecfg, int tmmnum, uint8_t *rows, + uint16_t *colsb) +{ + *rows = tilecfg.rows (tmmnum); + *colsb = tilecfg.bytes_per_row (tmmnum); + + if (*rows == 0) + *rows = tilecfg_reg::MAX_ROWS; + if (*colsb == 0) + *colsb = tilecfg_reg::MAX_BYTES_PER_ROW; +} + +/* Return the tile configuration for NEXT_FRAME. */ + +static tilecfg_reg +amd64_read_tilecfg (const frame_info_ptr &next_frame) +{ + gdbarch *gdbarch = frame_unwind_arch (next_frame); + i386_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + value *tilecfg_raw_val = value_of_register (tdep->tilecfg_raw_regnum, + next_frame); + + return tilecfg_reg (tilecfg_raw_val->contents ()); +} + +/* Read a tmm user register with dynamic resolution of the configured + dimensions. BATON is the tile number. */ + +static value * +amd64_value_of_tmm_user_reg (const frame_info_ptr &frame, const void *baton) +{ + gdbarch *gdbarch = get_frame_arch (frame); + i386_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + frame_info_ptr next_frame = get_next_frame_sentinel_okay (frame); + int tmmnum = *(const int *) baton; + + /* Read the register's dimensions from tilecfg. */ + tilecfg_reg tilecfg = amd64_read_tilecfg (next_frame); + uint8_t rows; + uint16_t colsb; + amd64_tmm_dimensions (tilecfg, tmmnum, &rows, &colsb); + + /* "i386_tmm_type" builds a union with one view per element type, e.g., + "int8" and "uint8". The rows have a fixed stride such that elements are + at the same offsets as in the raw register. */ + return value::allocate_register_lazy (next_frame, + tdep->tmm_raw_regnum + tmmnum, + i386_tmm_type (gdbarch, rows, colsb)); +} + /* Register classes as defined in the psABI. */ enum amd64_reg_class @@ -3863,6 +3940,12 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, amd64_in_indirect_branch_thunk); register_amd64_ravenscar_ops (gdbarch); + + /* Add tile registers tmm0 to tmm7 as user registers. */ + for (int i = 0; i < tdep->num_tmm_raw_regs; i++) + user_reg_add (gdbarch, amd64_tmm_user_names[i], + amd64_value_of_tmm_user_reg, &amd64_tmm_user_batons[i], + amd64_tmm_groups); } /* Initialize ARCH for x86-64, no osabi. */ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index ba9d3df1ac5..15b351e8c02 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -27466,7 +27466,11 @@ omitting reserved bits. The tile registers are supplied as the raw registers contents of a tile with its maximum dimensions of @w{16 rows} of @w{64 bytes}. The raw tile registers hold one @code{uint512} per row and only the elements within the dimensions configured in @samp{tilecfg} hold data. -For example: +Additional user registers @samp{tmm0}, @samp{tmm1}, @dots{}, @samp{tmm7} +present the raw registers with the dimensions configured in +@samp{tilecfg}. They are part of the @code{matrix} and @code{all} +register groups, so that @code{info registers matrix} and @code{info +all-registers} list them. For example: @smallexample (gdb) print/x $tilecfg_raw @@ -27482,8 +27486,15 @@ $3 = @{621397352980713455329738752, 932096029507240269422067969, $4 = @{@{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0 @}, @{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0 @}, @{0 @} @} +(gdb) print $tmm1.m_int8 +$5 = @{@{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2@}, + @{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3@}@} @end smallexample +In this example, @code{$tmm1.m_int8} shows the tile as signed 8-bit +integers with the dimensions configured in @samp{tilecfg} for +@samp{tmm1}: 2 rows (@code{rows}) of 12 bytes (@code{colsb}). + @node Alpha @subsection Alpha diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index a25abfbd1bc..21d4bf6f4a9 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -47,6 +47,7 @@ #include "i386-tdep.h" #include "i387-tdep.h" #include "gdbsupport/x86-xstate.h" +#include "gdbsupport/array-view.h" #include "x86-tdep.h" #include "expop.h" @@ -447,6 +448,22 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum) internal_error (_("invalid regnum")); } +/* AMX tilecfg_reg constructor. */ + +tilecfg_reg::tilecfg_reg (gdb::array_view raw_tilecfg) +{ + gdb_assert (raw_tilecfg.size () == X86_AMX_TILECFG_SIZE); + + /* Read the TILECFG column and row values. */ + for (int i = 0; i < NUM_TILES; i++) + { + const int offset = COLUMN_OFFSET + i * 2; + uint16_t colsb = extract_unsigned_integer (raw_tilecfg.slice (offset, 2), + BFD_ENDIAN_LITTLE); + m_tiles[i] = { colsb, raw_tilecfg[ROW_OFFSET + i] }; + } +} + /* Convert SVR4 DWARF register number REG to the appropriate register number used by GDB. */ @@ -3250,6 +3267,84 @@ i386_mmx_type (struct gdbarch *gdbarch) return tdep->i386_mmx_type; } +/* Return a view of a tile with ROWS rows of COLS elements of type ELT_TYPE. + The rows have a fixed stride of TILECFG_REG::MAX_BYTES_PER_ROW. */ + +static type * +i386_tmm_view_type (gdbarch *gdbarch, type *elt_type, int cols, int rows) +{ + type *row_type = init_vector_type (elt_type, cols); + + type_allocator alloc (gdbarch); + type *range_type + = create_static_range_type (alloc, builtin_type (gdbarch)->builtin_int, + 0, rows - 1); + dynamic_prop stride; + stride.set_const_val (tilecfg_reg::MAX_BYTES_PER_ROW); + + type *t = create_array_type_with_stride (alloc, row_type, range_type, + &stride, true); + t->set_is_vector (true); + return t; +} + +/* See i386-tdep.h. */ + +type * +i386_tmm_type (gdbarch *gdbarch, uint8_t rows, uint16_t colsb) +{ + i386_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + gdb_assert (rows > 0 && rows <= tilecfg_reg::MAX_ROWS); + gdb_assert (colsb > 0 && colsb <= tilecfg_reg::MAX_BYTES_PER_ROW); + + /* Cache the tmm type based on the configured dimension. */ + uint32_t key = ((uint32_t) rows << 16) | colsb; + auto it = tdep->i386_tmm_types.find (key); + if (it != tdep->i386_tmm_types.end ()) + return it->second; + + const struct builtin_type *bt = builtin_type (gdbarch); + + /* The type we're building is this: + + union __gdb_builtin_type_matrix1024i + { + int8_t m_int8[rows][colsb]; + uint8_t m_uint8[rows][colsb]; + int32_t m_int32[rows][colsb / 4]; + bfloat16_t m_bf16[rows][colsb / 2]; + float m_fp32[rows][colsb / 4]; + }; */ + + type *t = arch_composite_type (gdbarch, "builtin_type_tile", TYPE_CODE_UNION); + + append_composite_type_field + (t, "m_int8", + i386_tmm_view_type (gdbarch, bt->builtin_int8, colsb, rows)); + + append_composite_type_field + (t, "m_uint8", + i386_tmm_view_type (gdbarch, bt->builtin_uint8, colsb, rows)); + + append_composite_type_field + (t, "m_int32", + i386_tmm_view_type (gdbarch, bt->builtin_int32, colsb / 4, rows)); + + append_composite_type_field + (t, "m_bf16", + i386_tmm_view_type (gdbarch, bt->builtin_bfloat16, colsb / 2, rows)); + + append_composite_type_field + (t, "m_fp32", + i386_tmm_view_type (gdbarch, bt->builtin_float, colsb / 4, rows)); + + t->set_is_vector (true); + t->set_name ("builtin_type_tile"); + tdep->i386_tmm_types.emplace (key, t); + + return t; +} + /* The type of the TILECFG registers. */ static type * @@ -4372,6 +4467,9 @@ i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum, tilecfg_regnum_p = i386_tilecfg_regnum_p (gdbarch, regnum); tilecfg_raw_regnum_p = i386_tilecfg_raw_regnum_p (gdbarch, regnum); + if (group == matrix_reggroup) + return tilecfg_regnum_p; + avx512_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK) == X86_XSTATE_AVX_AVX512_MASK); avx_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK) diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h index 898a76dfb50..e9393580194 100644 --- a/gdb/i386-tdep.h +++ b/gdb/i386-tdep.h @@ -23,6 +23,7 @@ #include "gdbarch.h" #include "infrun.h" #include "expression.h" +#include "gdbsupport/unordered_map.h" #include "gdbsupport/x86-xstate.h" class frame_info_ptr; @@ -287,6 +288,9 @@ struct i386_gdbarch_tdep : gdbarch_tdep_base struct type *i387_ext_type = nullptr; type *i386_tilecfg_type = nullptr; + /* Type cache for tile user registers. */ + gdb::unordered_map i386_tmm_types; + /* If the registers containing the i386 Linux TLS related global descriptor table information are available. This is used to decide whether to add the NT_386_TLS note to the core file or not. */ @@ -437,6 +441,12 @@ extern void i386_ax_pseudo_register_collect (struct gdbarch *gdbarch, struct agent_expr *ax, int regnum); +/* Return the type of an Intel AMX tile that is configured to hold ROWS rows + of COLSB bytes each. */ + +extern type *i386_tmm_type (gdbarch *gdbarch, uint8_t rows, + uint16_t colsb); + /* Segment selectors. */ #define I386_SEL_RPL 0x0003 /* Requester's Privilege Level mask. */ #define I386_SEL_UPL 0x0003 /* User Privilege Level. */ @@ -536,4 +546,75 @@ extern bool i386_stap_is_single_operand (struct gdbarch *gdbarch, extern expr::operation_up i386_stap_parse_special_token (struct gdbarch *gdbarch, struct stap_parse_info *p); +/* TILECFG register. + 0 palette + 1 start_row + 2-15 reserved, must be zero + 16-17 tile0.colsb Tile 0 bytes per row. + 18-19 tile1.colsb Tile 1 bytes per row. + 20-21 tile2.colsb Tile 2 bytes per row. + ... (sequence continues) + 30-31 tile7.colsb Tile 7 bytes per row. + 32-47 reserved, must be zero + 48 tile0.rows Tile 0 rows. + 49 tile1.rows Tile 1 rows. + 50 tile2.rows Tile 2 rows. + ... (sequence continues) + 55 tile7.rows Tile 7 rows. + 56-63 reserved, must be zero. */ + +class tilecfg_reg +{ +public: + /* Construct it from raw tilecfg data. */ + explicit tilecfg_reg (gdb::array_view raw_tilecfg); + + /* Get number of configured bytes per row for tile P. */ + inline uint16_t + bytes_per_row (uint8_t p) const + { + gdb_assert (p < NUM_TILES); + return m_tiles[p].colsb; + } + + /* Get number of configured rows for tile P. */ + inline uint8_t + rows (uint8_t p) const + { + gdb_assert (p < NUM_TILES); + return m_tiles[p].rows; + } + + /* Maximum possible values for the current target. */ + static const uint16_t MAX_ROWS = 16; + static const uint16_t MAX_BYTES_PER_ROW = 64; + +private: + /* Offsets of the colsb and rows arrays. */ + static const uint16_t COLUMN_OFFSET = 16; + static const uint16_t ROW_OFFSET = 48; + + /* Size of the tiles. */ + static const uint16_t NUM_TILES = X86_AMX_NUM_TMM_REGISTERS; + + /* The configuration of a single tile. */ + struct tile + { + /* Number of configured bytes per row. */ + uint16_t colsb = 0; + + /* Number of configured rows. */ + uint8_t rows = 0; + + bool + operator== (const tile &t) const + { + return colsb == t.colsb && rows == t.rows; + } + }; + + /* The configuration of each tile. */ + std::array m_tiles {}; +}; + #endif /* GDB_I386_TDEP_H */ diff --git a/gdb/testsuite/gdb.arch/amd64-amx.c b/gdb/testsuite/gdb.arch/amd64-amx.c index 5dca29ad183..8233ada65b5 100644 --- a/gdb/testsuite/gdb.arch/amd64-amx.c +++ b/gdb/testsuite/gdb.arch/amd64-amx.c @@ -47,6 +47,12 @@ int8_t int8_matrix[2][8] = { { -1, -1, -1, -1, 1, 1, 1, 1 }, float fp32_matrix[2][2] = { { 1.0, 1.125 }, { 1.25, 1.375 } }; +/* The bfloat16 values 0, 0.125, 0.25, 0.375 and 0.5, 0.625, 0.75, 0.875. + We use encoded bf16 values to avoid a dependency on compilers supporting + Intel AMX but not the __bf16 data type. */ +uint16_t bf16_matrix[2][4] = { { 0x0000, 0x3e00, 0x3e80, 0x3ec0 }, + { 0x3f00, 0x3f20, 0x3f40, 0x3f60 } }; + static void tfmaps_calc (void) @@ -79,6 +85,8 @@ tfmaps_calc (void) tc.cols[C] = M * 4; /* Tiles for testing the remaining element types. */ + tc.rows[3] = 2; + tc.cols[3] = 8; tc.rows[4] = 2; tc.cols[4] = 8; tc.rows[5] = 2; @@ -87,6 +95,7 @@ tfmaps_calc (void) _tile_loadconfig (&tc); /* Load additional types for type testing. */ + _tile_loadd (3, bf16_matrix, 4 * 2); _tile_loadd (4, fp32_matrix, 2 * 4); _tile_loadd (5, int8_matrix, 4 * 2); diff --git a/gdb/testsuite/gdb.arch/amd64-amx.exp b/gdb/testsuite/gdb.arch/amd64-amx.exp index af92e2d37a0..1974160abb6 100644 --- a/gdb/testsuite/gdb.arch/amd64-amx.exp +++ b/gdb/testsuite/gdb.arch/amd64-amx.exp @@ -38,12 +38,12 @@ proc test_zeroed_tile {reg} { proc test_loaded_tiles {} { gdb_test "print/x \$tilecfg_raw" \ - [join {"= 0x20200020302000000000000000000000000000000000" \ - "000000000080008000000100010000c00000000000000000000000000000001"} ""] + [join {"= 0x20202020302000000000000000000000000000000000" \ + "000000000080008000800100010000c00000000000000000000000000000001"} ""] gdb_test "print \$tilecfg" \ [string_to_regexp "= {palette = 1, start_row = 0,\ - colsb = {12, 16, 16, 0, 8, 8, 0, 0}, rows = {2, 3, 2, 0, 2, 2, 0, 0}}"] + colsb = {12, 16, 16, 8, 8, 8, 0, 0}, rows = {2, 3, 2, 2, 2, 2, 0, 0}}"] gdb_test "print/d (uint8_t\[16\]\[64\]) \$tmm0_raw" \ [join {"= \\{\\{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\ @@ -52,6 +52,11 @@ proc test_loaded_tiles {} { "\\{0 \\} \\}"} \ ", "] + gdb_test "print \$tmm0.m_uint8" \ + [join {"= \\{\\{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2\\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3\\}\\}"} \ + ", "] + gdb_test "print/d (uint8_t\[16\]\[64\]) \$tmm1_raw" \ [join {"= \\{\\{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,\ 0 \\}" \ @@ -62,26 +67,48 @@ proc test_loaded_tiles {} { "\\{0 \\} \\}"} \ ", "] + gdb_test "print \$tmm1.m_uint8" \ + [join {"= \\{\\{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3\\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4\\}" \ + "\\{2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5\\}\\}"} \ + ", "] + gdb_test "print (int\[16\]\[16\]) \$tmm2_raw" \ [join {"= \\{\\{20, 32, 44, 56, 0 \\}" \ "\\{32, 56, 80, 104, 0 \\}" \ "\\{0 \\} \\}"} \ ", "] + gdb_test "print \$tmm2.m_int32" \ + "= \\{\\{20, 32, 44, 56\\}, \\{32, 56, 80, 104\\}\\}" + + gdb_test "print \$tmm3.m_bf16" \ + [join {"= \\{\\{0, 0.125, 0.25, 0.375\\}" \ + "\\{0.5, 0.625, 0.75, 0.875\\}\\}"} \ + ", "] + gdb_test "print (float\[16\]\[16\]) \$tmm4_raw" \ [join {"= \\{\\{1, 1.125, 0 \\}" \ "\\{1.25, 1.375, 0 \\}" \ "\\{0 \\} \\}"} \ ", "] + gdb_test "print \$tmm4.m_fp32" "= \\{\\{1, 1.125\\}, \\{1.25, 1.375\\}\\}" + gdb_test "print/d (int8_t\[16\]\[64\]) \$tmm5_raw" \ [join {"= \\{\\{-1, -1, -1, -1, 1, 1, 1, 1, 0 \\}" \ "\\{1, 1, 1, 1, -5, -5, -5, -5, 0 \\}" \ "\\{0 \\} \\}"} \ ", "] - foreach i {3 6 7} { + gdb_test "print \$tmm5.m_int8" \ + [join {"= \\{\\{-1, -1, -1, -1, 1, 1, 1, 1\\}" \ + "\\{1, 1, 1, 1, -5, -5, -5, -5\\}\\}"} \ + ", "] + + for {set i 6} {$i < 8} {incr i} { test_zeroed_tile "\$tmm${i}_raw" + test_zeroed_tile "\$tmm${i}" } } @@ -119,28 +146,126 @@ with_test_prefix "read tiles" { set gcorefile $binfile.gcore set gcore_generated [gdb_gcore_cmd $gcorefile "save a core file"] -# Test setting tiles. +# Test setting tiles. The raw registers and the user registers both map to +# the same tile data. A write to one of them must be reflected in the other +# one. with_test_prefix "setting tiles" { + # Write to a raw register. gdb_test_no_output "set ((uint8_t\[16\]\[64\]) \$tmm0_raw)\[0\]\[0\] = 1" gdb_test "print/d (uint8_t\[16\]\[64\]) \$tmm0_raw" \ [join {"= \\{\\{1, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\ 0 \\}" \ "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0 \\}" \ "\\{0 \\} \\}"} \ - ", "] + ", "] \ + "print tmm0_raw.m_uint8 after raw write" + + # The user register must reflect the write to the raw register. + gdb_test "print \$tmm0.m_uint8" \ + [join {"= \\{\\{1, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2\\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3\\}\\}"} \ + ", "] \ + "print tmm0.m_uint8 user register after raw write" + + # Write to another element of the same tile via the user register. + gdb_test_no_output "set \$tmm0.m_uint8\[0\]\[1\] = 2" + gdb_test "print \$tmm0.m_uint8" \ + [join {"= \\{\\{1, 2, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2\\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3\\}\\}"} \ + ", "] \ + "print tmm0.m_uint8 after user write" + + # The raw register must reflect the write to the user register. + gdb_test "print/d (uint8_t\[16\]\[64\]) \$tmm0_raw" \ + [join {"= \\{\\{1, 2, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,\ + 0 \\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0 \\}" \ + "\\{0 \\} \\}"} \ + ", "] \ + "print tmm0_raw.m_uint8 after user write" + # A whole row can be set at once. The remaining elements of the row are + # zeroed. gdb_test_no_output "set ((int\[16\]\[16\]) \$tmm2_raw)\[0\] = {1, 1, 1}" gdb_test "print (int\[16\]\[16\]) \$tmm2_raw" \ [join {"= \\{\\{1, 1, 1, 0 \\}" \ "\\{32, 56, 80, 104, 0 \\}" \ "\\{0 \\} \\}"} \ - ", "] + ", "] \ + "print tmm2_raw.m_int32 after raw write" + gdb_test "print \$tmm2.m_int32" \ + [join {"= \\{\\{1, 1, 1, 0\\}" \ + "\\{32, 56, 80, 104\\}\\}"} \ + ", "] \ + "print tmm2.m_int32 after raw write" + + gdb_test_no_output "set \$tmm2.m_int32\[0\] = {2, 2, 2}" + gdb_test "print \$tmm2.m_int32" \ + [join {"= \\{\\{2, 2, 2, 0\\}" \ + "\\{32, 56, 80, 104\\}\\}"} \ + ", "] \ + "print tmm2.m_int32 after user write" + gdb_test "print (int\[16\]\[16\]) \$tmm2_raw" \ + [join {"= \\{\\{2, 2, 2, 0 \\}" \ + "\\{32, 56, 80, 104, 0 \\}" \ + "\\{0 \\} \\}"} \ + ", "] \ + "print tmm2_raw.m_int32 after user write" + + # 0x3f00 is the bfloat16 encoding of 0.5. + gdb_test_no_output \ + "set ((uint16_t\[16\]\[32\]) \$tmm0_raw)\[0\]\[0\] = 0x3f00" + gdb_test "print \$tmm0.m_bf16\[0\]\[0\]" "= 0.5" + + gdb_test_no_output "set \$tmm0.m_bf16\[0\]\[1\] = 0.25" + gdb_test "print \$tmm0.m_bf16\[0\]\[1\]" "= 0.25" + gdb_test "print/x ((uint16_t\[16\]\[32\]) \$tmm0_raw)\[0\]\[1\]" "= 0x3e80" gdb_test_no_output "set ((float\[16\]\[16\]) \$tmm0_raw)\[0\]\[0\] = 0.75" - gdb_test "print ((float\[16\]\[16\]) \$tmm0_raw)\[0\]\[0\]" "= 0.75" + gdb_test "print ((float\[16\]\[16\]) \$tmm0_raw)\[0\]\[0\]" "= 0.75" \ + "print tmm0_raw.m_fp32\[0\]\[0\] after raw write" + gdb_test "print \$tmm0.m_fp32\[0\]\[0\]" "= 0.75" \ + "print tmm0.m_fp32\[0\]\[0\] after raw write" + + gdb_test_no_output "set \$tmm0.m_fp32\[0\]\[0\] = 0.5" + gdb_test "print \$tmm0.m_fp32\[0\]\[0\]" "= 0.5" \ + "print tmm0.m_fp32\[0\]\[0\] after user write" + gdb_test "print ((float\[16\]\[16\]) \$tmm0_raw)\[0\]\[0\]" "= 0.5" \ + "print tmm0_raw.m_fp32\[0\]\[0\] after user write" gdb_test_no_output "set ((int8_t\[16\]\[64\]) \$tmm0_raw)\[0\]\[0\] = -1" - gdb_test "print/d ((int8_t\[16\]\[64\]) \$tmm0_raw)\[0\]\[0\]" "= -1" + gdb_test "print/d ((int8_t\[16\]\[64\]) \$tmm0_raw)\[0\]\[0\]" "= -1" \ + "print tmm0_raw.m_int8\[0\]\[0\] after raw write" + gdb_test "print \$tmm0.m_int8\[0\]\[0\]" "= -1" \ + "print tmm0.m_int8\[0\]\[0\] after raw write" + + gdb_test_no_output "set \$tmm0.m_int8\[0\]\[0\] = -3" + gdb_test "print \$tmm0.m_int8\[0\]\[0\]" "= -3" \ + "print tmm0.m_int8\[0\]\[0\] after user write" + gdb_test "print/d ((int8_t\[16\]\[64\]) \$tmm0_raw)\[0\]\[0\]" "= -3" \ + "print tmm0_raw.m_int8\[0\]\[0\] after user write" +} + +# Test the value history with the tmm user registers. +with_test_prefix "test value history" { + set tmm0 \ + [join {"= \\{\\{-3, 0, 0, 63, 1, 1, 1, 1, 2, 2, 2, 2\\}" \ + "\\{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3\\}\\}"} \ + ", "] + + gdb_test "print \$tmm0.m_int8" $tmm0 \ + "print tmm0 before re-configuration" + + # Re-configure the tile and modify its contents. Test the value recorded + # in value history. It must match w.r.t. shape and content. + gdb_test_no_output "set \$tilecfg.colsb\[0\] = 4" + gdb_test_no_output "set \$tmm0.m_int8\[0\]\[0\] = 9" + gdb_test "print \$" $tmm0 "print tmm0 from the value history" + gdb_test "print \$tmm0.m_int8" \ + [join {"= \\{\\{9, 0, 0, 63\\}" \ + "\\{1, 1, 1, 1\\}\\}"} \ + ", "] \ + "print tmm0 after re-configuration" } # Test generic setting. @@ -167,6 +292,45 @@ with_test_prefix "set tilecfg" { colsb = {0, 0, 0, 0, 0, 0, 0, 0}, rows = {4, 0, 0, 0, 0, 0, 0, 0}}"] } +# Return the Intel AMX registers listed in the output of COMMAND. + +proc amx_regs_in_output {command} { + set output [capture_command_output $command ""] + set regs {} + foreach {-> reg} [regexp -all -inline -line \ + {^(tilecfg(?:_raw)?|tmm[0-7](?:_raw)?)[ \t]} $output] { + lappend regs $reg + } + verbose -log "Intel AMX registers in \"$command\": $regs" + return $regs +} + +# The tilecfg pseudo register and the tile user registers are in the +# "all" and "matrix" register groups. The raw registers are only in the +# "save" and "restore" register groups. +with_test_prefix "register groups" { + set matrix_regs {tilecfg} + set raw_regs {tilecfg_raw} + for {set i 0} {$i < 8} {incr i} { + lappend matrix_regs tmm$i + lappend raw_regs tmm${i}_raw + } + + foreach {command expected} [list \ + "info registers" {} \ + "info all-registers" $matrix_regs \ + "info registers general" {} \ + "info registers all" $matrix_regs \ + "info registers matrix" $matrix_regs \ + "info registers vector" {} \ + "info registers float" {} \ + "info registers system" {} \ + "info registers save" $raw_regs \ + "info registers restore" $raw_regs] { + gdb_assert {[amx_regs_in_output $command] eq $expected} $command + } +} + # Test the core file generated by gcore. We expect the registers values that # the live process had before the core file is generated. if {$gcore_generated} { -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.