From patchwork Mon Feb 18 04:56:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flora Cui X-Patchwork-Id: 10817303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17BDB6CB for ; Mon, 18 Feb 2019 04:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04E602A0D9 for ; Mon, 18 Feb 2019 04:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED1682A0E0; Mon, 18 Feb 2019 04:56:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 14AC72A0D9 for ; Mon, 18 Feb 2019 04:56:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8CC389152; Mon, 18 Feb 2019 04:56:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-BY2-obe.outbound.protection.outlook.com (mail-eopbgr710051.outbound.protection.outlook.com [40.107.71.51]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17B3B89152; Mon, 18 Feb 2019 04:56:13 +0000 (UTC) Received: from MN2PR12MB3312.namprd12.prod.outlook.com (20.179.83.160) by MN2PR12MB3294.namprd12.prod.outlook.com (20.179.83.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1622.16; Mon, 18 Feb 2019 04:56:12 +0000 Received: from MN2PR12MB3312.namprd12.prod.outlook.com ([fe80::3495:b4fb:12d2:245e]) by MN2PR12MB3312.namprd12.prod.outlook.com ([fe80::3495:b4fb:12d2:245e%6]) with mapi id 15.20.1622.018; Mon, 18 Feb 2019 04:56:12 +0000 From: "Cui, Flora" To: "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" Subject: [PATCH libdrm] tests/amdgpu: add dispatch test Thread-Topic: [PATCH libdrm] tests/amdgpu: add dispatch test Thread-Index: AQHUx0ZFo+23AIO0j0+T3ce1FqrxaQ== Date: Mon, 18 Feb 2019 04:56:12 +0000 Message-ID: <1550465735-27433-1-git-send-email-flora.cui@amd.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [180.167.199.189] x-clientproxiedby: HK2PR02CA0204.apcprd02.prod.outlook.com (2603:1096:201:20::16) To MN2PR12MB3312.namprd12.prod.outlook.com (2603:10b6:208:106::32) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 65518d5f-3d06-4547-6cad-08d6955d6755 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600110)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:MN2PR12MB3294; x-ms-traffictypediagnostic: MN2PR12MB3294: x-microsoft-exchange-diagnostics: 1; MN2PR12MB3294; 20:IvDJ/fXfk/ixcrvp5gp/v0ILvPBRi7GANFxl6rihXxCcZRpbkT0Zzw0wzbuUoleOOoOj90FTNWKqYgggYNB26FuXneOs75/VfRpstPP0lq/gnGKO/yepuSGcl3hkik6xoKbwGRYFSuw5qq+cfotg1QtgYx7QqKcDfViFbd5x9hlAAp+FrOc5HoU+t59VUTx4yF6dKr1SjQPOyXrfabhMoCFKadRYJp4OgqIZCGa/j2q2niAqQpBilCgxxfPFh+YL x-microsoft-antispam-prvs: x-forefront-prvs: 09525C61DB x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(136003)(39860400002)(396003)(366004)(346002)(189003)(199004)(316002)(6512007)(66066001)(6506007)(3846002)(52116002)(26005)(386003)(110136005)(486006)(6116002)(97736004)(102836004)(186003)(106356001)(4326008)(53936002)(86362001)(2501003)(105586002)(68736007)(72206003)(99286004)(25786009)(50226002)(8936002)(305945005)(6436002)(450100002)(7736002)(71190400001)(36756003)(476003)(256004)(2616005)(81166006)(8676002)(14454004)(81156014)(14444005)(478600001)(71200400001)(6486002)(2906002)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR12MB3294; H:MN2PR12MB3312.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 2M+YWDK91aG3kiiMkTHCEnv9QJzM0c6bDU96sQzmrvUxtEaYyKyACrOp7vtpSHHj5tCWJEdJRaNnKurhXfjFwSZqaZ5DhNxr2ICL5uhPhpRLvGcIYMV8oIg/1xIB6aJTGP/klY4KCOoatM7O2mHSI1E7jgqzL0FkNYnQJ5rwd81K43JeE3WxNQkkvYOj4+J2Jol6jitVlByev1Kr1JOQ5l4++M4gl4f+gyOG+DvX+IgafMbpdAzTpW+WgyH06J3Yt0O/MYHDmjkcKOx4TjRSUcO8ZAPWc+/JOVj9r59XvD6/JzSOwfZ+rNwEJSl0Fku74z6xheluzNIC5rod/Cyg80Tkps9n1Fq8KdZRHHr/yBxlDU3+BzaotLsEJKvVrMxSqgv6IYI/kul1LQIa1G8ZeU6nVSw9cwdJN+pBUlSmxaY= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65518d5f-3d06-4547-6cad-08d6955d6755 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Feb 2019 04:56:10.5913 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3294 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ecWsYK9ySFW19gHtvkwNKAjo/ndJkfSF8kVLIKT+Bc0=; b=x2LM0lqEmPs0CL96vreNzPSwcO9LpiO6Lj87hXJvvXSxsG50VbIZcrldWQGVuZI4IIXZDzaH5qVZesJVA3QdmaAW9Dqe7rMDVJz3EKVLQlM5L+pMhuDtGGt4cVJyJFreM6f16pGMIN50vtamz1e+fbhtPKRKTArvISw3R2hzPxs= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Flora.Cui@amd.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Cui, Flora" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Flora Cui Change-Id: I6f5dfa4379cb21c41c68757fae0105527a03e54f Signed-off-by: Flora Cui Signed-off-by: Flora Cui --- tests/amdgpu/basic_tests.c | 175 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 2 deletions(-) diff --git a/tests/amdgpu/basic_tests.c b/tests/amdgpu/basic_tests.c index d79859a..649c5a4 100644 --- a/tests/amdgpu/basic_tests.c +++ b/tests/amdgpu/basic_tests.c @@ -49,6 +49,7 @@ static void amdgpu_userptr_test(void); static void amdgpu_semaphore_test(void); static void amdgpu_sync_dependency_test(void); static void amdgpu_bo_eviction_test(void); +static void amdgpu_memset_dispatch_test(void); static void amdgpu_direct_gma_test(void); static void amdgpu_command_submission_write_linear_helper(unsigned ip_type); @@ -71,6 +72,7 @@ CU_TestInfo basic_tests[] = { { "Command submission Test (SDMA)", amdgpu_command_submission_sdma }, { "SW semaphore Test", amdgpu_semaphore_test }, { "Sync dependency Test", amdgpu_sync_dependency_test }, + { "Memset dispatch Test", amdgpu_memset_dispatch_test }, { "Direct GMA", amdgpu_direct_gma_test }, CU_TEST_INFO_NULL, }; @@ -119,6 +121,7 @@ CU_TestInfo basic_tests[] = { #define PACKET3(op, n) ((PACKET_TYPE3 << 30) | \ (((op) & 0xFF) << 8) | \ ((n) & 0x3FFF) << 16) +#define PACKET3_COMPUTE(op, n) PACKET3(op, n) | (1 << 1) /* Packet 3 types */ #define PACKET3_NOP 0x10 @@ -247,8 +250,8 @@ CU_TestInfo basic_tests[] = { #define PACKET3_SET_SH_REG_START 0x00002c00 #define PACKET3_DISPATCH_DIRECT 0x15 - - +#define PACKET3_EVENT_WRITE 0x46 +#define PACKET3_ACQUIRE_MEM 0x58 /* gfx 8 */ #define mmCOMPUTE_PGM_LO 0x2e0c #define mmCOMPUTE_PGM_RSRC1 0x2e12 @@ -1945,6 +1948,174 @@ static void amdgpu_sync_dependency_test(void) free(ibs_request.dependencies); } +static const uint32_t bufferclear_cs_shader_gfx9[] = +{ + 0xD1FD0000, 0x04010C08, 0x7E020204, 0x7E040205, + 0x7E060206, 0x7E080207, 0xE01C2000, 0x80000100, + 0xBF810000 +}; +static const uint32_t bufferclear_cs_shader_registers_gfx9[][2] = { + {0x2e12, 0x000C0041}, //{ mmCOMPUTE_PGM_RSRC1, 0x000C0041 }, + {0x2e13, 0x00000090}, //{ mmCOMPUTE_PGM_RSRC2, 0x00000090 }, + {0x2e07, 0x00000040}, //{ mmCOMPUTE_NUM_THREAD_X, 0x00000040 }, + {0x2e08, 0x00000001}, //{ mmCOMPUTE_NUM_THREAD_Y, 0x00000001 }, + {0x2e09, 0x00000001}, //{ mmCOMPUTE_NUM_THREAD_Z, 0x00000001 } +}; +static void amdgpu_memset_dispatch_gfx_test_gfx9() +{ + amdgpu_context_handle context_handle; + amdgpu_bo_handle bo_dst, bo_shader, resources[2]; + volatile unsigned char *ptr_dst; + void *ptr_shader; + uint64_t mc_address_dst, mc_address_shader; + amdgpu_va_handle va_dst, va_shader; + int i, j, r; + uint32_t *ptr; + int bo_dst_size = 16384; + struct amdgpu_cs_request ibs_request; + struct amdgpu_cs_ib_info ib_info; + + ptr = calloc(256, sizeof(*ptr)); + CU_ASSERT_NOT_EQUAL(ptr, NULL); + memset(ptr, 0, 256); + + r = amdgpu_cs_ctx_create(device_handle, &context_handle); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_alloc_and_map(device_handle, 4096, 4096, + AMDGPU_GEM_DOMAIN_VRAM, 0, + &bo_shader, &ptr_shader, + &mc_address_shader, &va_shader); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_bo_alloc_and_map(device_handle, bo_dst_size, 4096, + AMDGPU_GEM_DOMAIN_VRAM, 0, + &bo_dst, &ptr_dst, + &mc_address_dst, &va_dst); + CU_ASSERT_EQUAL(r, 0); + + memcpy(ptr_shader, bufferclear_cs_shader_gfx9, sizeof(bufferclear_cs_shader_gfx9)); + + i = 0; + ptr[i++] = PACKET3(PKT3_CONTEXT_CONTROL, 1); + ptr[i++] = 0x80000000; + ptr[i++] = 0x80000000; + + /* Issue commands to set default compute state. */ + /* clear mmCOMPUTE_START_Z - mmCOMPUTE_START_X */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 3); + ptr[i++] = 0x204; + ptr[i++] = 0; + ptr[i++] = 0; + ptr[i++] = 0; + /* clear mmCOMPUTE_RESOURCE_LIMITS */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 1); + ptr[i++] = 0x215; + ptr[i++] = 0; + /* clear mmCOMPUTE_TMPRING_SIZE */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 1); + ptr[i++] = 0x218; + ptr[i++] = 0; + + /* Issue commands to set cu mask used in current dispatch */ + /* set mmCOMPUTE_STATIC_THREAD_MGMT_SE1 - mmCOMPUTE_STATIC_THREAD_MGMT_SE0 */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 2); + ptr[i++] = 0x216; + ptr[i++] = 0xffffffff; + ptr[i++] = 0xffffffff; + /* set mmCOMPUTE_STATIC_THREAD_MGMT_SE3 - mmCOMPUTE_STATIC_THREAD_MGMT_SE2 */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 2); + ptr[i++] = 0x219; + ptr[i++] = 0xffffffff; + ptr[i++] = 0xffffffff; + + /* Writes shader state to HW */ + /* set mmCOMPUTE_PGM_HI - mmCOMPUTE_PGM_LO */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 2); + ptr[i++] = 0x20c; + ptr[i++] = (mc_address_shader >> 8); + ptr[i++] = (mc_address_shader >> 40); + /* write sh regs*/ + for (j = 0; j < 5; j++) { + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 1); + /* - Gfx9ShRegBase */ + ptr[i++] = bufferclear_cs_shader_registers_gfx9[j][0] - 0x2c00; + ptr[i++] = bufferclear_cs_shader_registers_gfx9[j][1]; + } + /* Write constant data */ + /* Writes the UAV constant data to the SGPRs. */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 4); + ptr[i++] = 0x240; + ptr[i++] = mc_address_dst; + ptr[i++] = (mc_address_dst > 32) | 0x100000; + ptr[i++] = 0x400; + ptr[i++] = 0x74fac; + /* Sets a range of pixel shader constants */ + ptr[i++] = PACKET3_COMPUTE(PKT3_SET_SH_REG, 4); + ptr[i++] = 0x244; + ptr[i++] = 0x22222222; + ptr[i++] = 0x22222222; + ptr[i++] = 0x22222222; + ptr[i++] = 0x22222222; + + /* dispatch direct command */ + ptr[i++] = PACKET3_COMPUTE(PACKET3_DISPATCH_DIRECT, 3); + ptr[i++] = 0x10; + ptr[i++] = 1; + ptr[i++] = 1; + ptr[i++] = 1; + + /* Wait for CS to complete and then invalidates L1/L2 cache with SurfaceSync */ + ptr[i++] = PACKET3(PACKET3_EVENT_WRITE, 0); + ptr[i++] = 0x407; + ptr[i++] = PACKET3(PACKET3_ACQUIRE_MEM, 5); + ptr[i++] = 0x80c40000; + ptr[i++] = 0xffffffff; + ptr[i++] = 0xff; + ptr[i++] = 0; + ptr[i++] = 0; + ptr[i++] = 0xa; + + while (i & 7) + ptr[i++] = 0xffff1000; /* type3 nop packet */ + + resources[0] = bo_dst; + resources[1] = bo_shader; + amdgpu_test_exec_cs_helper(context_handle, + AMDGPU_HW_IP_GFX, 0, + i, ptr, + 2, resources, + &ib_info, &ibs_request); + + /* verify if memset test result meets with expected */ + i = 0; + while(i < bo_dst_size) { + CU_ASSERT_EQUAL(ptr_dst[i++], 0x22); + } + + free(ptr); + + r = amdgpu_bo_unmap_and_free(bo_shader, va_shader, mc_address_shader, 4096); + CU_ASSERT_EQUAL(r, 0); + r = amdgpu_bo_unmap_and_free(bo_dst, va_dst, mc_address_dst, bo_dst_size); + CU_ASSERT_EQUAL(r, 0); + + r = amdgpu_cs_ctx_free(context_handle); + CU_ASSERT_EQUAL(r, 0); +} + +static void amdgpu_memset_dispatch_test() +{ + struct drm_amdgpu_info_hw_ip info; + int r; + + r = amdgpu_query_hw_ip_info(device_handle, AMDGPU_HW_IP_COMPUTE, 0, &info); + CU_ASSERT_EQUAL(r, 0); + + if (info.hw_ip_version_major == 9) + amdgpu_memset_dispatch_gfx_test_gfx9(); +} + static int amdgpu_direct_gma_bo_alloc_and_map(amdgpu_device_handle dev, amdgpu_device_handle peer, unsigned size, unsigned alignment, amdgpu_bo_handle *bo, amdgpu_bo_handle *bo_peer,