From patchwork Wed Apr 5 08:11:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 747124 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 3vydq11tKyz9s2Q for ; Wed, 5 Apr 2017 18:11:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SU1vU+WC"; 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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=G9sLapBl/CXz6VpJYats/+YniecpAwpTfiJjPKIeTBBvVzWv//IMo zQ+ZEYF0yoXbDmbDZuVci+6iEK50WIgrObJzK+l7SQBBoIy0o4DHpPXB3QH1Jnml MtTnIkouHLuAzZrnItWpOf5Z1G6CDikUYfUMzLCQ9Q7bhn6ONOfraI= 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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=0ff8I0akJlCfS12Cdh7yF/xz+BE=; b=SU1vU+WCVF5UtEzbr5k4c5r9HEXw kRg9kkL9FJ5c0DCq59bqsFj0t3bGAAaLmlZcqY3luAxltT3JhFUEPfGXvzMSn25t y5wvuadlvzqspbKenqttEO6ZFYjvGoWPZqYdD0Gp3YC8206+1tUAc69Lj9dcyrd5 wTXU69m/Rup5g+8= Received: (qmail 78900 invoked by alias); 5 Apr 2017 08:11:46 -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 78885 invoked by uid 89); 5 Apr 2017 08:11:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=plug-in, 53010, 5306, AGENT X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Apr 2017 08:11:44 +0000 Received: from svr-orw-fem-02x.mgc.mentorg.com ([147.34.96.206] helo=SVR-ORW-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1cvg2Y-0006Ir-O8 from Thomas_Schwinge@mentor.com ; Wed, 05 Apr 2017 01:11:42 -0700 Received: from tftp-cs (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.3.224.2; Wed, 5 Apr 2017 01:11:42 -0700 Received: by tftp-cs (Postfix, from userid 49978) id B61F5C21B2; Wed, 5 Apr 2017 01:11:41 -0700 (PDT) From: Thomas Schwinge To: Martin =?utf-8?Q?Li=C5=A1ka?= , GCC Patches CC: Martin Jambor , Richard Biener Subject: Re: [HSA, PATCH] Load an HSA runtime via dlopen mechanism In-Reply-To: <5715EB44.1030903@suse.cz> References: <5715EB44.1030903@suse.cz> User-Agent: Notmuch/0.9-125-g4686d11 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Wed, 5 Apr 2017 10:11:34 +0200 Message-ID: <87pogrgtop.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Hi! On Tue, 19 Apr 2016 10:24:36 +0200, Martin Liška wrote: > After brief discussions about packaging of an HSA runtime, we've decided to load > an HSA runtime via dlopen mechanism. Following patch introduces necessary header > files and all functions within the HSA plug-in are loaded via dlsym. > > Patch survives HSA regression tests, installed to the HSA branch as r235189. (And later pushed into trunk.) > --- a/libgomp/plugin/plugin-hsa.c > +++ b/libgomp/plugin/plugin-hsa.c > +#define DLSYM_FN(function) \ > + hsa_fns.function##_fn = dlsym (handle, #function); \ > + if (hsa_fns.function##_fn == NULL) \ > + return false; > + > +static bool > +init_hsa_runtime_functions (void) > +{ > + void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); > + if (handle == NULL) > + return false; > + > + DLSYM_FN (hsa_status_string) > +[...] > + DLSYM_FN (hsa_ext_program_finalize) > + return true; > +} I ran into a case where the libgomp hsa plugin wouldn't load. The following patch helped me to quickly diagnose and then fix that. OK for trunk? commit 54099202eb88464530dd3a55709c9afb85766ee0 Author: Thomas Schwinge Date: Wed Apr 5 09:58:02 2017 +0200 libgomp hsa plugin: debug output for HSA runtime library loading failure libgomp/ * plugin/plugin-hsa.c (DLSYM_FN, init_hsa_runtime_functions): Debug output for failure. --- libgomp/plugin/plugin-hsa.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) Grüße Thomas diff --git libgomp/plugin/plugin-hsa.c libgomp/plugin/plugin-hsa.c index 9cc243d..90ca247 100644 --- libgomp/plugin/plugin-hsa.c +++ libgomp/plugin/plugin-hsa.c @@ -491,14 +491,14 @@ static struct hsa_context_info hsa_context; #define DLSYM_FN(function) \ hsa_fns.function##_fn = dlsym (handle, #function); \ if (hsa_fns.function##_fn == NULL) \ - return false; + goto dl_fail; static bool init_hsa_runtime_functions (void) { void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY); if (handle == NULL) - return false; + goto dl_fail; DLSYM_FN (hsa_status_string) DLSYM_FN (hsa_agent_get_info) @@ -530,6 +530,10 @@ init_hsa_runtime_functions (void) DLSYM_FN (hsa_ext_program_destroy) DLSYM_FN (hsa_ext_program_finalize) return true; + + dl_fail: + HSA_DEBUG ("while loading %s: %s\n", hsa_runtime_lib, dlerror ()); + return false; } /* Find kernel for an AGENT by name provided in KERNEL_NAME. */