-
Notifications
You must be signed in to change notification settings - Fork 434
/
Copy pathinit.c
142 lines (131 loc) · 3.95 KB
/
init.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2001-2014. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ucs/sys/compiler.h>
#include <ucs/sys/module.h>
#include <ucs/arch/cpu.h>
#include <ucs/config/parser.h>
#include <ucs/config/ucm_opts.h>
#include <ucs/debug/debug_int.h>
#include <ucs/debug/log.h>
#include <ucs/debug/memtrack_int.h>
#include <ucs/profile/profile.h>
#include <ucs/memory/memtype_cache.h>
#include <ucs/memory/numa.h>
#include <ucs/stats/stats.h>
#include <ucs/async/async.h>
#include <ucs/sys/lib.h>
#include <ucs/sys/sys.h>
#include <ucs/sys/topo/base/topo.h>
#include <ucs/sys/math.h>
/* run-time CPU detection */
static UCS_F_NOOPTIMIZE void ucs_check_cpu_flags(void)
{
char str[256];
char *p_str;
int cpu_flags;
struct {
const char* flag;
ucs_cpu_flag_t value;
} *p_flags,
cpu_flags_array[] = {
{ "cmov", UCS_CPU_FLAG_CMOV },
{ "mmx", UCS_CPU_FLAG_MMX },
{ "mmx2", UCS_CPU_FLAG_MMX2 },
{ "sse", UCS_CPU_FLAG_SSE },
{ "sse2", UCS_CPU_FLAG_SSE2 },
{ "sse3", UCS_CPU_FLAG_SSE3 },
{ "ssse3", UCS_CPU_FLAG_SSSE3 },
{ "sse41", UCS_CPU_FLAG_SSE41 },
{ "sse42", UCS_CPU_FLAG_SSE42 },
{ "avx", UCS_CPU_FLAG_AVX },
{ "avx2", UCS_CPU_FLAG_AVX2 },
{ NULL, UCS_CPU_FLAG_UNKNOWN },
};
cpu_flags = ucs_arch_get_cpu_flag();
if (UCS_CPU_FLAG_UNKNOWN == cpu_flags) {
return ;
}
strncpy(str, UCS_PP_MAKE_STRING(CPU_FLAGS), sizeof(str) - 1);
p_str = strtok(str, " |\t\n\r");
while (p_str) {
p_flags = cpu_flags_array;
while (p_flags && p_flags->flag) {
if (!strcmp(p_str, p_flags->flag)) {
if (!(cpu_flags & p_flags->value)) {
fprintf(stderr, "[%s:%d] FATAL: UCX library was compiled with %s"
" but CPU does not support it.\n",
ucs_get_host_name(), getpid(), p_flags->flag);
exit(1);
}
break;
}
p_flags++;
}
if (NULL == p_flags->flag) {
fprintf(stderr, "[%s:%d] FATAL: UCX library was compiled with %s"
" but CPU does not support it.\n",
ucs_get_host_name(), getpid(), p_str);
exit(1);
}
p_str = strtok(NULL, " |\t\n\r");
}
}
static void ucs_modules_load()
{
UCS_MODULE_FRAMEWORK_DECLARE(ucs);
UCS_MODULE_FRAMEWORK_LOAD(ucs, UCS_MODULE_LOAD_FLAG_GLOBAL);
}
void UCS_F_CTOR ucs_init()
{
ucs_status_t status;
ucs_check_cpu_flags();
ucs_log_early_init(); /* Must be called before all others */
ucs_global_opts_init();
ucs_init_ucm_opts();
ucs_memtype_cache_global_init();
ucs_cpu_init();
ucs_log_init();
#ifdef ENABLE_STATS
ucs_stats_init();
#endif
ucs_memtrack_init();
ucs_debug_init();
status = ucs_profile_init(ucs_global_opts.profile_mode,
ucs_global_opts.profile_file,
ucs_global_opts.profile_log_size,
&ucs_profile_default_ctx);
if (status != UCS_OK) {
ucs_fatal("failed to init ucs profile - aborting");
}
ucs_async_global_init();
ucs_numa_init();
ucs_topo_init();
ucs_rand_seed_init();
ucs_debug("%s loaded at 0x%lx", ucs_sys_get_lib_path(),
ucs_sys_get_lib_base_addr());
ucs_debug("cmd line: %s", ucs_get_process_cmdline());
ucs_modules_load();
}
static void UCS_F_DTOR ucs_cleanup(void)
{
ucs_topo_cleanup();
ucs_numa_cleanup();
ucs_async_global_cleanup();
ucs_profile_cleanup(ucs_profile_default_ctx);
ucs_debug_cleanup(0);
ucs_config_parser_cleanup();
ucs_memtrack_cleanup();
#ifdef ENABLE_STATS
ucs_stats_cleanup();
#endif
ucs_memtype_cache_cleanup();
ucs_cleanup_ucm_opts();
ucs_global_opts_cleanup();
ucs_log_cleanup();
}