Add ARM and AARCH64 config.

This commit is contained in:
Zhang Xianyi 2015-05-01 20:24:07 +00:00
parent 2ed622c582
commit b9a4068eef
8 changed files with 201 additions and 2 deletions

View File

@ -31,6 +31,17 @@ int main()
printf("x86_64");
return 0;
#endif
#if defined(__arm__) || defined(_M_ARM) || (__TARGET_ARCH_ARM)
printf("arm");
return 0;
#endif
#if defined(__aarch64__)
printf("aarch64");
return 0;
#endif
//default
printf("generic");
return 0;

View File

@ -31,6 +31,17 @@ try_run(cpu_detect_result cpu_detect_compile_result
#endif()
endif()
#For ARM 32-bit
if(OpenVML_ARCH STREQUAL "arm")
try_run(cpu_detect_result cpu_detect_compile_result
${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/cpuid_arm.c
COMPILE_DEFINITIONS ${OpenVML_CPU_DETECT_FLAGS}
RUN_OUTPUT_VARIABLE cpu_detect_output
COMPILE_OUTPUT_VARIABLE cpu_detect_compile_output
)
endif()
if(cpu_detect_compile_result)
if(cpu_detect_result EQUAL 0)
set (OpenVML_CPU_CORENAME ${cpu_detect_output})
@ -38,8 +49,8 @@ else()
message("${cpu_detect_output}")
endif()
else()
message("detect compile error")
message("${cpu_detect_compile_output}")
#message("detect compile error")
#message("${cpu_detect_compile_output}")
endif()

136
cmake/cpuid_arm.c Normal file
View File

@ -0,0 +1,136 @@
/* * Copyright (c) 2014, 2015 Zhang Xianyi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#define CPUNAME_GENERIC 0
#define CPUNAME_ARMV7 1
#define CPUNAME_CORTEXA9 2
#define CPUNAME_CORTEXA15 3
static char *cpuname[] = {
"generic",
"armv7a",
"cortexa9",
"cortexa15",
};
int get_feature(char *search)
{
FILE *infile;
char buffer[2048], *p,*t;
p = (char *) NULL;
infile = fopen("/proc/cpuinfo", "r");
if (infile == NULL) {
return 0;
}
while (fgets(buffer, sizeof(buffer), infile)) {
if (!strncmp("Features", buffer, 8)) {
p = strchr(buffer, ':') + 2;
break;
}
}
fclose(infile);
if( p == NULL ) return 0;
t = strtok(p," ");
if (t != NULL) {
if (!strcmp(t, search)) { return 1; }
}
while( t = strtok(NULL," ")){
if (!strcmp(t, search)) { return 1; }
}
return 0;
}
int cpu_detect(void)
{
FILE *infile;
char buffer[512], *p;
p = (char *) NULL ;
infile = fopen("/proc/cpuinfo", "r");
if (infile == NULL) {
return CPUNAME_GENERIC;
}
while (fgets(buffer, sizeof(buffer), infile)) {
if (!strncmp("CPU part", buffer, 8)) {
p = strchr(buffer, ':') + 2;
break;
}
}
fclose(infile);
if(p != NULL) {
if (strstr(p, "0xc09")) {
if(get_feature("neon"))
return CPUNAME_CORTEXA9;
else
return CPUNAME_ARMV7;
}
if (strstr(p, "0xc0f")) {
if(get_feature("neon"))
return CPUNAME_CORTEXA15;
else
return CPUNAME_ARMV7;
}
}
p = (char *) NULL ;
infile = fopen("/proc/cpuinfo", "r");
if (infile == NULL) {
return CPUNAME_GENERIC;
}
while (fgets(buffer, sizeof(buffer), infile)) {
if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9))) {
p = strchr(buffer, ':') + 2;
break;
}
}
fclose(infile);
if(p != NULL) {
if (strstr(p, "ARMv7")) {
return CPUNAME_ARMV7;
}
}
return CPUNAME_GENERIC;
}
int main()
{
int cpuname_id;
cpuname_id=cpu_detect();
printf("%s", cpuname[cpuname_id]);
return 0;
}

View File

@ -0,0 +1,19 @@
set(add_S_KERNEL_SOURCE generic/add_kernel.c)
set(add_D_KERNEL_SOURCE generic/add_kernel.c)
set(add_C_KERNEL_SOURCE generic/add_kernel.c)
set(add_Z_KERNEL_SOURCE generic/add_kernel.c)
set(sub_S_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_D_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_C_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c)
set(pow_S_KERNEL_SOURCE generic/pow_kernel.c)
set(pow_D_KERNEL_SOURCE generic/pow_kernel.c)
set(exp_S_KERNEL_SOURCE generic/exp_kernel.c)
set(exp_D_KERNEL_SOURCE generic/exp_kernel.c)
set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c)
set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c)

View File

@ -0,0 +1 @@
include(${OpenVML_ARCH}/Kernel_generic.txt)

View File

@ -0,0 +1 @@
include(${OpenVML_ARCH}/Kernel_generic.txt)

View File

@ -0,0 +1 @@
include(${OpenVML_ARCH}/Kernel_generic.txt)

View File

@ -0,0 +1,19 @@
set(add_S_KERNEL_SOURCE generic/add_kernel.c)
set(add_D_KERNEL_SOURCE generic/add_kernel.c)
set(add_C_KERNEL_SOURCE generic/add_kernel.c)
set(add_Z_KERNEL_SOURCE generic/add_kernel.c)
set(sub_S_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_D_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_C_KERNEL_SOURCE generic/sub_kernel.c)
set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c)
set(pow_S_KERNEL_SOURCE generic/pow_kernel.c)
set(pow_D_KERNEL_SOURCE generic/pow_kernel.c)
set(exp_S_KERNEL_SOURCE generic/exp_kernel.c)
set(exp_D_KERNEL_SOURCE generic/exp_kernel.c)
set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c)
set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c)