From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2RYGLrBr7GrDjx8AWB0awg (envelope-from ) for ; Thu, 05 Nov 2026 06:42:40 -0500 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=iSdZwQIB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B47971E023; Thu, 05 Nov 2026 06:42:40 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 2C2781E023 for ; Thu, 05 Nov 2026 06:42:38 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B30E4BA2E27 for ; Thu, 5 Nov 2026 11:42:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B30E4BA2E27 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=iSdZwQIB Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by sourceware.org (Postfix) with ESMTPS id 788FC4BA23CD for ; Thu, 5 Nov 2026 11:42:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 788FC4BA23CD 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 788FC4BA23CD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793878920; cv=none; b=FR7i5yoyxpmOo8LwQNksIJT2wZlaleD+2s7ivfRwcx3dNjHx6miiYD6mzVaid8MAEDtSml6tfFOwbl+buoznVcYx0PjKHAcCbHw+DwCaPjjOANTlNzPaKRHu0dzJNn77aZ/H8DKP6lNPYwFVbsGSE3ftKNwL9O3V1H4C73BoNFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793878920; c=relaxed/simple; bh=nxVCd+qbdR+vagIGru+CM8uiXwy1KCq/VRz+kAjg0uk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XKVjrPTYEOd1Y/vMUyg/YSz0rQYxoGy/iUmJz+9K97Eernxb4fttELCstWeAX1+VI2BOrp6I6zjanr/74wcWCVlm6gTO1b9lskc0fAKkt+2FBs91dkMVx1EN/H2N7E2RUonsttQf5Q4AaRMy0pl90awnwDy2wG9yDmiKBhu97ec= 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=iSdZwQIB DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 788FC4BA23CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1793878921; x=1825414921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nxVCd+qbdR+vagIGru+CM8uiXwy1KCq/VRz+kAjg0uk=; b=iSdZwQIBwsyoDn+n2cI4NAZUVrbAtIrGirG88VDTcg9fOH1bGRDtiCSk 01H0HpwvOQOtZEKHW2knH4PSkI4lpnw77YmNnZXmW023Gd/7BwdyiJT/F w7kgeHCC+E6Y2FEXRD0ENDJ00YKny6MtTKwHDE8TJBhSMpf/WeWtKx+sG OrfgtRr/9SBJBZi00bZNwkdaNRg/D/dHjjxjEYRNHVG/amZpPa1Uzm0E3 9tF41DkGY+rfV+t8kevjXDdgMwLn3lJqCqsux0qJiaE6PE1QlJ4Spl7xl AAXjHSqWIMEXMvcdFLpDpJwxTf+aPN1rIL56FcUHk+uKhOVWFwZJVekhi Q==; X-CSE-ConnectionGUID: r56BAOqDSW6TGHQ9J5SK4g== X-CSE-MsgGUID: nbnrI8N3SL+XpeHDMujhSQ== X-IronPort-AV: E=McAfee;i="6800,10657,11956"; a="2559961" X-IronPort-AV: E=Sophos;i="6.27,197,1787036400"; d="scan'208";a="2559961" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2026 03:41:59 -0800 X-CSE-ConnectionGUID: 2Hn6AI/CSt+X1TV1U/lZIw== X-CSE-MsgGUID: UKhP8N/2TmGBjpVKJIoTnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,197,1787036400"; d="scan'208";a="7327230" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2026 03:41:58 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: pedro@palves.net, eliz@gnu.org, jhb@FreeBSD.org, luis.machado@arm.com, christina.joos@intel.com Subject: [PATCH v3 5/5] gdb: add Intel AMX tile registers as user registers Date: Thu, 5 Nov 2026 11:41:09 +0000 Message-ID: <20261105114109.153949-6-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261105114109.153949-1-stephan.rohr@intel.com> References: <20261105114109.153949-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 implement a union with the following types: - int8 - uint8 - int32 - bfloat16 - float Intel AMX instructions operate on dwords. A row of a tile holds colsb / 4 dwords, each of which holds four 1-byte elements, two 2-byte elements or one 4-byte element. A user register is void if the tile configuration is not valid. That is, if - palette 0 is selected, - the number of rows is either zero or exceeds the maximum number of rows, - the number of bytes per row (colsb) is zero or exceeds the maximum number of bytes per row, - colsb is not a multiple of 4. Intel AMX instructions cannot operate on a tile with such a configuration. The raw tile register still shows the contents of the tile. 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 | 68 +++++++++ gdb/doc/gdb.texinfo | 25 +++- gdb/i386-tdep.c | 104 ++++++++++++++ gdb/i386-tdep.h | 96 +++++++++++++ gdb/testsuite/gdb.arch/amd64-amx.c | 9 ++ gdb/testsuite/gdb.arch/amd64-amx.exp | 202 +++++++++++++++++++++++++-- 7 files changed, 491 insertions(+), 15 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 0a0d3edc624..afe51616b60 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 0b3985eb156..83ca4be933d 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,24 @@ static const char * const amd64_tmm_raw_names[] = { "tmm4_raw", "tmm5_raw", "tmm6_raw", "tmm7_raw" }; +/* Register names for the tmm user registers. */ + +static const char * const 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 +652,48 @@ amd64_ax_pseudo_register_collect (struct gdbarch *gdbarch, +/* Return the tile dimensions configured in TILECFG for NEXT_FRAME. */ + +static tile_dimensions +amd64_read_tile_dimensions (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 tile_dimensions (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. */ + tile_dimensions dims = amd64_read_tile_dimensions (next_frame); + + /* Return void if the configuration is not valid, see i386-tdep.h. */ + if (!dims.is_valid (tmmnum)) + return value::allocate (builtin_type (gdbarch)->builtin_void); + + uint8_t rows = dims.rows (tmmnum); + uint16_t colsb = dims.bytes_per_row (tmmnum); + + /* "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 @@ -3862,6 +3924,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 970c7cecc3b..8ccabb4220f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -27465,7 +27465,11 @@ omitting reserved bits. The tile registers are supplied as the raw registers @samp{tmm0_raw}, @samp{tmm1_raw}, @dots{}, @samp{tmm7_raw}, which show the 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. -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 @@ -27481,8 +27485,27 @@ $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}). + +A user register is @code{void} if its tile is not configured, or if the +tile configuration is not valid, that is, if: + +@itemize @bullet +@item @code{rows} is zero or exceeds the maximum number of rows. +@item @code{colsb} is zero or exceeds the maximum number of bytes per row. +@item @code{colsb} is not a multiple of four, as Intel @acronym{AMX} +instructions operate on doublewords. +@end itemize + +The raw tile register still shows the contents of the tile. + @node Alpha @subsection Alpha diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index a25abfbd1bc..4dcdd7663a6 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,26 @@ i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum) internal_error (_("invalid regnum")); } +/* See i386-tdep.h. */ + +tile_dimensions::tile_dimensions (gdb::array_view raw_tilecfg) +{ + gdb_assert (raw_tilecfg.size () == X86_AMX_TILECFG_SIZE); + + /* Ignore palette 0. */ + if (raw_tilecfg[PALETTE_OFFSET] == 0) + return; + + /* 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 +3271,86 @@ 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 TILE_DIMENSIONS::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 (tile_dimensions::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 <= tile_dimensions::MAX_ROWS); + gdb_assert (colsb > 0 && colsb <= tile_dimensions::MAX_BYTES_PER_ROW + && colsb % 4 == 0); + + /* 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 +4473,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 4b37b8204dd..b2ba4671dcb 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; @@ -286,6 +287,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. */ @@ -436,6 +440,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. */ @@ -535,4 +545,90 @@ 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. + + The tile dimensions configured in TILECFG. */ + +class tile_dimensions +{ +public: + /* Construct it from raw tilecfg data. With palette 0, no tile is + configured. */ + explicit tile_dimensions (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; + } + + /* Return true if the configuration of tile P is valid. A configuration + is invalid if: + + - rows is zero or exceeds MAX_ROWS. + - colsb is zero or exceeds MAX_BYTES_PER_ROW. + - colsb is not a multiple of 4, as Intel AMX instructions operate + on dwords. */ + inline bool + is_valid (uint8_t p) const + { + gdb_assert (p < NUM_TILES); + const tile &t = m_tiles[p]; + return (t.rows > 0 && t.rows <= MAX_ROWS + && t.colsb > 0 && t.colsb <= MAX_BYTES_PER_ROW + && t.colsb % 4 == 0); + } + + /* 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 palette and of the colsb and rows arrays. */ + static const uint16_t PALETTE_OFFSET = 0; + 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; + }; + + /* 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 5ca779565b4..0100baf701f 100644 --- a/gdb/testsuite/gdb.arch/amd64-amx.c +++ b/gdb/testsuite/gdb.arch/amd64-amx.c @@ -49,6 +49,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) @@ -81,6 +87,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; @@ -89,6 +97,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 94dfa441daf..acebab6a487 100644 --- a/gdb/testsuite/gdb.arch/amd64-amx.exp +++ b/gdb/testsuite/gdb.arch/amd64-amx.exp @@ -37,14 +37,14 @@ proc test_zeroed_tile {reg} { proc test_tiles {} { gdb_test "print/x \$tilecfg_raw" \ - [join {"= 0x20200020302000000000000000000000000000000000" \ - "000000000080008000000100010000c" \ + [join {"= 0x20202020302000000000000000000000000000000000" \ + "000000000080008000800100010000c" \ "00000000000000000000000000000001"} ""] 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,\ @@ -53,6 +53,11 @@ proc test_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 \\}" \ @@ -63,26 +68,48 @@ proc test_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" + gdb_test "print \$tmm${i}" "= void" } } @@ -119,28 +146,130 @@ 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" + + # Restore the configuration of tmm0. The program computes with it + # below. + gdb_test_no_output "set \$tilecfg.colsb\[0\] = 12" } # Test that the modified tiles are written back to the target. Some targets, @@ -204,6 +333,47 @@ with_test_prefix "set tilecfg" { rows = {4, 0, 0, 0, 0, 0, 0, 0}}"] } +# Test tile dimensions. +with_test_prefix "tile dimensions" { + gdb_test "print \$tmm6" "= void" "print unconfigured tmm6" + + set tile_1x4 [string_to_regexp "= {{0, 0, 0, 0}}"] + set tile_16x64 \ + [string_to_regexp "= {{0 } }"] + + foreach {rows colsb expected name} [list \ + 1 4 $tile_1x4 "1 row of 4 bytes" \ + 16 64 $tile_16x64 "maximum dimensions"] { + with_test_prefix $name { + gdb_test_no_output "set \$tilecfg.rows\[6\] = $rows" + gdb_test_no_output "set \$tilecfg.colsb\[6\] = $colsb" + gdb_test "print \$tmm6.m_uint8" $expected + } + } + + foreach {rows colsb name} { + 2 0 "0 bytes per row" + 0 8 "0 rows" + 2 65 "65 bytes per row" + 17 8 "17 rows" + 2 2 "2 bytes per row" + 2 6 "6 bytes per row" + } { + with_test_prefix $name { + gdb_test_no_output "set \$tilecfg.rows\[6\] = $rows" + gdb_test_no_output "set \$tilecfg.colsb\[6\] = $colsb" + gdb_test "print \$tmm6" "= void" + } + } + + with_test_prefix "palette 0" { + gdb_test_no_output "set \$tilecfg.rows\[6\] = 2" + gdb_test_no_output "set \$tilecfg.colsb\[6\] = 8" + gdb_test_no_output "set \$tilecfg.palette = 0" + gdb_test "print \$tmm6" "= void" + } +} + # Return the Intel AMX registers listed in the output of COMMAND. proc amx_regs_in_output {command} { @@ -217,19 +387,23 @@ proc amx_regs_in_output {command} { return $regs } -# The tilecfg pseudo register is in the "all" register group. The raw -# registers are only in the "save" and "restore" register groups. +# 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" {tilecfg} \ + "info all-registers" $matrix_regs \ "info registers general" {} \ - "info registers all" {tilecfg} \ + "info registers all" $matrix_regs \ + "info registers matrix" $matrix_regs \ "info registers vector" {} \ "info registers float" {} \ "info registers system" {} \ -- 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.