From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C8E92385803E for ; Fri, 29 Apr 2022 14:20:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8E92385803E Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-327-AEINYzFfP62kGOaRg3ZVRg-1; Fri, 29 Apr 2022 10:20:18 -0400 X-MC-Unique: AEINYzFfP62kGOaRg3ZVRg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA6591C05AC1; Fri, 29 Apr 2022 14:20:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B55840D1B99; Fri, 29 Apr 2022 14:20:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 23TEKF0W3384899 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 29 Apr 2022 16:20:15 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 23TEKE4i3384898; Fri, 29 Apr 2022 16:20:14 +0200 Date: Fri, 29 Apr 2022 16:20:14 +0200 From: Jakub Jelinek To: Ahmed Sayed Mousse Cc: gcc@gcc.gnu.org Subject: Re: FW: ompd_get_thread_id in OMPD implementation Message-ID: Reply-To: Jakub Jelinek References: <83CFFA00-57E0-417C-8F3B-393F7FB92734@hxcore.ol> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2022 14:20:21 -0000 On Sat, Apr 09, 2022 at 12:38:11AM +0200, Ahmed Sayed Mousse wrote: > Sorry for the late reply. > I did check gomp_thread_self but I'm still not sure about what I should do, > maybe because I lack experience/knowledge. > Here is where my thinking is going right now and I hope you tell me if I'm > wrong. Sorry for the delay, I've been busy with GCC 12. > in gomp_thread_to_pthread_t there are 4 possible outputs > 1 - if LIBGOMP_USE_PTHREADS is enabled > { > first pthread_self() if the thread calling is the same thread as the > function input. > or gomp_thread->handle in case GOMP_NEEDS_THREAD_HANDLE is enabled. > or pthread_self () + ((uintptr_t) input_thread - (uintptr_t) > calling_thread) > } ompd_get_thread_id is for mapping of the OMPD thread id to the native thread id. If LIBGOMP_USE_PTHREADS, we are using POSIX threads, so OMPD_THREAD_ID_PTHREAD is what we want to provide. If GOMP_NEEDS_THREAD_HANDLE, then we want to read the handle member for it and return it. Otherwise as the comment says, we optimize and because we know that in the initial-exec TLS model &gomp_tls_data - pthread_self () is the same for each thread, we don't store the handle at all, so ompd_get_thread_id instead needs to compute the bias. If it is too hard to do it in libgompd.so alone, perhaps during gompd_load libgomp.so.1 could compute it and store in some variable that libgompd.so can then read. > 2 -if LIBGOMP_USE_PTHREADS not enabled > - empty struct casted to a pthread_t > currently think i should check for the GOMP_NEED_THREAD_HANDLE, if it's > enabled i extract the pthread_t from the gomp_thread handle given in the > function and return that. > If it's not enabled then I return an empty struct or an rc_unspported > return code. > Note: > The openmp specification doesn't really tell me how things should be > done so I get confused a lot and I think I have a misunderstanding of the > function. > I would appreciate it a lot if I get any directions to where I can > increase my knowledge around this part. If LIBGOMP_USE_PTHREADS is not enabled, then it is libgomp.a built for one of the offloading targets, either NVPTX or GCN. We then can't return OMPD_THREAD_ID_PTHREAD, threads are numbered differently there, they are either the CUDA threads or GCN threads. But I think at least initially we only build libgompd.so for the host so how exactly we OMPD offloading should be postponed until after the host handling works. Jakub