HPCToolkit
papi-c-cupti.c File Reference
#include <ucontext.h>
#include <dlfcn.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <papi.h>
#include <monitor.h>
#include <cuda_runtime_api.h>
#include <cupti.h>
#include <lib/prof-lean/spinlock.h>
#include <hpcrun/thread_data.h>
#include <messages/messages.h>
#include <hpcrun/sample_event.h>
#include <hpcrun/safe-sampling.h>
#include <hpcrun/sample_sources_all.h>
#include <sample-sources/common.h>
#include <sample-sources/ss-obj-name.h>
#include "papi-c.h"
#include "papi-c-extended-info.h"
Include dependency graph for papi-c-cupti.c:

Go to the source code of this file.

Classes

struct  papi_cuda_data_t
 
struct  cuda_callback_t
 

Macros

#define CUPTI_LAUNCH_CALLBACK_DEPTH   7
 
#define Cupti_call(fn, ...)
 
#define Cupti_call_silent(fn, ...)
 
#define Chk_dlopen(v, lib, flags)
 
#define Chk_dlsym(h, fn)
 

Typedefs

typedef struct cuda_callback_t cuda_callback_t
 

Functions

static void dlgpu (void)
 
static void papi_c_no_action (void)
 
static bool is_papi_c_cuda (const char *name)
 
static void CUPTIAPI hpcrun_cuda_kernel_callback (void *userdata, CUpti_CallbackDomain domain, CUpti_CallbackId cbid, const CUpti_CallbackData *cbInfo)
 
static void papi_c_cupti_setup (void)
 
void papi_c_cupti_get_event_set (int *ev_s)
 
int papi_c_cupti_add_event (int ev_s, int ev)
 
void papi_c_cupti_finalize_event_set (void)
 
static void papi_c_cupti_teardown (void)
 
void SS_OBJ_CONSTRUCTOR() papi_c_cupti (void)
 

Variables

static bool event_set_created = false
 
static bool event_set_finalized = false
 
static papi_cuda_data_t local = {}
 
static spinlock_t cupti_lock = SPINLOCK_UNLOCKED
 
static spinlock_t setup_lock = SPINLOCK_UNLOCKED
 
cudaError_t(* dcudaThreadSynchronize )(void)
 
CUptiResult(* dcuptiGetResultString )(CUptiResult result, const char **str)
 
CUptiResult(* dcuptiSubscribe )(CUpti_SubscriberHandle *subscriber, CUpti_CallbackFunc callback, void *userdata)
 
CUptiResult(* dcuptiEnableCallback )(uint32_t enable, CUpti_SubscriberHandle subscriber, CUpti_CallbackDomain domain, CUpti_CallbackId cbid)
 
CUptiResult(* dcuptiUnsubscribe )(CUpti_SubscriberHandle subscriber)
 
static CUpti_SubscriberHandle subscriber
 
static sync_info_list_t cuda_component
 

Macro Definition Documentation

◆ Chk_dlopen

#define Chk_dlopen (   v,
  lib,
  flags 
)
Value:
void* v = monitor_real_dlopen(lib, flags); \
if (! v) { \
fprintf(stderr, "gpu dlopen %s failed\n", lib); \
return; \
} \

Definition at line 62 of file papi-c-cupti.c.

◆ Chk_dlsym

#define Chk_dlsym (   h,
  fn 
)
Value:
{ \
dlerror(); \
d ## fn = dlsym(h, #fn); \
char* e = dlerror(); \
if (e) { \
fprintf(stderr, "dlsym(%s) fails w '%s'\n", #fn, e); \
return; \
} \
}

Definition at line 69 of file papi-c-cupti.c.

◆ Cupti_call

#define Cupti_call (   fn,
  ... 
)
Value:
{ \
int ret = fn(__VA_ARGS__); \
if (ret != CUPTI_SUCCESS) { \
const char* errstr; \
dcuptiGetResultString(ret, &errstr); \
hpcrun_abort("error: CUDA/CUPTI API " \
#fn " failed w error code %d ==> '%s'\n", \
ret, errstr); \
} \
}

Definition at line 45 of file papi-c-cupti.c.

◆ Cupti_call_silent

#define Cupti_call_silent (   fn,
  ... 
)
Value:
{ \
(void) fn(__VA_ARGS__); \
}

Definition at line 57 of file papi-c-cupti.c.

◆ CUPTI_LAUNCH_CALLBACK_DEPTH

#define CUPTI_LAUNCH_CALLBACK_DEPTH   7

Definition at line 43 of file papi-c-cupti.c.

Typedef Documentation

◆ cuda_callback_t

Function Documentation

◆ dlgpu()

static void dlgpu ( void  )
static

Definition at line 126 of file papi-c-cupti.c.

Here is the caller graph for this function:

◆ hpcrun_cuda_kernel_callback()

static void CUPTIAPI hpcrun_cuda_kernel_callback ( void *  userdata,
CUpti_CallbackDomain  domain,
CUpti_CallbackId  cbid,
const CUpti_CallbackData *  cbInfo 
)
static

Definition at line 160 of file papi-c-cupti.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_papi_c_cuda()

static bool is_papi_c_cuda ( const char *  name)
static

Definition at line 154 of file papi-c-cupti.c.

Here is the caller graph for this function:

◆ papi_c_cupti()

void SS_OBJ_CONSTRUCTOR() papi_c_cupti ( void  )

Definition at line 382 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_cupti_add_event()

int papi_c_cupti_add_event ( int  ev_s,
int  ev 
)

Definition at line 325 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_cupti_finalize_event_set()

void papi_c_cupti_finalize_event_set ( void  )

Definition at line 342 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_cupti_get_event_set()

void papi_c_cupti_get_event_set ( int *  ev_s)

Definition at line 304 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_cupti_setup()

static void papi_c_cupti_setup ( void  )
static

Definition at line 250 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_cupti_teardown()

static void papi_c_cupti_teardown ( void  )
static

Definition at line 354 of file papi-c-cupti.c.

Here is the call graph for this function:

◆ papi_c_no_action()

static void papi_c_no_action ( void  )
static

Definition at line 145 of file papi-c-cupti.c.

Variable Documentation

◆ cuda_component

sync_info_list_t cuda_component
static
Initial value:
= {
.pred = is_papi_c_cuda,
.get_event_set = papi_c_cupti_get_event_set,
.add_event = papi_c_cupti_add_event,
.finalize_event_set = papi_c_cupti_finalize_event_set,
.sync_setup = papi_c_cupti_setup,
.sync_teardown = papi_c_cupti_teardown,
.sync_start = papi_c_no_action,
.sync_stop = papi_c_no_action,
.process_only = true,
.next = NULL,
}
static void papi_c_no_action(void)
Definition: papi-c-cupti.c:145
static void papi_c_cupti_teardown(void)
Definition: papi-c-cupti.c:354
static void papi_c_cupti_setup(void)
Definition: papi-c-cupti.c:250
void papi_c_cupti_get_event_set(int *ev_s)
Definition: papi-c-cupti.c:304
int papi_c_cupti_add_event(int ev_s, int ev)
Definition: papi-c-cupti.c:325
#define NULL
Definition: ElfHelper.cpp:85
void papi_c_cupti_finalize_event_set(void)
Definition: papi-c-cupti.c:342
static bool is_papi_c_cuda(const char *name)
Definition: papi-c-cupti.c:154

Definition at line 367 of file papi-c-cupti.c.

◆ cupti_lock

spinlock_t cupti_lock = SPINLOCK_UNLOCKED
static

Definition at line 91 of file papi-c-cupti.c.

◆ dcudaThreadSynchronize

cudaError_t(* dcudaThreadSynchronize) (void)

Definition at line 99 of file papi-c-cupti.c.

◆ dcuptiEnableCallback

CUptiResult(* dcuptiEnableCallback) (uint32_t enable, CUpti_SubscriberHandle subscriber, CUpti_CallbackDomain domain, CUpti_CallbackId cbid)

Definition at line 107 of file papi-c-cupti.c.

◆ dcuptiGetResultString

CUptiResult(* dcuptiGetResultString) (CUptiResult result, const char **str)

Definition at line 101 of file papi-c-cupti.c.

◆ dcuptiSubscribe

CUptiResult(* dcuptiSubscribe) (CUpti_SubscriberHandle *subscriber, CUpti_CallbackFunc callback, void *userdata)

Definition at line 103 of file papi-c-cupti.c.

◆ dcuptiUnsubscribe

CUptiResult(* dcuptiUnsubscribe) (CUpti_SubscriberHandle subscriber)

Definition at line 112 of file papi-c-cupti.c.

◆ event_set_created

bool event_set_created = false
static

Definition at line 86 of file papi-c-cupti.c.

◆ event_set_finalized

bool event_set_finalized = false
static

Definition at line 87 of file papi-c-cupti.c.

◆ local

papi_cuda_data_t local = {}
static

Definition at line 89 of file papi-c-cupti.c.

◆ setup_lock

spinlock_t setup_lock = SPINLOCK_UNLOCKED
static

Definition at line 92 of file papi-c-cupti.c.

◆ subscriber

CUpti_SubscriberHandle subscriber
static

Definition at line 244 of file papi-c-cupti.c.