From patchwork Thu Jul 9 23:01:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y2s1982 X-Patchwork-Id: 1326253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Nmhyrt+n; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B2s9N2vPMz9sSJ for ; Fri, 10 Jul 2020 09:01:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C72CD384B106; Thu, 9 Jul 2020 23:01:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C72CD384B106 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594335667; bh=8ZCJLW3EmWZCyysbXDQs7QbYbJ6f3aMYo57sTFQhuhY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Nmhyrt+ngEASHqLJoJtzt0gyYw7dl7K0unKrJbWbhNa2VqXFXTxnJL8B5UxUctziL mjroOBOBNkj3o4ZxWLfck9IN7aNygH37ucNsBdivL06MxC01NJ2P2B57FQ90kaRVlg 0VAQq58d1XLbLhwtDL0wuA8iXYR7vgncwC5qAOyk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by sourceware.org (Postfix) with ESMTPS id 841063861970 for ; Thu, 9 Jul 2020 23:01:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 841063861970 Received: by mail-qt1-x82e.google.com with SMTP id 6so3058593qtt.0 for ; Thu, 09 Jul 2020 16:01:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8ZCJLW3EmWZCyysbXDQs7QbYbJ6f3aMYo57sTFQhuhY=; b=javtPKpRw1E8qLjgkvIF1zF1uwlIErapRMiQjowXZxeZY1bB7NR7w09EfpWQJrTu3E sAWmM7gEYrbCHfbG0XttvdmVCwBeEu98FVgYtRNkB+3Phn7CCQwMV1JixKMnla73Z3MY Wug7VZyza+VCY3L+4H2F4nwrVGfQah3psySNWHMkDYLOdYg2qxKI6xUVvX064tBTpdYR t7psqs0gRgY2ijeK5vD2M2aDc0xUX2ogalWYlHRtz0h4XS/ZPBfPbfi4qVGr/Yf+jx22 nEh/Ujj3EUsiGXxW6SeQ/llv0V0ebsjDnEeEGfhoHAi/LQtBnMG33+cTfws84kEmRq+V SItg== X-Gm-Message-State: AOAM531pS99v2Hv8A5khcXZOeN405R4MvVbWwRrGgLJujT1A6vOQnnFr sdk3rEW2TM2vX2rPSNyvhGI= X-Google-Smtp-Source: ABdhPJwnwm1phMh6ymsZYQ1H7FBBo3uhPyyKmXhlIfMpEh4uYE1RYJKT24i86s3pBnR6cwdg9U7jKg== X-Received: by 2002:ac8:44d6:: with SMTP id b22mr67952790qto.391.1594335663976; Thu, 09 Jul 2020 16:01:03 -0700 (PDT) Received: from localhost.localdomain (toroon474aw-lp130-05-174-93-91-15.dsl.bell.ca. [174.93.91.15]) by smtp.gmail.com with ESMTPSA id x14sm5317151qki.65.2020.07.09.16.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 16:01:03 -0700 (PDT) To: mjambor@suse.cz, jakub@redhat.com Subject: [PATCH] libgomp: Add OMPD Address Space Information functions. Date: Thu, 9 Jul 2020 19:01:00 -0400 Message-Id: <20200709230100.3614328-1-y2s1982@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: y2s1982 via Gcc-patches From: y2s1982 Reply-To: y2s1982 Cc: gcc-patches@gcc.gnu.org, y2s1982 Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch adds Address Space Information function implementations as defined in section 5.5.4 of OpenMP API Specification 5.0. It also defines a struct that stores various information used by OMPD. 2020-07-09 Tony Sim libgomp/ChangeLog: * Makefile.am (libgompd_la_OBJECTS): Add ompd-addr.c. * Makefile.in: Regenerate. * libgompd.h (struct gompd_env): Add an extern declaration. * ompd-lib.c (struct gompd_env): Define. (gompd_set_environment): Define a placeholder function. (ompd_initialize): Add a call to gompd_set_environment. * ompd-addr.c: New file. --- libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 5 +-- libgomp/libgompd.h | 15 +++++++++ libgomp/ompd-addr.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ libgomp/ompd-lib.c | 12 +++++++ 5 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 libgomp/ompd-addr.c diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index fe0a92122ea..0a4a9c10eb9 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -90,7 +90,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c error.c \ oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \ affinity-fmt.c teams.c allocator.c oacc-profiling.c oacc-target.c -libgompd_la_SOURCES = ompd-lib.c ompd-proc.c +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 2b487e00499..9ceb2c6e460 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -235,7 +235,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo critical.lo \ $(am__objects_1) libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS) libgompd_la_LIBADD = -am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo +am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.lo ompd-addr.lo libgompd_la_OBJECTS = $(am_libgompd_la_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -592,7 +592,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \ affinity-fmt.c teams.c allocator.c oacc-profiling.c \ oacc-target.c $(am__append_4) -libgompd_la_SOURCES = ompd-lib.c ompd-proc.c +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c ompd-addr.c # Nvidia PTX OpenACC plugin. @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION) @@ -816,6 +816,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-plugin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-profiling.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oacc-target.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-addr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-lib.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ompd-proc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ordered.Plo@am__quote@ diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h index 495995e00d3..36cb858589e 100644 --- a/libgomp/libgompd.h +++ b/libgomp/libgompd.h @@ -47,4 +47,19 @@ typedef struct _ompd_aspace_handle { ompd_size_t ref_count; } ompd_address_space_handle_t; +struct gompd_env +{ + /* TODO: when the struct is better defined, turn it into a compact form. + LINK: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549698.html + For now, keep it as a struct. */ + + /* Environment set version number. */ + ompd_word_t gompd_env_version; + /* Represents _OPENMP that is in yyyymm format. */ + ompd_word_t openmp_version; +}; + +/* TODO: when gompd_env is better defined, turn it into a compact form. */ +extern struct gompd_env gompd_env_info; + #endif /* LIBGOMPD_H */ diff --git a/libgomp/ompd-addr.c b/libgomp/ompd-addr.c new file mode 100644 index 00000000000..b751d64ce28 --- /dev/null +++ b/libgomp/ompd-addr.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2020 Free Software Foundation, Inc. + Contributed by Yoosuk Sim . + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +/* This file contains function definitions for OMPD's Address Space Information + functions defined in the OpenMP 5.0 API Documentation, 5.5.4. */ + +#include +#include +#include +#include "omp-tools.h" +#include "libgompd.h" + +ompd_rc_t +ompd_get_omp_version (ompd_address_space_handle_t *address_space, + ompd_word_t *omp_version) +{ + if (omp_version == NULL) + return ompd_rc_bad_input; + if (address_space == NULL) + return ompd_rc_stale_handle; + + *omp_version = gompd_env_info.openmp_version; + + return ompd_rc_ok; +} + +ompd_rc_t +ompd_get_omp_version_string (ompd_address_space_handle_t *address_space, + const char **string) +{ + if (string == NULL) + return ompd_rc_bad_input; + + if (address_space == NULL) + return ompd_rc_stale_handle; + + ompd_size_t macro_length = 6; /* _OPENMP format: yyyymm. */ + ompd_word_t omp_version; + ompd_rc_t ret = ompd_get_omp_version (address_space, &omp_version); + if (ret != ompd_rc_ok) + return ret; + + char *tmp = "GNU OpenMP Runtime implementing OpenMP 5.0 "; + ompd_size_t tmp_length = strlen (tmp); + + size_t total_length = tmp_length + macro_length + 1; + + char *t = NULL; + ret = gompd_callbacks.alloc_memory (total_length, (void *) t); + if (ret != ompd_rc_ok) + return ret; + + memcpy (t, tmp, tmp_length); + snprintf (t + tmp_length, macro_length, "%ld", omp_version); + + *string = t; + + return ret; +} diff --git a/libgomp/ompd-lib.c b/libgomp/ompd-lib.c index d5350e1045c..1b4f5cf0472 100644 --- a/libgomp/ompd-lib.c +++ b/libgomp/ompd-lib.c @@ -31,6 +31,17 @@ ompd_callbacks_t gompd_callbacks; static int ompd_initialized = 0; +struct gompd_env gompd_env_info; + +ompd_rc_t +gompd_set_environment () +{ + /* TODO: Turn this placeholder function to handle OMPD environment variables + when it becomes compact. */ + struct gompd_env temp_env = { 202007, 201811 }; + gompd_env_info = temp_env; + return ompd_rc_ok; +} ompd_rc_t ompd_get_api_version (ompd_word_t *version) @@ -57,6 +68,7 @@ ompd_initialize (ompd_word_t api_version, const ompd_callbacks_t *callbacks) return ompd_rc_error; gompd_callbacks = *callbacks; + gompd_set_environment (); (void) api_version;