From patchwork Fri Jul 3 17:49:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: y2s1982 X-Patchwork-Id: 1322583 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=2620:52:3:1:0:246e:9693:128c; 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=ajpUNZfM; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 49z2XZ4cjTz9sR4 for ; Sat, 4 Jul 2020 03:49:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23182384402F; Fri, 3 Jul 2020 17:49:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23182384402F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593798570; bh=19tjC3kzIn3aUf2ajWA6hTuhDuYrfclhXCU7Wg3ISi4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ajpUNZfMFw9lsUCWPrWyHv5A63ioXUwxn1Wh7xe/eXndhQjH3QmYOq7r/t+fzxSEA IjTCQ9GzwqfoL99ldGIhvEE3yr91GFfduDgHT6nk196K8LMnMdIIjzZ1ptcLCwtWYR pC2fSMEa3HIXOluZL39pqt5TE93Xmtf4qoOVA6M8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 153B23844079 for ; Fri, 3 Jul 2020 17:49:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 153B23844079 Received: by mail-qk1-x733.google.com with SMTP id 145so26975157qke.9 for ; Fri, 03 Jul 2020 10:49:27 -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=19tjC3kzIn3aUf2ajWA6hTuhDuYrfclhXCU7Wg3ISi4=; b=Cdt7MirQayvIR+qc9eq0BxIiaqzcQBG/sCpG9VvvoubptL0JjebwQmxM37sTeYXoQu dvrt/EPMbuuWxkiR5Ivb69YBpxR0MLVnDsNEuBwF0Y8g57hPCKOa/aGL0uo4V2Lk6AzK Ynmvo3aQntLLe90DUw4FccGkpo+h2FFr82SyXFPzPTFq5hw41CamDLbt3HekGJ3J0gC8 2FFP9EYt+Pknw2x+Wv57+YwlrRfJ9U6aYxpTkZ0mQ+vPsbjEUvIHVwzTSwcXD8zcxEAM k176sPpeSomsgMUAs95bhJx4xoHO6kXp0LF1PT2kkxJKhvjgOzTr8BFesiegRDDGytMK vdvw== X-Gm-Message-State: AOAM531j/npVfIRHpMu5CEIyVrDKwtVgOqH9yBH87CgTgSvtDBaFJh/E MqO6VCd5KVjjz27/r822krw= X-Google-Smtp-Source: ABdhPJz1iuyKWoek5yE0dH0/QlJPuU4eRz2X3NlY06YjTufNi/qoC5qdPIN+LM6drubs5oEV4RVV0A== X-Received: by 2002:a05:620a:1275:: with SMTP id b21mr35390956qkl.4.1593798566554; Fri, 03 Jul 2020 10:49:26 -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 p80sm11255758qke.19.2020.07.03.10.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 10:49:25 -0700 (PDT) To: mjambor@suse.cz, jakub@redhat.com Subject: [PATCH] libgomp: Add OMPD per-process functions. Date: Fri, 3 Jul 2020 13:49:21 -0400 Message-Id: <20200703174921.3242338-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 OMPD process and device handling functions and related data structures as described in the OMP 5.0 API documentation, section 5.5.2. 2020-07-03 Tony Sim libgomp/ChangeLog: * Makefile.am (libgompd_la_SOURCES): Add ompd-proc.c * Makefile.in: Regenerate. * libgompd.h (ompd_address_space_handle_t): Add definition. * ompd-proc.c: New file. * ompd-types.h: New file. --- libgomp/Makefile.am | 2 +- libgomp/Makefile.in | 9 +-- libgomp/libgompd.h | 9 +++ libgomp/ompd-proc.c | 132 +++++++++++++++++++++++++++++++++++++++++++ libgomp/ompd-types.h | 90 +++++++++++++++++++++++++++++ 5 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 libgomp/ompd-proc.c create mode 100644 libgomp/ompd-types.h diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index e15a838e55c..e5556ef61e5 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 +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c include $(top_srcdir)/plugin/Makefrag.am diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index af897d6c6ba..f0f91761a0d 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 +am_libgompd_la_OBJECTS = ompd-lib.lo ompd-proc.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@) @@ -574,10 +574,10 @@ nodist_toolexeclib_HEADERS = libgomp.spec libgomp_version_info = -version-info $(libtool_VERSION) libgompd_version_info = -version-info $(libtool_VERSION) libgomp_la_LDFLAGS = $(libgomp_version_info) $(libgomp_version_script) \ - $(lt_host_flags) + $(lt_host_flags) libgompd_la_LDFLAGS = $(libgompd_version_info) $(libgompd_version_script) \ - $(lt_host_flags) + $(lt_host_flags) libgomp_la_DEPENDENCIES = $(libgomp_version_dep) libgompd_la_DEPENDENCIES = $(libgompd_version_dep) @@ -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 +libgompd_la_SOURCES = ompd-lib.c ompd-proc.c # Nvidia PTX OpenACC plugin. @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info $(libtool_VERSION) @@ -817,6 +817,7 @@ distclean-compile: @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-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@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parallel.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/priority_queue.Plo@am__quote@ diff --git a/libgomp/libgompd.h b/libgomp/libgompd.h index 3a428e1c1e4..495995e00d3 100644 --- a/libgomp/libgompd.h +++ b/libgomp/libgompd.h @@ -38,4 +38,13 @@ extern ompd_callbacks_t gompd_callbacks; +typedef struct _ompd_aspace_handle { + ompd_address_space_context_t *context; + ompd_device_t kind; + ompd_size_t sizeof_id; + void *id; + ompd_address_space_handle_t *process_reference; + ompd_size_t ref_count; +} ompd_address_space_handle_t; + #endif /* LIBGOMPD_H */ diff --git a/libgomp/ompd-proc.c b/libgomp/ompd-proc.c new file mode 100644 index 00000000000..39feba056f2 --- /dev/null +++ b/libgomp/ompd-proc.c @@ -0,0 +1,132 @@ +/* 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 per-process functions + defined in the OpenMP 5.0 API Documentation, 5.5.2. */ + +#include +#include "omp-tools.h" +#include "libgompd.h" +#include "ompd-types.h" + +ompd_rc_t +ompd_process_initialize (ompd_address_space_context_t *context, + ompd_address_space_handle_t **handle) +{ + ompd_rc_t ret = handle ? ompd_rc_ok : ompd_rc_stale_handle; + if (ret != ompd_rc_ok) + return ret; + + ret = context ? ompd_rc_ok : ompd_rc_bad_input; + + void *p = NULL; + ret = gompd_callbacks.alloc_memory (sizeof (ompd_address_space_handle_t), p); + if (ret != ompd_rc_ok) + return ret; + + *handle = p; + (*handle)->context = context; + (*handle)->kind = OMPD_DEVICE_KIND_HOST; + (*handle)->id = NULL; + (*handle)->sizeof_id = 0; + (*handle)->process_reference = NULL; + (*handle)->ref_count = 0; + + return ret; +} + +ompd_rc_t +ompd_device_initialize (ompd_address_space_handle_t *process_handle, + ompd_address_space_context_t *device_context, + ompd_device_t kind, ompd_size_t sizeof_id, void *id, + ompd_address_space_handle_t **device_handle) +{ + ompd_rc_t ret = process_handle && device_handle + ? ompd_rc_ok : ompd_rc_stale_handle; + + if (ret != ompd_rc_ok) + return ret; + + ret = device_context && id ? ompd_rc_ok : ompd_rc_bad_input; + if (ret != ompd_rc_ok) + return ret; + + void *p = NULL; + ret = gompd_callbacks.alloc_memory (sizeof (ompd_address_space_handle_t), p); + if (ret != ompd_rc_ok) + return ret; + + *device_handle = p; + p = NULL; + + ret = gompd_callbacks.alloc_memory (sizeof_id, p); + if (ret != ompd_rc_ok) + return ret; + + (*device_handle)->id = p; + + ret = gompd_callbacks.write_memory (device_context, NULL, id, sizeof_id, + (*device_handle)->id); + if (ret != ompd_rc_ok) + return ret; + (*device_handle)->sizeof_id = sizeof_id; + (*device_handle)->context = device_context; + (*device_handle)->kind = kind; + (*device_handle)->ref_count = 0; + (*device_handle)->process_reference = process_handle; + process_handle->ref_count++; + + return ret; +} + +ompd_rc_t +ompd_rel_address_space_handle (ompd_address_space_handle_t *handle) +{ + ompd_rc_t ret = handle && handle->context + ? ompd_rc_ok : ompd_rc_stale_handle; + if (ret != ompd_rc_ok) + return ret; + + ret = handle->ref_count == 0 ? ompd_rc_ok : ompd_rc_unavailable; + if (ret != ompd_rc_ok) + return ret; + + if (handle->process_reference) + { + if (handle->process_reference->ref_count == 0) + return ompd_rc_error; + handle->process_reference->ref_count--; + } + + if (handle->id) + { + ret = gompd_callbacks.free_memory (handle->id); + if (ret != ompd_rc_ok) + return ret; + } + + ret = gompd_callbacks.free_memory (handle); + return ret; +} diff --git a/libgomp/ompd-types.h b/libgomp/ompd-types.h new file mode 100644 index 00000000000..4a9aec18ebc --- /dev/null +++ b/libgomp/ompd-types.h @@ -0,0 +1,90 @@ +/* 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 various library-defined data types for OMPD library. */ + +#ifndef OMPD_TYPES_H +#define OMPD_TYPES_H 1 + +#include "omp-tools.h" + +#define OMPD_TYPES_VERSION 20180906 /* YYYYMMDD Format */ + +/* Kinds of device threads */ +#define OMPD_THREAD_ID_PTHREAD ((ompd_thread_id_t) 0) +#define OMPD_THREAD_ID_LWP ((ompd_thread_id_t) 1) +#define OMPD_THREAD_ID_WINTHREAD ((ompd_thread_id_t) 2) +#define OMPD_THREAD_ID_CUDALOGICAL ((ompd_thread_id_t) 3) +/* The range of non-standard implementation defined values */ +#define OMPD_THREAD_ID_LO ((ompd_thread_id_t) 1000000) +#define OMPD_THREAD_ID_HI ((ompd_thread_id_t) 1100000) + +/* Target Cuda device-specific thread identification */ +typedef struct ompd_dim3_t { + ompd_addr_t x; + ompd_addr_t y; + ompd_addr_t z; +} ompd_dim3_t; + +typedef struct ompd_cudathread_coord_t { + ompd_addr_t cudaDevId; + ompd_addr_t cudaContext; + ompd_addr_t warpSize; + ompd_addr_t gridId; + ompd_dim3_t gridDim; + ompd_dim3_t blockDim; + ompd_dim3_t blockIdx; + ompd_dim3_t threadIdx; +} ompd_cudathread_coord_t; + +/* Memory Access Segment definitions for Host and Target Devices */ +#define OMPD_SEGMENT_UNSPECIFIED ((ompd_seg_t) 0) + +/* Cuda-specific values consistent with those defined in cudadebugger.h */ +#define OMPD_SEGMENT_CUDA_PTX_UNSPECIFIED ((ompd_seg_t) 0) +#define OMPD_SEGMENT_CUDA_PTX_CODE ((ompd_seg_t) 1) +#define OMPD_SEGMENT_CUDA_PTX_REG ((ompd_seg_t) 2) +#define OMPD_SEGMENT_CUDA_PTX_SREG ((ompd_seg_t) 3) +#define OMPD_SEGMENT_CUDA_PTX_CONST ((ompd_seg_t) 4) +#define OMPD_SEGMENT_CUDA_PTX_GLOBAL ((ompd_seg_t) 5) +#define OMPD_SEGMENT_CUDA_PTX_LOCAL ((ompd_seg_t) 6) +#define OMPD_SEGMENT_CUDA_PTX_PARAM ((ompd_seg_t) 7) +#define OMPD_SEGMENT_CUDA_PTX_SHARED ((ompd_seg_t) 8) +#define OMPD_SEGMENT_CUDA_PTX_SURF ((ompd_seg_t) 9) +#define OMPD_SEGMENT_CUDA_PTX_TEX ((ompd_seg_t) 10) +#define OMPD_SEGMENT_CUDA_PTX_TEXSAMPLER ((ompd_seg_t) 11) +#define OMPD_SEGMENT_CUDA_PTX_GENERIC ((ompd_seg_t) 12) +#define OMPD_SEGMENT_CUDA_PTX_IPARAM ((ompd_seg_t) 13) +#define OMPD_SEGMENT_CUDA_PTX_OPARAM ((ompd_seg_t) 14) +#define OMPD_SEGMENT_CUDA_PTX_FRAME ((ompd_seg_t) 15) + +/* Kinds of device device address spaces */ +#define OMPD_DEVICE_KIND_HOST ((ompd_device_t) 1) +#define OMPD_DEVICE_KIND_CUDA ((ompd_device_t) 2) +/* The range of non-standard implementation defined values */ +#define OMPD_DEVICE_IMPL_LO ((ompd_device_t) 1000000) +#define OMPD_DEVICE_IMPL_HI ((ompd_device_t) 1100000) + +#endif /* OMPD_TYPES_H */