OpenRadioss
2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
get_ibuiltin_arch.c
Go to the documentation of this file.
1
//Copyright> OpenRadioss
2
//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3
//Copyright>
4
//Copyright> This program is free software: you can redistribute it and/or modify
5
//Copyright> it under the terms of the GNU Affero General Public License as published by
6
//Copyright> the Free Software Foundation, either version 3 of the License, or
7
//Copyright> (at your option) any later version.
8
//Copyright>
9
//Copyright> This program is distributed in the hope that it will be useful,
10
//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11
//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
//Copyright> GNU Affero General Public License for more details.
13
//Copyright>
14
//Copyright> You should have received a copy of the GNU Affero General Public License
15
//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16
//Copyright>
17
//Copyright>
18
//Copyright> Commercial Alternative: Altair Radioss Software
19
//Copyright>
20
//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21
//Copyright> software under a commercial license. Contact Altair to discuss further if the
22
//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
27
#define _FCALL
28
29
30
/* Define
31
ARCH_TYPE HW target
32
ARCH_TYPE=1 X86-64
33
ARCH_TYPE=2 ARM64
34
35
OS_TYPE Linux or Windows
36
OS_TYPE=1 Linux
37
OS_TYPE=2 Windows
38
39
40
*/
41
42
43
/* ---------------- */
44
/* Define ARCH_TYPE */
45
/* ---------------- */
46
#ifdef __unix
47
48
#ifdef __x86_64
49
#define ARCH_TYPE 1
50
#endif
51
52
#ifdef __ARM_ARCH
53
#define ARCH_TYPE 2
54
#endif
55
56
#endif
57
58
#ifdef _WIN64
59
#define ARCH_TYPE 1
60
#endif
61
62
/* ---------------- */
63
/* Define ARCH_TYPE */
64
/* ---------------- */
65
66
#ifdef __unix
67
#define OS_TYPE 1
68
#endif
69
70
#ifdef _WIN64
71
#define OS_TYPE 2
72
#endif
73
74
int
parse_cpuinfo
();
75
76
77
/* --------------------------------------------------
78
get_ibuiltin_arch()
79
routine to find the underlying CPU/OS architecture
80
to apply proper Domain Decomposition optimization
81
82
0 - X86-64 Linux AVX-2
83
1 - X86-64 Linux AVX-512
84
2 - X86-64 Linux SSE3
85
3 - ARM64 Linux
86
4 - X86-64 Windows AVX-2
87
-------------------------------------------------- */
88
89
void
get_ibuiltin_arch
(
int
*iarch)
90
{
91
int
os_type,arch_type;
92
93
os_type=OS_TYPE;
94
arch_type=ARCH_TYPE;
95
96
*iarch=0;
97
switch
(arch_type){
98
case
1 : {
if
(os_type==1){
99
*iarch=
parse_cpuinfo
();
100
}
else
{
101
*iarch= 4;
102
}
103
}
104
break
;
105
106
case
2 : *iarch=3;
break
;
107
}
108
109
110
}
111
112
void
get_ibuiltin_arch_
(
int
*iarch){
113
get_ibuiltin_arch
(iarch);
114
}
115
116
void
_FCALL
GET_IBUILTIN_ARCH
(
int
*iarch){
117
get_ibuiltin_arch
(iarch);
118
}
119
120
int
parse_cpuinfo
(){
121
122
FILE * stream = NULL;
123
char
ligne[2049];
124
char
* compstr=
"flags :"
;
125
char
* strptr;
126
int
unknown;
127
int
cmplen=strlen(compstr);
128
129
int
instruction_set=0;
130
131
stream=fopen(
"/proc/cpuinfo"
,
"r"
);
132
unknown = 1;
133
while
(fgets(ligne,2048,stream) && unknown){
134
if
(strncmp(compstr,ligne,cmplen)==0){
135
unknown = 0;
136
break
;
137
}
138
}
139
strptr = strstr(ligne,
"avx512"
);
140
141
if
(strptr !=NULL){
142
instruction_set=1;
143
}
else
{
144
strptr = strstr(ligne,
"avx2"
);
145
if
(strptr !=NULL){
146
instruction_set=0;
147
}
else
{
148
instruction_set=2;
149
}
150
}
151
152
153
return
instruction_set;
154
}
155
156
#ifdef MAIN
157
158
int
main
()
159
{
160
161
int
iflag;
162
get_ibuiltin_arch
(&iflag);
163
164
printf(
"\nArchitecture Found= %i\n\n"
,iflag);
165
166
return
1;
167
168
}
169
#endif
main
int main()
Definition
cblas_example1.c:7
GET_IBUILTIN_ARCH
void _FCALL GET_IBUILTIN_ARCH(int *iarch)
Definition
get_ibuiltin_arch.c:116
get_ibuiltin_arch
void get_ibuiltin_arch(int *iarch)
Definition
get_ibuiltin_arch.c:89
parse_cpuinfo
int parse_cpuinfo()
Definition
get_ibuiltin_arch.c:120
get_ibuiltin_arch_
void get_ibuiltin_arch_(int *iarch)
Definition
get_ibuiltin_arch.c:112
_FCALL
#define _FCALL
Definition
memory_use_c.c:25
starter
source
system
get_ibuiltin_arch.c
Generated by
1.15.0