rewrite add and sub for generic.

This commit is contained in:
Zhang Xianyi 2015-01-07 17:35:37 +08:00
parent 15580f4a86
commit ed26fc047c
13 changed files with 124 additions and 40 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@
*~
lib.grd
nohup.out
build/

View File

@ -11,6 +11,9 @@ set (OpenVML_VERSION_PATCH 1)
set (OpenVML_ARCH "generic")
set (OpenVML_CPU_CORENAME "generic")
set (OpenVML_FUNC_PREFIX "")
set (OpenVML_FUNC_SUFFIX "")
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_BINARY_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/include")
@ -21,7 +24,6 @@ configure_file (
)
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(OpenVML_LIBSRC_S "")
@ -32,9 +34,36 @@ set(OpenVML_LIBSRC_OTHER "")
#define -DDOUBLE for double precision
set(OpenVML_S_DEFINITIONS "")
set(OpenVML_D_DEFINITIONS "DOUBLE")
set(OpenVML_C_DEFINITIONS "COMPLEX")
set(OpenVML_Z_DEFINITIONS "COMPLEX DOUBLE")
set(OpenVML_D_DEFINITIONS DOUBLE)
set(OpenVML_C_DEFINITIONS COMPLEX)
set(OpenVML_Z_DEFINITIONS COMPLEX DOUBLE)
##########################################################
# For RPATH http://www.cmake.org/Wiki/CMake_RPATH_handling
#
set(CMAKE_MACOSX_RPATH 1)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
##########################################################
add_subdirectory(interface)
add_subdirectory(kernel)
@ -72,3 +101,4 @@ install(FILES ${PROJECT_BINARY_DIR}/openvml_export.h DESTINATION include)
install(FILES ${PROJECT_BINARY_DIR}/include/openvml_config.h DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/include/openvml.h DESTINATION include)
install(FILES ${PROJECT_SOURCE_DIR}/include/openvml_common.h DESTINATION include)

View File

@ -8,11 +8,11 @@
extern "C" {
#endif
OPENVML_EXPORT void vsAdd(VML_INT n, const float * a, const float * b, float * y);
OPENVML_EXPORT void vdAdd(VML_INT n, const double * a, const double * b, double * y);
OPENVML_EXPORT void OpenVML_FUNCNAME(vsAdd)(VML_INT n, const float * a, const float * b, float * y);
OPENVML_EXPORT void OpenVML_FUNCNAME(vdAdd)(VML_INT n, const double * a, const double * b, double * y);
OPENVML_EXPORT void vsSub(VML_INT n, const float * a, const float * b, float * y);
OPENVML_EXPORT void vdSub(VML_INT n, const double * a, const double * b, double * y);
OPENVML_EXPORT void OpenVML_FUNCNAME(vsSub)(VML_INT n, const float * a, const float * b, float * y);
OPENVML_EXPORT void OpenVML_FUNCNAME(vdSub)(VML_INT n, const double * a, const double * b, double * y);
#ifdef __cplusplus
}

View File

@ -3,6 +3,12 @@
#include "openvml_config.h"
#ifdef DOUBLE
typedef double VML_FLOAT;
#else
typedef float VML_FLOAT;
#endif
#if defined(OS_WINDOWS) && defined(__64BIT__)
typedef long long VMLLONG;
typedef unsigned long long VMLULONG;
@ -17,4 +23,9 @@ typedef VMLLONG VML_INT;
typedef int VML_INT;
#endif
#define OpenVML_FUNCNAME_3(pre,x,suf) pre##x##suf
#define OpenVML_FUNCNAME_2(pre,x,suf) OpenVML_FUNCNAME_3(pre, x, suf)
#define OpenVML_FUNCNAME_1(x) OpenVML_FUNCNAME_2(OPENVML_FUNC_PREFIX, x, OPENVML_FUNC_SUFFIX)
#define OpenVML_FUNCNAME(x) OpenVML_FUNCNAME_1(x)
#endif

View File

@ -2,6 +2,9 @@
#define OPENVML_VERSION_MINOR @OpenVML_VERSION_MINOR@
#define OPENVML_VERSION_PATCH @OpenVML_VERSION_PATCH@
#define OPENVML_FUNC_PREFIX @OpenVML_FUNC_PREFIX@
#define OPENVML_FUNC_SUFFIX @OpenVML_FUNC_SUFFIX@
#cmakedefine USE64BITINT
#cmakedefine __64BIT__
#cmakedefine OS_WINDOWS

View File

@ -2,8 +2,12 @@
#define _OPENVML_KERNEL_H_
#include "openvml_common.h"
#include "openvml_macros.h"
void sadd_k(VMLLONG n, float * a, float * b, float * y);
void dadd_k(VMLLONG n, float * a, float * b, float * y);
void OpenVML_FUNCNAME(sadd_k)(VMLLONG n, float * a, float * b, float * y);
void OpenVML_FUNCNAME(dadd_k)(VMLLONG n, double * a, double * b, double * y);
void OpenVML_FUNCNAME(ssub_k)(VMLLONG n, float * a, float * b, float * y);
void OpenVML_FUNCNAME(dsub_k)(VMLLONG n, double * a, double * b, double * y);
#endif

View File

@ -1,24 +1,35 @@
#ifndef _OPENVML_MACROS_H_
#define _OPENVML_MACROS_H_
#define SADD_K sadd_k
#define SADD_K OpenVML_FUNCNAME(sadd_k)
#define DADD_K OpenVML_FUNCNAME(dadd_k)
//reuse
#define CADD_K OpenVML_FUNCNAME(sadd_k)
#define ZADD_K OpenVML_FUNCNAME(dadd_k)
#define DADD_K dadd_k
#define SSUB_K OpenVML_FUNCNAME(ssub_k)
#define DSUB_K OpenVML_FUNCNAME(dsub_k)
//reuse
#define CSUB_K OpenVML_FUNCNAME(ssub_k)
#define ZSUB_K OpenVML_FUNCNAME(dsub_k)
#ifndef COMPLEX
#ifndef DOUBLE
#define ADD_K SADD_K
#define SUB_K SSUB_K
#else
#define ADD_K DADD_K
#define SUB_K DSUB_K
#endif
#else
#ifndef DOUBLE
#define ADD_K CADD_K
#define SUB_K CSUB_K
#else
#define ADD_K ZADD_K
#define SUB_K CSUB_K
#endif
#endif

View File

@ -8,6 +8,13 @@ set(OpenVML_LIBSRC_Z "")
set(REAL_INTERFACE_LIST add sub)
set(COMPLEX_INTERFACE_LIST add sub)
function(cap_string var_name var_name_cap)
string(SUBSTRING ${var_name} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" PROTO_NAME_CAP "${var_name}")
set(${var_name_cap} ${PROTO_NAME_CAP} PARENT_SCOPE)
endfunction()
foreach(INTERFACE ${REAL_INTERFACE_LIST})
set(OpenVML_LIBSRC_S
@ -20,6 +27,18 @@ foreach(INTERFACE ${REAL_INTERFACE_LIST})
${CMAKE_CURRENT_BINARY_DIR}/${INTERFACE}_d.c
)
set(OpenVML_INTERFACE_NAME "")
cap_string(${INTERFACE} OpenVML_INTERFACE_NAME)
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${INTERFACE}.c
APPEND
PROPERTY COMPILE_DEFINITIONS ${OpenVML_S_DEFINITIONS} )
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${INTERFACE}.c
APPEND
PROPERTY COMPILE_DEFINITIONS CNAME=${OpenVML_FUNC_PREFIX}vs${OpenVML_INTERFACE_NAME}${OpenVML_FUNC_SUFFIX} )
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${INTERFACE}_d.c
DEPENDS ${INTERFACE}.c
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${INTERFACE}.c ${CMAKE_CURRENT_BINARY_DIR}/${INTERFACE}_d.c
@ -29,6 +48,10 @@ foreach(INTERFACE ${REAL_INTERFACE_LIST})
APPEND
PROPERTY COMPILE_DEFINITIONS ${OpenVML_D_DEFINITIONS} )
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${INTERFACE}_d.c
APPEND
PROPERTY COMPILE_DEFINITIONS CNAME=${OpenVML_FUNC_PREFIX}vd${OpenVML_INTERFACE_NAME}${OpenVML_FUNC_SUFFIX} )
endforeach(INTERFACE)
add_library(openvml_interface_core OBJECT ${OpenVML_LIBSRC_S} ${OpenVML_LIBSRC_D} ${OpenVML_LIBSRC_C} ${OpenVML_LIBSRC_Z} ${OpenVML_LIBSRC_OTHER})

View File

@ -1,12 +1,10 @@
#include <openvml.h>
#include <openvml_kernel.h>
#include <stdio.h>
#ifndef DOUBLE
void vsAdd(VML_INT n, const float * a, const float * b, float * y) {
#else
void vdAdd(VML_INT n, const double * a, const double * b, double * y) {
#endif
void CNAME(VML_INT n, const VML_FLOAT * a, const VML_FLOAT * b, VML_FLOAT * y) {
if (n<=0) return;
ADD_K(n, (VML_FLOAT*)a, (VML_FLOAT*)b, y);
printf("%s", __func__);
}

View File

@ -1,12 +1,10 @@
#include <openvml.h>
#include <openvml_kernel.h>
#include <stdio.h>
#ifndef DOUBLE
void vsSub(VML_INT n, const float * a, const float * b, float * y) {
#else
void vdSub(VML_INT n, const double * a, const double * b, double * y) {
#endif
void CNAME(VML_INT n, const VML_FLOAT * a, const VML_FLOAT * b, VML_FLOAT * y) {
if(n<=0) return;
SUB_K(n, (VML_FLOAT*)a, (VML_FLOAT *)b, y);
printf("%s", __func__);
}

View File

@ -32,6 +32,10 @@ foreach(KERNEL ${KERNEL_LIST})
APPEND
PROPERTY COMPILE_DEFINITIONS ${OpenVML_S_DEFINITIONS} )
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${KERNEL}_kernel_s_${OpenVML_ARCH}_${OpenVML_CPU_CORENAME}.c
APPEND
PROPERTY COMPILE_DEFINITIONS KERNEL_NAME=${OpenVML_FUNC_PREFIX}s${KERNEL}_k${OpenVML_FUNC_SUFFIX} )
set(D_KERNEL_SOURCE ${${KERNEL}_D_KERNEL_SOURCE})
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${KERNEL}_kernel_d_${OpenVML_ARCH}_${OpenVML_CPU_CORENAME}.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${D_KERNEL_SOURCE}
@ -42,6 +46,10 @@ foreach(KERNEL ${KERNEL_LIST})
APPEND
PROPERTY COMPILE_DEFINITIONS ${OpenVML_D_DEFINITIONS} )
set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${KERNEL}_kernel_d_${OpenVML_ARCH}_${OpenVML_CPU_CORENAME}.c
APPEND
PROPERTY COMPILE_DEFINITIONS KERNEL_NAME=${OpenVML_FUNC_PREFIX}d${KERNEL}_k${OpenVML_FUNC_SUFFIX})
endforeach(KERNEL)
add_library(openvml_kernel_${OpenVML_ARCH}_${OpenVML_CPU_CORENAME}_core OBJECT ${OpenVML_LIBSRC_S} ${OpenVML_LIBSRC_D} ${OpenVML_LIBSRC_C} ${OpenVML_LIBSRC_Z})

View File

@ -1,10 +1,9 @@
#include "openvml_kernel.h"
#ifndef DOUBLE
void sadd_k(VMLLONG n, float * a, float * b, float * y) {
#else
void dadd_k(VMLLONG n, float * a, float * b, float * y) {
#endif
void KERNEL_NAME(VMLLONG n, VML_FLOAT * a, VML_FLOAT * b, VML_FLOAT * y) {
VMLLONG i=0;
for(i=0; i<n; i++){
y[i]=a[i]+b[i];
}
}

View File

@ -1,10 +1,8 @@
#include "openvml_kernel.h"
#ifndef DOUBLE
void ssub_k(VMLLONG n, float * a, float * b, float * y) {
#else
void dsub_k(VMLLONG n, float * a, float * b, float * y) {
#endif
void KERNEL_NAME(VMLLONG n, VML_FLOAT * a, VML_FLOAT * b, VML_FLOAT * y) {
VMLLONG i=0;
for(i=0; i<n; i++){
y[i]=a[i]-b[i];
}
}