PAPI  5.7.0.0
gpu_activity.c File Reference
Include dependency graph for gpu_activity.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 22 of file gpu_activity.c.

22  {
23 
24 
25  int pid;
26  if(argc < 2){
27  printf("please supply Cuda app to be profiled \n");
28  exit(-1);
29  }
30 
31 
32  //get CUDA device ID and sampling rate from args
33  char *samp, *device;
34  extern char* optarg;
35  extern int optind;
36  int c,tmp,index;
37 
38  //set default samp and device
39  device="0";
40  samp="5";
41  index=1;
42  while((c=getopt(argc,argv,"d:s:"))!=-1){
43  switch(c){
44  case 'd':
45  device = optarg;
46  tmp=atoi(device);
47  index = optind;
48  if(tmp < 0){
49  printf("GPU device ID not valid \n");
50  exit(-1);
51  }
52  break;
53  case 's':
54  samp = optarg;
55  tmp=atoi(samp);
56  //record index for argument forming for cuda app
57  index = optind;
58  if(tmp < 0 || tmp > 5){
59  printf("PC sampling rate not valid \n");
60  exit(-1);
61  }
62  break;
63  case '?':
64  printf("Switch not recognized by papi_sampling_cuda utility \n");
65  break;
66  }
67  }
68 
69 
70  //form the arg list for the cuda app
71  char** var;
72  var=&argv[index];
73 
74 
75  char* ld_lib;
76  char env1[1024];
77  char env2[256];
78  char env3[256];
79  int status;
80 
81  //get the shared library load path
82  strcpy(env1,"LD_LIBRARY_PATH=");
83  ld_lib=getenv("LD_LIBRARY_PATH");
84  if(ld_lib == NULL){
85  printf("Error loading CUDA shared libraries: LD_LIBRARY_PATH=NULL \n");
86  exit(-1);
87  }
88  strcat(env1,ld_lib);
89 
90  strcpy(env2,"GPU_DEVICE_ID=");
91  strcat(env2,device);
92 
93  strcpy(env3,"PC_SAMPLING_RATE=");
94  strcat(env3,samp);
95 
96  //form the env variable
97  char* env[]={env1,env2,env3,ld_prld, NULL};
98 
99  printf("\n\n\n\n");
100  printf("***************** PAPI_SAMPLING_CUDA utility **********************\n");
101  pid=fork();
102  if(pid==0){
103  execve(var[0],var,env);
104  }else if(pid==-1){
105  printf("Profile fork failed \n");
106  exit(-1);
107  }else{
108  wait(&status);
109  }
110  return 0;
111 }
int atoi()
char * getenv()
double c
Definition: multiplex.c:22
double tmp
static int pid
int wait()
int optind
long long status
Definition: iozone.c:1335
void exit()
char * optarg
Here is the call graph for this function: