* FW: ompd_get_thread_id in OMPD implementation [not found] <83CFFA00-57E0-417C-8F3B-393F7FB92734@hxcore.ol> @ 2022-04-08 22:38 ` Ahmed Sayed Mousse 2022-04-29 14:20 ` Jakub Jelinek 0 siblings, 1 reply; 2+ messages in thread From: Ahmed Sayed Mousse @ 2022-04-08 22:38 UTC (permalink / raw) To: gcc; +Cc: jakub 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. 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) } 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. *From: *Ahmed Sayed Mousse <ahmedsayedmousse@gmail.com> *Sent: *Wednesday, March 23, 2022 7:23 PM *To: *gcc-help@gcc.gnu.org *Cc: *jakub@redhat.com *Subject: *ompd_get_thread_id in OMPD implementation Hi everyone, I was doing a research to help me implement the function “ompd_get_thread_id” from the OpenMP API specification under section 20.5.5.5. In this function I need to return a native thread identifier and from research I found that it’s a “pthread_t” handle which exists inside a struct named “gomp_thread” of the “libgomp.h” file. The problem is that this handle isn’t always defined and to show what I mean look at the code below. struct gomp_thread { ….. #if defined(LIBGOMP_USE_PTHREADS) \ && (!defined(HAVE_TLS) \ || !defined(__GLIBC__) \ || !defined(USING_INITIAL_EXEC_TLS)) #define GOMP_NEEDS_THREAD_HANDLE 1 pthread_t handle; #endif }; I use a macro to calculate the offset of this handle and use the this offset to get it from memory and I thought I would just check for GOMP_NEEDS_THREAD_HANDLE before trying to calculate this offset but It still causes errors and also if that handle isn’t defined then what should I return as a native identifier? Thanks for help. ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: FW: ompd_get_thread_id in OMPD implementation 2022-04-08 22:38 ` FW: ompd_get_thread_id in OMPD implementation Ahmed Sayed Mousse @ 2022-04-29 14:20 ` Jakub Jelinek 0 siblings, 0 replies; 2+ messages in thread From: Jakub Jelinek @ 2022-04-29 14:20 UTC (permalink / raw) To: Ahmed Sayed Mousse; +Cc: gcc 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-29 14:20 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <83CFFA00-57E0-417C-8F3B-393F7FB92734@hxcore.ol> 2022-04-08 22:38 ` FW: ompd_get_thread_id in OMPD implementation Ahmed Sayed Mousse 2022-04-29 14:20 ` Jakub Jelinek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).