Skip to content

Commit b9a4068

Browse files
committed
Add ARM and AARCH64 config.
1 parent 2ed622c commit b9a4068

8 files changed

+201
-2
lines changed

cmake/arch_detect.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ int main()
3131
printf("x86_64");
3232
return 0;
3333
#endif
34+
35+
#if defined(__arm__) || defined(_M_ARM) || (__TARGET_ARCH_ARM)
36+
printf("arm");
37+
return 0;
38+
#endif
39+
40+
#if defined(__aarch64__)
41+
printf("aarch64");
42+
return 0;
43+
#endif
44+
3445
//default
3546
printf("generic");
3647
return 0;

cmake/auto_detect_cpu.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,26 @@ try_run(cpu_detect_result cpu_detect_compile_result
3131
#endif()
3232
endif()
3333

34+
35+
#For ARM 32-bit
36+
if(OpenVML_ARCH STREQUAL "arm")
37+
try_run(cpu_detect_result cpu_detect_compile_result
38+
${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/cpuid_arm.c
39+
COMPILE_DEFINITIONS ${OpenVML_CPU_DETECT_FLAGS}
40+
RUN_OUTPUT_VARIABLE cpu_detect_output
41+
COMPILE_OUTPUT_VARIABLE cpu_detect_compile_output
42+
)
43+
endif()
44+
3445
if(cpu_detect_compile_result)
3546
if(cpu_detect_result EQUAL 0)
3647
set (OpenVML_CPU_CORENAME ${cpu_detect_output})
3748
else()
3849
message("${cpu_detect_output}")
3950
endif()
4051
else()
41-
message("detect compile error")
42-
message("${cpu_detect_compile_output}")
52+
#message("detect compile error")
53+
#message("${cpu_detect_compile_output}")
4354
endif()
4455

4556

cmake/cpuid_arm.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/* * Copyright (c) 2014, 2015 Zhang Xianyi
2+
* All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without modification,
5+
* are permitted provided that the following conditions are met:
6+
*
7+
* * Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
*
10+
* * Redistributions in binary form must reproduce the above copyright notice, this
11+
* list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include <stdio.h>
27+
#include <string.h>
28+
29+
#define CPUNAME_GENERIC 0
30+
#define CPUNAME_ARMV7 1
31+
#define CPUNAME_CORTEXA9 2
32+
#define CPUNAME_CORTEXA15 3
33+
34+
static char *cpuname[] = {
35+
"generic",
36+
"armv7a",
37+
"cortexa9",
38+
"cortexa15",
39+
};
40+
41+
int get_feature(char *search)
42+
{
43+
FILE *infile;
44+
char buffer[2048], *p,*t;
45+
p = (char *) NULL;
46+
47+
infile = fopen("/proc/cpuinfo", "r");
48+
if (infile == NULL) {
49+
return 0;
50+
}
51+
52+
while (fgets(buffer, sizeof(buffer), infile)) {
53+
if (!strncmp("Features", buffer, 8)) {
54+
p = strchr(buffer, ':') + 2;
55+
break;
56+
}
57+
}
58+
fclose(infile);
59+
60+
if( p == NULL ) return 0;
61+
62+
t = strtok(p," ");
63+
if (t != NULL) {
64+
if (!strcmp(t, search)) { return 1; }
65+
}
66+
while( t = strtok(NULL," ")){
67+
if (!strcmp(t, search)) { return 1; }
68+
}
69+
70+
return 0;
71+
}
72+
73+
int cpu_detect(void)
74+
{
75+
FILE *infile;
76+
char buffer[512], *p;
77+
p = (char *) NULL ;
78+
79+
infile = fopen("/proc/cpuinfo", "r");
80+
if (infile == NULL) {
81+
return CPUNAME_GENERIC;
82+
}
83+
while (fgets(buffer, sizeof(buffer), infile)) {
84+
if (!strncmp("CPU part", buffer, 8)) {
85+
p = strchr(buffer, ':') + 2;
86+
break;
87+
}
88+
}
89+
fclose(infile);
90+
91+
if(p != NULL) {
92+
if (strstr(p, "0xc09")) {
93+
if(get_feature("neon"))
94+
return CPUNAME_CORTEXA9;
95+
else
96+
return CPUNAME_ARMV7;
97+
}
98+
if (strstr(p, "0xc0f")) {
99+
if(get_feature("neon"))
100+
return CPUNAME_CORTEXA15;
101+
else
102+
return CPUNAME_ARMV7;
103+
}
104+
}
105+
106+
p = (char *) NULL ;
107+
infile = fopen("/proc/cpuinfo", "r");
108+
if (infile == NULL) {
109+
return CPUNAME_GENERIC;
110+
}
111+
112+
while (fgets(buffer, sizeof(buffer), infile)) {
113+
if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9))) {
114+
p = strchr(buffer, ':') + 2;
115+
break;
116+
}
117+
}
118+
fclose(infile);
119+
120+
if(p != NULL) {
121+
if (strstr(p, "ARMv7")) {
122+
return CPUNAME_ARMV7;
123+
}
124+
}
125+
126+
return CPUNAME_GENERIC;
127+
}
128+
129+
int main()
130+
{
131+
int cpuname_id;
132+
133+
cpuname_id=cpu_detect();
134+
printf("%s", cpuname[cpuname_id]);
135+
return 0;
136+
}

kernel/aarch64/Kernel_generic.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(add_S_KERNEL_SOURCE generic/add_kernel.c)
2+
set(add_D_KERNEL_SOURCE generic/add_kernel.c)
3+
set(add_C_KERNEL_SOURCE generic/add_kernel.c)
4+
set(add_Z_KERNEL_SOURCE generic/add_kernel.c)
5+
6+
set(sub_S_KERNEL_SOURCE generic/sub_kernel.c)
7+
set(sub_D_KERNEL_SOURCE generic/sub_kernel.c)
8+
set(sub_C_KERNEL_SOURCE generic/sub_kernel.c)
9+
set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c)
10+
11+
set(pow_S_KERNEL_SOURCE generic/pow_kernel.c)
12+
set(pow_D_KERNEL_SOURCE generic/pow_kernel.c)
13+
14+
set(exp_S_KERNEL_SOURCE generic/exp_kernel.c)
15+
set(exp_D_KERNEL_SOURCE generic/exp_kernel.c)
16+
17+
set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c)
18+
set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c)
19+

kernel/arm/Kernel_armv7a.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${OpenVML_ARCH}/Kernel_generic.txt)

kernel/arm/Kernel_cortexa15.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${OpenVML_ARCH}/Kernel_generic.txt)

kernel/arm/Kernel_cortexa9.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${OpenVML_ARCH}/Kernel_generic.txt)

kernel/arm/Kernel_generic.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(add_S_KERNEL_SOURCE generic/add_kernel.c)
2+
set(add_D_KERNEL_SOURCE generic/add_kernel.c)
3+
set(add_C_KERNEL_SOURCE generic/add_kernel.c)
4+
set(add_Z_KERNEL_SOURCE generic/add_kernel.c)
5+
6+
set(sub_S_KERNEL_SOURCE generic/sub_kernel.c)
7+
set(sub_D_KERNEL_SOURCE generic/sub_kernel.c)
8+
set(sub_C_KERNEL_SOURCE generic/sub_kernel.c)
9+
set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c)
10+
11+
set(pow_S_KERNEL_SOURCE generic/pow_kernel.c)
12+
set(pow_D_KERNEL_SOURCE generic/pow_kernel.c)
13+
14+
set(exp_S_KERNEL_SOURCE generic/exp_kernel.c)
15+
set(exp_D_KERNEL_SOURCE generic/exp_kernel.c)
16+
17+
set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c)
18+
set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c)
19+

0 commit comments

Comments
 (0)