From patchwork Wed Apr 19 16:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 85495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp521827vqo; Wed, 19 Apr 2023 09:39:07 -0700 (PDT) X-Google-Smtp-Source: AKy350ZDSj62Ixmyj7dPdehrGlBDh0SeyGNoiNr4t4iPpp5A5UId3Z+7UMHXwgZ5k4p0ZUD8qPiX X-Received: by 2002:a17:906:22c9:b0:94a:67a9:6052 with SMTP id q9-20020a17090622c900b0094a67a96052mr15756368eja.67.1681922347011; Wed, 19 Apr 2023 09:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681922346; cv=none; d=google.com; s=arc-20160816; b=RC8cgnqIZHjGIawj/FPXx91LLiKjg/rf52w0VLotJ/lBYm6brqwkolIgtVb96qnmZa R0lGwkreo5y7Ols6UCR8KjPjDhtOoBwbX2lcJXNQBYFW3KTi6LdWHX86+zLctGvU2v/2 bYD0yn88J78lWK0l+jmXRkVsq1wYYeDujPD+R+TMU1r4CNfObEkHZ4rpXq85Wk7BA0zM hk49jLnPZoIZYKJ6vX3F797v8kbEKcwtWCBz+7OCFJ5+amP1J+IiIOq3nndzYSKz/X9C wZl+x0zzNvcM8AHZrzUi0ar4tA4PXr3D+WnC9CLkNzHydLAM6k19KjIJvgUFBtkna/re avSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dmarc-filter:delivered-to; bh=hE0hD8dc8C2ByjbTYUpuo1mCqtB4qPjyktx5kjjcBag=; b=ENST6DXJTMZTIc+gwxhnPqKUbXma4cHaHM8fTb7dOUPPubVAvPJRGUm2mP66f2izxP B5hLNpGWVGc8RWp/j8l3Qydrd0dutJEysWP5g3R7Jjg9KyMK+31oA/G6sp0GlhUC4zcu VuGgpRU6X7gAk4T9KFynkHBffjoxoY44ClMfxYhRnARQQETEUZ9cm+vI49Pt4rVA4Ibp 6/B/F1Y7CkQPpx0DNKVF2D2LHBVHLspMk9f+AN2BjmfbaP7c2ZSJUDbTB/a4aH5HXIzx RTjA3EFgmFRdrYFIDvnCk/TO3LV142+yIwxlM+UMePxIY7SV1ncs7lHt/vrdsu2w0B/V Dozw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fr21-20020a170906891500b0094f6fdfc626si7786128ejc.677.2023.04.19.09.39.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 09:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F182385B52E for ; Wed, 19 Apr 2023 16:37:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg154.qq.com (smtpbg154.qq.com [15.184.224.54]) by sourceware.org (Postfix) with ESMTPS id 4DCEB385772E for ; Wed, 19 Apr 2023 16:36:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DCEB385772E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp62t1681922201tpydy01c Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 20 Apr 2023 00:36:40 +0800 (CST) X-QQ-SSF: 01400000000000F0P000000A0000000 X-QQ-FEAT: /pBoQNkXukW+ASjdmlNcLo1UacjPprbDjoJbAS/vtmoNSakbSblW1OEnT8UO9 06b58aLS/fdnEJuAaubRgr448ZvOkcc0MNajUCQBVYl3TJK0xast9VPvAsbE418Lv0V4dVS 1TEP+gMoA1AsuwFywgwykkCkK+McWIq3ez08XELOOVdTSiHYFK3LA4LGqJDTWQ2u9i52Nb3 I3aCmxIGLlrdaxo57UgjOZMCObkPjEARQNCgnPOaXdhstPBHpvAxRDwJ0IEQNAtMwlMyUAx QCQlv4SYiG6cI1nmBIo0sK0xoaeViDCVNax2zj/hdREbmP9KsOIpRtTrBN37Fze2t0hmr28 PSjvbTh3ksnUdt4pZhuFojHjPPXpFRAzgqbwx1twhVciyESJVfl7JNtdq84nA== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 7725104505256673044 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, Ju-Zhe Zhong Subject: [PATCH 1/3] RISC-V: Add auto-vectorization compile option for RVV Date: Thu, 20 Apr 2023 00:36:32 +0800 Message-Id: <20230419163634.1030144-2-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20230419163634.1030144-1-juzhe.zhong@rivai.ai> References: <20230419163634.1030144-1-juzhe.zhong@rivai.ai> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763623406830181512?= X-GMAIL-MSGID: =?utf-8?q?1763623406830181512?= From: Ju-Zhe Zhong This patch is adding 2 compile option for RVV auto-vectorization. 1. -param=riscv-autovec-preference= This option is to specify the auto-vectorization approach for RVV. Currently, we only support scalable and fixed-vlmax. - scalable means VLA auto-vectorization. The vector-length to compiler is unknown and runtime invariant. Such approach can allow us compile the code run on any vector-length RVV CPU. - fixed-vlmax means the compile known the RVV CPU vector-length, compile option in fixed-length VLS auto-vectorization. Meaning if we specify vector-length=512. The execution file can only run on vector-length = 512 RVV CPU. - TODO: we may need to support min-length VLS auto-vectorization, means the execution file can run on larger length RVV CPU. gcc/ChangeLog: * config/riscv/riscv-opts.h (enum riscv_autovec_preference_enum): Add enum for auto-vectorization preference. (enum riscv_autovec_lmul_enum): Add enum for choosing LMUL of RVV auto-vectorization. * config/riscv/riscv.opt: Add compile option for RVV auto-vectorization. --- gcc/config/riscv/riscv-opts.h | 15 ++++++++++++++ gcc/config/riscv/riscv.opt | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index cf0cd669be4..4207db240ea 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -67,6 +67,21 @@ enum stack_protector_guard { SSP_GLOBAL /* global canary */ }; +/* RISC-V auto-vectorization preference. */ +enum riscv_autovec_preference_enum { + NO_AUTOVEC, + RVV_SCALABLE, + RVV_FIXED_VLMAX +}; + +/* RISC-V auto-vectorization RVV LMUL. */ +enum riscv_autovec_lmul_enum { + RVV_M1 = 1, + RVV_M2 = 2, + RVV_M4 = 4, + RVV_M8 = 8 +}; + #define MASK_ZICSR (1 << 0) #define MASK_ZIFENCEI (1 << 1) diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index ff1dd4ddd4f..ef1bdfcfe28 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -254,3 +254,40 @@ Enum(isa_spec_class) String(20191213) Value(ISA_SPEC_CLASS_20191213) misa-spec= Target RejectNegative Joined Enum(isa_spec_class) Var(riscv_isa_spec) Init(TARGET_DEFAULT_ISA_SPEC) Set the version of RISC-V ISA spec. + +Enum +Name(riscv_autovec_preference) Type(enum riscv_autovec_preference_enum) +The RISC-V auto-vectorization preference: + +EnumValue +Enum(riscv_autovec_preference) String(none) Value(NO_AUTOVEC) + +EnumValue +Enum(riscv_autovec_preference) String(scalable) Value(RVV_SCALABLE) + +EnumValue +Enum(riscv_autovec_preference) String(fixed-vlmax) Value(RVV_FIXED_VLMAX) + +-param=riscv-autovec-preference= +Target RejectNegative Joined Enum(riscv_autovec_preference) Var(riscv_autovec_preference) Init(NO_AUTOVEC) +-param=riscv-autovec-preference= Set the preference of auto-vectorization in the RISC-V port. + +Enum +Name(riscv_autovec_lmul) Type(enum riscv_autovec_lmul_enum) +The RVV possible LMUL: + +EnumValue +Enum(riscv_autovec_lmul) String(m1) Value(RVV_M1) + +EnumValue +Enum(riscv_autovec_lmul) String(m2) Value(RVV_M2) + +EnumValue +Enum(riscv_autovec_lmul) String(m4) Value(RVV_M4) + +EnumValue +Enum(riscv_autovec_lmul) String(m8) Value(RVV_M8) + +-param=riscv-autovec-lmul= +Target RejectNegative Joined Enum(riscv_autovec_lmul) Var(riscv_autovec_lmul) Init(RVV_M1) +-param=riscv-autovec-lmul= Set the RVV LMUL of auto-vectorization in the RISC-V port.