From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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, 05 Apr 2017 08:11:00 -0000 Message-ID: <87pogrgtop.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2017-04/txt/msg00199.txt.bz2 Hi! On Tue, 19 Apr 2016 10:24:36 +0200, Martin Li=C5=A1ka wrot= e: > 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. >=20 > Patch survives HSA regression tests, installed to the HSA branch as r2351= 89. (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 =3D dlsym (handle, #function); \ > + if (hsa_fns.function##_fn =3D=3D NULL) \ > + return false; > + > +static bool > +init_hsa_runtime_functions (void) > +{ > + void *handle =3D dlopen (hsa_runtime_lib, RTLD_LAZY); > + if (handle =3D=3D 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 =20=20=20=20 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(-) 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 =3D dlsym (handle, #function); \ if (hsa_fns.function##_fn =3D=3D NULL) \ - return false; + goto dl_fail; =20 static bool init_hsa_runtime_functions (void) { void *handle =3D dlopen (hsa_runtime_lib, RTLD_LAZY); if (handle =3D=3D NULL) - return false; + goto dl_fail; =20 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; } =20 /* Find kernel for an AGENT by name provided in KERNEL_NAME. */ Gr=C3=BC=C3=9Fe Thomas