From patchwork Mon Nov 23 14:35:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 547561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CCB2F140213 for ; Tue, 24 Nov 2015 01:36:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=UIjUDcW6; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=bmkFQdnDRktynUz25NBvLOp/wODcU0T/gfLhMG7b7x8MiSDwi/xyT 525r2BEeYTZkA3SBeqxIOxyGTamJ4yn4rwsKGZjZ6Y6RgFC+l0pcvQh60r4SHaPH 0MjnD3mGfsHMNlSi1SFIk2s3TA28xIfWpTPC3kMybvgoqo3UlOEZV4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=+ntbvcFssOWvVmuQEtUWl9YA15g=; b=UIjUDcW6A4oPyQTjbfGH nKWkxSYspPowPYqtY1PT5XhaRc89tUBcgsZkZW58jHAmNXueMsJ5e2cFhaW6nAic 09EwqFMVclRICjE0UwKSWoR7ZXWdwdeW2gqWYXi5ZmekVdmIdJJhaoncduIiyH81 6R8nduWcNxojJWgJSQXBUm8= Received: (qmail 43886 invoked by alias); 23 Nov 2015 14:35:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 43855 invoked by uid 89); 23 Nov 2015 14:35:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 23 Nov 2015 14:35:51 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E109CACE0 for ; Mon, 23 Nov 2015 14:34:40 +0000 (UTC) Date: Mon, 23 Nov 2015 15:35:48 +0100 From: Martin Jambor To: GCC Patches Subject: [hsa] Use new format of device-specific target arguments Message-ID: <20151123143547.GD6879@virgil.suse.cz> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi, I have committed this branch which changes the format of device-specific arguments of GOMP_target_ext to something closer to what Jakub wants. Specifically, lowest 7 bits determine the accelerator type (0 means all of them), next bit determines whether the next element in args array is also part of this one, then there are 8 bits for an ID of the argument and then up to 16 bits for a value. Thanks, Martin 2015-11-20 Martin Jambor gcc/ * omp-low.c (get_target_argument_identifier_1): New function. (get_target_argument_identifier): Likewise. (get_target_argument_value): Likewise. (get_target_arguments): Use them. include/ * gomp-constants.h (GOMP_TARGET_ARG_FIRST_DEVICE_SPECIFIC): Removed. (GOMP_TARGET_ARG_DEVICE_MASK): New. (GOMP_TARGET_ARG_DEVICE_ALL): Likewise. (GOMP_TARGET_ARG_SUBSEQUENT_PARAM): Likewise. (GOMP_TARGET_ARG_ID_MASK): Likewise. (GOMP_TARGET_ARG_VALUE_SHIFT): Likewise. (GOMP_TARGET_ARG_NUM_TEAMS): Skifted by 8. (GOMP_TARGET_ARG_THREAD_LIMIT): Likewise. (GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES): Likewise. libgomp/ * plugin/plugin-hsa.c (parse_launch_attributes): Renamed to parse_target_attributes. Process the new format of arguments. --- gcc/omp-low.c | 69 ++++++++++++++++++++++++++++++++++++--------- include/gomp-constants.h | 32 +++++++++++++++------ libgomp/plugin/plugin-hsa.c | 16 +++++++---- 3 files changed, 89 insertions(+), 28 deletions(-) diff --git a/gcc/omp-low.c b/gcc/omp-low.c index f2436d7..a9188dc 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -12638,7 +12638,50 @@ get_kernel_launch_attributes (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt) return build_fold_addr_expr (lattrs); } -/* Create an array of arguments that is then passed to GOMP_target. */ +/* Build target argument identifier from the DEVICE identifier, value + identifier ID and whether the element also has a SUBSEQUENT_PARAM. */ + +static tree +get_target_argument_identifier_1 (int device, bool subseqent_param, int id) +{ + tree t = build_int_cst (integer_type_node, device); + if (subseqent_param) + t = fold_build2 (BIT_IOR_EXPR, integer_type_node, t, + build_int_cst (integer_type_node, + GOMP_TARGET_ARG_SUBSEQUENT_PARAM)); + t = fold_build2 (BIT_IOR_EXPR, integer_type_node, t, + build_int_cst (integer_type_node, id)); + return t; +} + +/* Like above but return it in type that can be directly stored as an element + of the argument array. */ + +static tree +get_target_argument_identifier (int device, bool subseqent_param, int id) +{ + tree t = get_target_argument_identifier_1 (device, subseqent_param, id); + return fold_convert (ptr_type_node, t); +} + +/* Return a target argument consisiting of DEVICE identifier, value identifier + ID, and the actual VALUE. */ + +static tree +get_target_argument_value (gimple_stmt_iterator *gsi, int device, int id, + tree value) +{ + tree t = fold_build2 (LSHIFT_EXPR, integer_type_node, + fold_convert (integer_type_node, value), + build_int_cst (unsigned_type_node, + GOMP_TARGET_ARG_VALUE_SHIFT)); + t = fold_build2 (BIT_IOR_EXPR, integer_type_node, t, + get_target_argument_identifier_1 (device, false, id)); + t = fold_convert (ptr_type_node, t); + return force_gimple_operand_gsi (gsi, t, true, NULL, true, GSI_SAME_STMT); +} + +/* Create an array of arguments that is then passed to GOMP_target. */ static tree get_target_arguments (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt) @@ -12647,28 +12690,28 @@ get_target_arguments (gimple_stmt_iterator *gsi, gomp_target *tgt_stmt) tree clauses = gimple_omp_target_clauses (tgt_stmt); tree t, c = find_omp_clause (clauses, OMP_CLAUSE_NUM_TEAMS); if (c) - { - t = fold_convert (ptr_type_node, OMP_CLAUSE_NUM_TEAMS_EXPR (c)); - t = force_gimple_operand_gsi (gsi, t, true, NULL, true, GSI_SAME_STMT); - } + t = OMP_CLAUSE_NUM_TEAMS_EXPR (c); else - t = fold_convert (ptr_type_node, integer_minus_one_node); + t = integer_minus_one_node; + t = get_target_argument_value (gsi, GOMP_TARGET_ARG_DEVICE_ALL, + GOMP_TARGET_ARG_NUM_TEAMS, t); args.quick_push (t); + c = find_omp_clause (clauses, OMP_CLAUSE_THREAD_LIMIT); if (c) - { - t = fold_convert (ptr_type_node, OMP_CLAUSE_THREAD_LIMIT_EXPR (c)); - t = force_gimple_operand_gsi (gsi, t, true, NULL, true, GSI_SAME_STMT); - } + t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c); else - t = fold_convert (ptr_type_node, integer_minus_one_node); + t = integer_minus_one_node; + t = get_target_argument_value (gsi, GOMP_TARGET_ARG_DEVICE_ALL, + GOMP_TARGET_ARG_THREAD_LIMIT, t); args.quick_push (t); /* Add HSA-specific grid sizes, if available. */ if (gimple_omp_target_dimensions (tgt_stmt)) { - args.quick_push (build_int_cst (ptr_type_node, - GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES)); + t = get_target_argument_identifier (GOMP_DEVICE_HSA, true, + GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES); + args.quick_push (t); args.quick_push (get_kernel_launch_attributes (gsi, tgt_stmt)); } diff --git a/include/gomp-constants.h b/include/gomp-constants.h index 9a792e0..747e7b0 100644 --- a/include/gomp-constants.h +++ b/include/gomp-constants.h @@ -229,18 +229,32 @@ enum gomp_map_kind #define GOMP_LAUNCH_OP(X) (((X) >> GOMP_LAUNCH_OP_SHIFT) & 0xffff) #define GOMP_LAUNCH_OP_MAX 0xffff -/* First device-specific identifier among target arguments. */ -#define GOMP_TARGET_ARG_FIRST_DEVICE_SPECIFIC 2 -/* Target argument index of NUM_TEAMS */ -#define GOMP_TARGET_ARG_NUM_TEAMS 0 -/* Target argument index of THREAD_LIMIT */ -#define GOMP_TARGET_ARG_THREAD_LIMIT 1 - -/* Identifiers of device-specific target arguments. */ -#define GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES 1 +/* Bitmask to apply in order to find out the intended device of a target + argument. */ +#define GOMP_TARGET_ARG_DEVICE_MASK ((1 << 7) - 1) +/* The target argument is significant for all devices. */ +#define GOMP_TARGET_ARG_DEVICE_ALL 0 + +/* Flag set when the subsequent element in the device-specific argument + values. */ +#define GOMP_TARGET_ARG_SUBSEQUENT_PARAM (1 << 7) + +/* Bitmask to apply to a target argument to find out the value identifier. */ +#define GOMP_TARGET_ARG_ID_MASK (((1 << 8) - 1) << 8) +/* Target argument index of NUM_TEAMS. */ +#define GOMP_TARGET_ARG_NUM_TEAMS (1 << 8) +/* Target argument index of THREAD_LIMIT. */ +#define GOMP_TARGET_ARG_THREAD_LIMIT (2 << 8) + +/* If the value is directly embeded in target argument, it should be a 16-bit + at most and shifted by tis many bits. */ +#define GOMP_TARGET_ARG_VALUE_SHIFT 16 /* HSA specific data structures. */ +/* Identifiers of device-specific target arguments. */ +#define GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES (1 << 8) + /* Structure describing the run-time and grid properties of an HSA kernel lauch. */ diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c index 72f5bdd..f0e7044 100644 --- a/libgomp/plugin/plugin-hsa.c +++ b/libgomp/plugin/plugin-hsa.c @@ -1047,12 +1047,12 @@ init_kernel (struct kernel_info *kernel) "mutex"); } -/* Parse the launch attributes INPUT provided by the compiler and return true +/* Parse the target attributes INPUT provided by the compiler and return true if we should run anything all. If INPUT is NULL, fill DEF with default values, then store INPUT or DEF into *RESULT. */ static bool -parse_launch_attributes (void **input, +parse_target_attributes (void **input, struct GOMP_kernel_launch_attributes *def, struct GOMP_kernel_launch_attributes **result) { @@ -1060,16 +1060,20 @@ parse_launch_attributes (void **input, GOMP_PLUGIN_fatal ("No target arguments provided"); bool attrs_found = false; - input += GOMP_TARGET_ARG_FIRST_DEVICE_SPECIFIC; while (*input) { uintptr_t id = (uintptr_t) *input; - input++; - if (id == GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES) + if ((id & GOMP_TARGET_ARG_DEVICE_MASK) == GOMP_DEVICE_HSA + && ((id & GOMP_TARGET_ARG_ID_MASK) + == GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES)) { + input++; attrs_found = true; break; } + + if (id & GOMP_TARGET_ARG_SUBSEQUENT_PARAM) + input++; input++; } @@ -1138,7 +1142,7 @@ GOMP_OFFLOAD_run (int n, void *fn_ptr, void *vars, void** args) struct agent_info *agent = kernel->agent; struct GOMP_kernel_launch_attributes def; struct GOMP_kernel_launch_attributes *kla; - if (!parse_launch_attributes (args, &def, &kla)) + if (!parse_target_attributes (args, &def, &kla)) { HSA_DEBUG ("Will not run HSA kernel because the grid size is zero\n"); return;