-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-dl.c
71 lines (48 loc) · 1.3 KB
/
main-dl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include "utils.h"
#include "init.h"
#include "global.h"
#ifdef NVIDIA
#include "nvidia.h"
#endif
//to disable THP
#include <sys/prctl.h>
scilib_freplace scilib_farray[] = {
INIT_FARRAY
};
int scilib_fsize = sizeof(scilib_farray) / sizeof(scilib_farray[0]);
char *exe_path;
int scilib_skip_flag;
void scilib_elf_init(){
get_exe_path(&exe_path);
scilib_skip_flag = check_string(exe_path);
scilib_init();
if (scilib_thpoff == 1)
prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
#ifdef NVIDIA
scilib_nvidia_init();
#endif
// register functions
for( int i=0; i< scilib_fsize; i++) {
scilib_farray[i].fptr= dlsym(RTLD_NEXT, scilib_farray[i].f0);
}
return;
}
void scilib_elf_fini(){
#ifdef NVIDIA
scilib_nvidia_fini();
#endif
for( int i=0; i< scilib_fsize; i++) {
if(scilib_farray[i].t0 > 1e-7)
fprintf(stderr, "%10s time: total= %15.6f, compute= %15.6f, other= %15.6f\n", scilib_farray[i].f0, scilib_farray[i].t0, scilib_farray[i].t1, scilib_farray[i].t0-scilib_farray[i].t1) ;
}
fflush(stderr);
fflush(stdout);
return;
}
__attribute__((section(".init_array"))) void *__init = scilib_elf_init;
__attribute__((section(".fini_array"))) void *__fini = scilib_elf_fini;