From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53725 invoked by alias); 23 Nov 2015 14:38:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 53711 invoked by uid 89); 23 Nov 2015 14:38:33 -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:38:32 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B3696ACE0 for ; Mon, 23 Nov 2015 14:37:21 +0000 (UTC) Date: Mon, 23 Nov 2015 14:39:00 -0000 From: Martin Jambor To: GCC Patches Subject: [hsa] Perform version checks in HSA plugin Message-ID: <20151123143828.GE6879@virgil.suse.cz> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg02731.txt.bz2 Hi, the following patch against the HSA branch makes it call GOMP_offload_register_ver and GOMP_offload_unregister_ver as opposed to the routines without version information and adds a version check to the libgomp plugin along the lines other plugins do it. Committed to the branch, any feedback welcome, Martin 2015-11-23 Martin Jambor gcc/ * builtin-types.def (BT_FN_VOID_PTR_INT_PTR): Removed. (BT_FN_VOID_UINT_PTR_INT_PTR): New. * fortran/types.def (BT_FN_VOID_PTR_INT_PTR): Removed. (BT_FN_VOID_UINT_PTR_INT_PTR): New. * hsa-brig.c: Include gomp-constants. (hsa_output_libgomp_mapping): Add version arguments to to registration and unregistration calls. * omp-builtins.def (BUILT_IN_GOMP_OFFLOAD_REGISTER): Change to refer to functions with versions. (BUILT_IN_GOMP_OFFLOAD_UNREGISTER): Likewise. include/ * gomp-constants.h (GOMP_VERSION_HSA): New. libgomp/ * plugin/plugin-hsa.c (GOMP_OFFLOAD_load_image): Check version. (GOMP_OFFLOAD_unload_image): Likewise. --- gcc/builtin-types.def | 3 ++- gcc/fortran/types.def | 3 ++- gcc/hsa-brig.c | 19 ++++++++++++------- gcc/omp-builtins.def | 9 +++++---- include/gomp-constants.h | 1 + libgomp/plugin/plugin-hsa.c | 21 +++++++++++++-------- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index 251c980..8dcf3a6 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -450,7 +450,6 @@ DEF_FUNCTION_TYPE_3 (BT_FN_BOOL_ULONG_ULONG_ULONGPTR, BT_BOOL, BT_ULONG, BT_ULONG, BT_PTR_ULONG) DEF_FUNCTION_TYPE_3 (BT_FN_BOOL_ULONGLONG_ULONGLONG_ULONGLONGPTR, BT_BOOL, BT_ULONGLONG, BT_ULONGLONG, BT_PTR_ULONGLONG) -DEF_FUNCTION_TYPE_3 (BT_FN_VOID_PTR_INT_PTR, BT_VOID, BT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR, BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR) @@ -479,6 +478,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_LONGPTR_LONGPTR_LONGPTR, DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_ULLPTR_ULLPTR_ULLPTR, BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_PTR_ULONGLONG, BT_PTR_ULONGLONG) +DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, BT_INT, BT_PTR, + BT_INT, BT_PTR) DEF_FUNCTION_TYPE_5 (BT_FN_INT_STRING_INT_SIZE_CONST_STRING_VALIST_ARG, BT_INT, BT_STRING, BT_INT, BT_SIZE, BT_CONST_STRING, diff --git a/gcc/fortran/types.def b/gcc/fortran/types.def index d5f44ab..283eaf4 100644 --- a/gcc/fortran/types.def +++ b/gcc/fortran/types.def @@ -145,7 +145,6 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I2_INT, BT_VOID, BT_VOLATILE_PTR, BT_I2, BT DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I4_INT, BT_VOID, BT_VOLATILE_PTR, BT_I4, BT_INT) DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I8_INT, BT_VOID, BT_VOLATILE_PTR, BT_I8, BT_INT) DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I16_INT, BT_VOID, BT_VOLATILE_PTR, BT_I16, BT_INT) -DEF_FUNCTION_TYPE_3 (BT_FN_VOID_PTR_INT_PTR, BT_VOID, BT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_4 (BT_FN_VOID_OMPFN_PTR_UINT_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT) @@ -160,6 +159,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_LONGPTR_LONGPTR_LONGPTR, DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_ULLPTR_ULLPTR_ULLPTR, BT_BOOL, BT_UINT, BT_PTR_ULONGLONG, BT_PTR_ULONGLONG, BT_PTR_ULONGLONG) +DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, BT_INT, BT_PTR, + BT_INT, BT_PTR) DEF_FUNCTION_TYPE_5 (BT_FN_VOID_OMPFN_PTR_UINT_UINT_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT, diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c index f47e9c3..b687cc5 100644 --- a/gcc/hsa-brig.c +++ b/gcc/hsa-brig.c @@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see #include "print-tree.h" #include "symbol-summary.h" #include "hsa.h" +#include "gomp-constants.h" #define BRIG_ELF_SECTION_NAME ".brig" #define BRIG_LABEL_STRING "hsa_brig" @@ -2216,10 +2217,12 @@ hsa_output_libgomp_mapping (tree brig_decl) gcc_checking_assert (offload_register); append_to_statement_list - (build_call_expr (offload_register, 3, + (build_call_expr (offload_register, 4, + build_int_cstu (unsigned_type_node, + GOMP_VERSION_PACK (GOMP_VERSION, + GOMP_VERSION_HSA)), build_fold_addr_expr (hsa_libgomp_host_table), - /* 7 stands for HSA. */ - build_int_cst (integer_type_node, 7), + build_int_cst (integer_type_node, GOMP_DEVICE_HSA), build_fold_addr_expr (hsa_img_descriptor)), &hsa_ctor_statements); @@ -2230,10 +2233,12 @@ hsa_output_libgomp_mapping (tree brig_decl) gcc_checking_assert (offload_unregister); append_to_statement_list - (build_call_expr (offload_unregister, - 3, build_fold_addr_expr (hsa_libgomp_host_table), - /* 7 stands for HSA. */ - build_int_cst (integer_type_node, 7), + (build_call_expr (offload_unregister, 4, + build_int_cstu (unsigned_type_node, + GOMP_VERSION_PACK (GOMP_VERSION, + GOMP_VERSION_HSA)), + build_fold_addr_expr (hsa_libgomp_host_table), + build_int_cst (integer_type_node, GOMP_DEVICE_HSA), build_fold_addr_expr (hsa_img_descriptor)), &hsa_dtor_statements); cgraph_build_static_cdtor ('D', hsa_dtor_statements, DEFAULT_INIT_PRIORITY); diff --git a/gcc/omp-builtins.def b/gcc/omp-builtins.def index edf3c4b..b9054ef 100644 --- a/gcc/omp-builtins.def +++ b/gcc/omp-builtins.def @@ -338,10 +338,11 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_COPY_START, "GOMP_single_copy_start", BT_FN_PTR, ATTR_NOTHROW_LEAF_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_SINGLE_COPY_END, "GOMP_single_copy_end", BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST) -DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_REGISTER, "GOMP_offload_register", - BT_FN_VOID_PTR_INT_PTR, ATTR_NOTHROW_LIST) -DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_UNREGISTER, "GOMP_offload_unregister", - BT_FN_VOID_PTR_INT_PTR, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_REGISTER, "GOMP_offload_register_ver", + BT_FN_VOID_UINT_PTR_INT_PTR, ATTR_NOTHROW_LIST) +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_OFFLOAD_UNREGISTER, + "GOMP_offload_unregister_ver", + BT_FN_VOID_UINT_PTR_INT_PTR, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET, "GOMP_target_ext", BT_FN_VOID_INT_OMPFN_SIZE_PTR_PTR_PTR_UINT_PTR_PTR, ATTR_NOTHROW_LIST) diff --git a/include/gomp-constants.h b/include/gomp-constants.h index 747e7b0..983d9d0 100644 --- a/include/gomp-constants.h +++ b/include/gomp-constants.h @@ -202,6 +202,7 @@ enum gomp_map_kind #define GOMP_VERSION 0 #define GOMP_VERSION_NVIDIA_PTX 1 #define GOMP_VERSION_INTEL_MIC 0 +#define GOMP_VERSION_HSA 0 #define GOMP_VERSION_PACK(LIB, DEV) (((LIB) << 16) | (DEV)) #define GOMP_VERSION_LIB(PACK) (((PACK) >> 16) & 0xffff) diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c index f0e7044..b866a78 100644 --- a/libgomp/plugin/plugin-hsa.c +++ b/libgomp/plugin/plugin-hsa.c @@ -575,12 +575,15 @@ destroy_hsa_program (struct agent_info *agent) brig_image_desc in TARGET_DATA and return references to kernel descriptors in TARGET_TABLE. */ -/* FIXME: Start using some kind of versioning scheme too, I suppose. */ - int -GOMP_OFFLOAD_load_image (int ord, unsigned version __attribute__ ((unused)), - void *target_data, struct addr_pair **target_table) +GOMP_OFFLOAD_load_image (int ord, unsigned version, void *target_data, + struct addr_pair **target_table) { + if (GOMP_VERSION_DEV (version) > GOMP_VERSION_HSA) + GOMP_PLUGIN_fatal ("Offload data incompatible with HSA plugin" + " (expected %u, received %u)", + GOMP_VERSION_HSA, GOMP_VERSION_DEV (version)); + struct brig_image_desc *image_desc = (struct brig_image_desc *) target_data; struct agent_info *agent; struct addr_pair *pair; @@ -1315,12 +1318,14 @@ destroy_module (struct module_info *module) /* Part of the libgomp plugin interface. Unload BRIG module described by struct brig_image_desc in TARGET_DATA from agent number N. */ -/* FIXME: Like when loading an image, look at the version. */ - void -GOMP_OFFLOAD_unload_image (int n, unsigned version __attribute__ ((unused)), - void *target_data) +GOMP_OFFLOAD_unload_image (int n, unsigned version, void *target_data) { + if (GOMP_VERSION_DEV (version) > GOMP_VERSION_HSA) + GOMP_PLUGIN_fatal ("Offload data incompatible with HSA plugin" + " (expected %u, received %u)", + GOMP_VERSION_HSA, GOMP_VERSION_DEV (version)); + struct agent_info *agent; agent = get_agent_info (n); if (pthread_rwlock_wrlock (&agent->modules_rwlock)) -- 2.6.0