2019-06-06 14:21:15 +02:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
|
|
|
project(dev_tests)
|
|
|
|
message("Starting up tests build")
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake" ${CMAKE_MODULE_PATH})
|
|
|
|
|
|
|
|
# Download and unpack googletest at configure time
|
|
|
|
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# OPTIONAL MKL-DNN
|
|
|
|
if ("${BUILD_MKLDNN}")
|
|
|
|
# Download and unpack mkl-dnn at configure time
|
2019-09-11 20:50:28 +02:00
|
|
|
configure_file(../../CMakeLists.txt.mkldnn.in mkldnn-download/CMakeLists.txt)
|
2019-06-06 14:21:15 +02:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mkldnn-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "CMake step for mkldnn failed: ${result}")
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mkldnn-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "Build step for mkldnn failed: ${result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/mkldnn-src
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/mkldnn-build
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
set(mkldnn_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/mkldnn-src)
|
|
|
|
set(HAVE_MKLDNN 1)
|
2019-09-11 20:50:28 +02:00
|
|
|
add_definitions("-DHAVE_MKLDNN")
|
2019-06-06 14:21:15 +02:00
|
|
|
include_directories(${mkldnn_SOURCE_DIR}/include ${mkldnn_SOURCE_DIR}/external/mklml_lnx_2019.0.3.20190220/include ${mkldnn_SOURCE_DIR})
|
2019-11-20 11:23:08 +01:00
|
|
|
set(MKLDNN dnnl)
|
2019-06-06 14:21:15 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Download and unpack flatbuffers at configure time
|
|
|
|
configure_file(../../CMakeLists.txt.in flatbuffers-download/CMakeLists.txt)
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "CMake step for flatbuffers failed: ${result}")
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-download )
|
|
|
|
if(result)
|
|
|
|
message(FATAL_ERROR "Build step for flatbuffers failed: ${result}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add flatbuffers directly to our build.
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-src
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
|
|
|
|
set(HAVE_FLATBUFFERS 1)
|
|
|
|
set(FLATBUFFERS_PATH ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-src)
|
|
|
|
include_directories(${FLATBUFFERS_PATH}/include)
|
|
|
|
|
|
|
|
|
|
|
|
# Prevent overriding the parent project's compiler/linker
|
|
|
|
# settings on Windows
|
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
|
|
|
|
# Add googletest directly to our build. This defines
|
|
|
|
# the gtest and gtest_main targets.
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
|
|
|
EXCLUDE_FROM_ALL)
|
|
|
|
|
|
|
|
set(gtest_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest-src)
|
|
|
|
add_definitions(-D__STANDALONE_BUILD__=true)
|
|
|
|
|
|
|
|
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
|
2020-03-02 10:49:41 +01:00
|
|
|
include_directories(../../include)
|
2019-06-06 14:21:15 +02:00
|
|
|
if(LINUX)
|
|
|
|
link_directories(/usr/local/lib)
|
|
|
|
link_directories(/usr/lib)
|
|
|
|
link_directories(/lib)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
message("Using apple")
|
|
|
|
link_directories(/usr/local/lib)
|
|
|
|
link_directories(/usr/lib)
|
|
|
|
link_directories(/lib)
|
|
|
|
endif()
|
|
|
|
if(WIN32)
|
|
|
|
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
|
|
|
|
foreach(dir ${dirs})
|
|
|
|
message(STATUS "dir='${dir}'")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# -fsanitize=address
|
|
|
|
# -fsanitize=leak
|
|
|
|
if (APPLE)
|
2020-03-02 10:49:41 +01:00
|
|
|
set(CMAKE_CXX_FLAGS " -O0 -g -fPIC -std=c++11 -D__APPLE_OS__=true -DSD_APPLE_BUILD=true")
|
2019-06-06 14:21:15 +02:00
|
|
|
elseif(WIN32)
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2019-11-03 11:37:19 +01:00
|
|
|
set(CMAKE_CXX_FLAGS " -g -fPIC -std=c++11 -Wa,-mbig-obj")
|
2019-06-06 14:21:15 +02:00
|
|
|
endif()
|
|
|
|
else()
|
2019-11-13 15:15:18 +01:00
|
|
|
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -DLINUX_BUILD=true")
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
if ("${_RELEASE}" OR CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
message("Release build for tests")
|
2019-11-13 15:15:18 +01:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -std=c++11 -D_RELEASE=true")
|
2019-06-06 14:21:15 +02:00
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64*")
|
|
|
|
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -mcpu=native")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native")
|
|
|
|
endif()
|
|
|
|
else()
|
2019-11-03 11:37:19 +01:00
|
|
|
set(CMAKE_CXX_FLAGS " -g -O0 -fPIC -std=c++11 ")
|
2020-03-02 10:49:41 +01:00
|
|
|
if (NOT SD_CUDA)
|
2019-06-06 14:21:15 +02:00
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (${F16C})
|
2019-09-11 20:50:28 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c -DSD_F16C=true")
|
2019-06-06 14:21:15 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if ("${_RELEASE}" OR CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRELEASE_BUILD=true")
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG_BUILD=true")
|
|
|
|
endif()
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
if ("${SD_EXPERIMENTAL}" STREQUAL "yes")
|
2019-06-06 14:21:15 +02:00
|
|
|
message("Experimental mode ENABLED")
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__ND4J_EXPERIMENTAL__=true")
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__ND4J_EXPERIMENTAL__=true")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# tests are always compiled with all ops included
|
2020-03-02 10:49:41 +01:00
|
|
|
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSD_ALL_OPS=true -DDEFAULT_ENGINE=samediff::ENGINE_CPU")
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
# using Clang
|
|
|
|
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_TUNE} -Wno-logical-op-parentheses -Wno-inconsistent-missing-override -Wno-implicit-conversion-floating-point-to-bool -Wno-delete-non-virtual-dtor")
|
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
|
|
|
message("AppleClang used")
|
|
|
|
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_TUNE} -Wno-logical-op-parentheses -Wno-inconsistent-missing-override -Wno-implicit-conversion-floating-point-to-bool -Wno-delete-non-virtual-dtor")
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
|
|
|
# using Intel C++
|
|
|
|
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_TUNE} -fp-model fast")
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
# using Visual Studio C++
|
|
|
|
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
# using GCC
|
|
|
|
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=2")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|
|
|
include_directories("/usr/include")
|
|
|
|
include_directories("/usr/local/include")
|
|
|
|
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|
|
|
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 4.9)
|
|
|
|
message(FATAL_ERROR "You need at least GCC 4.9")
|
|
|
|
endif()
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
message("Looking for OpenMP")
|
2019-06-06 14:21:15 +02:00
|
|
|
find_package(OpenMP)
|
|
|
|
if (OPENMP_FOUND)
|
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
|
|
|
else()
|
|
|
|
message("OPENMP NOT FOUND")
|
|
|
|
endif()
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
if ("${OPENBLAS}" OR CMAKE_BUILD_TYPE STREQUAL "Release" OR "${BUILD_MKLDNN}")
|
|
|
|
message("Looking for BLAS")
|
|
|
|
find_package(BLAS REQUIRED)
|
2019-06-06 14:21:15 +02:00
|
|
|
if (BLAS_FOUND)
|
2019-09-11 20:50:28 +02:00
|
|
|
message("Found external BLAS library: ${BLAS_LIBRARIES}")
|
2019-06-06 14:21:15 +02:00
|
|
|
add_definitions(-D__EXTERNAL_BLAS__=true)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-07-12 07:21:15 +02:00
|
|
|
file(GLOB_RECURSE PERF_SOURCES false ../../include/performance/*.cpp ../../include/performance/*.h)
|
2019-06-06 14:21:15 +02:00
|
|
|
file(GLOB_RECURSE EXCEPTIONS_SOURCES false ../../include/exceptions/*.cpp ../../include/exceptions/*.h)
|
|
|
|
file(GLOB_RECURSE EXEC_SOURCES false ../../include/execution/*.cpp ../../include/execution/*.h)
|
|
|
|
file(GLOB_RECURSE TYPES_SOURCES false ../../include/types/*.cpp ../../include/types/*.h)
|
|
|
|
file(GLOB_RECURSE ARRAY_SOURCES false ../../include/array/*.cpp ../../include/array/*.h)
|
|
|
|
file(GLOB_RECURSE MEMORY_SOURCES false ../../include/memory/*.cpp ../../include/memory/*.h)
|
|
|
|
file(GLOB_RECURSE GRAPH_SOURCES false ../../include/graph/*.cpp ../../include/graph/*.h)
|
|
|
|
file(GLOB_RECURSE CUSTOMOPS_SOURCES false ../../include/ops/declarable/generic/*.cpp)
|
2019-09-11 20:50:28 +02:00
|
|
|
file(GLOB_RECURSE CUSTOMOPS_GENERIC_SOURCES false ../../include/ops/declarable/helpers/cpu/*.cpp ../../include/ops/declarable/helpers/impl/*.cpp)
|
2019-06-06 14:21:15 +02:00
|
|
|
file(GLOB_RECURSE OPS_SOURCES false ../../include/ops/impl/*.cpp ../../include/ops/declarable/impl/*.cpp ../../include/ops/*.h)
|
|
|
|
file(GLOB_RECURSE INDEXING_SOURCES false ../../include/indexing/*.cpp ../../include/indexing/*.h)
|
2019-09-11 20:50:28 +02:00
|
|
|
file(GLOB_RECURSE HELPERS_SOURCES false ../../include/helpers/*.cpp)
|
2020-03-02 10:49:41 +01:00
|
|
|
file(GLOB_RECURSE LEGACY_SOURCES false ../../include/legacy/impl/*.cpp ../../include/legacy/cpu/*.cpp ../../include/legacy/*.h)
|
2019-06-06 14:21:15 +02:00
|
|
|
file(GLOB_RECURSE LOOPS_SOURCES false ../../include/loops/*.cpp ../../include/loops/*.h)
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
# optionally build mkldnn
|
|
|
|
if ("${BUILD_MKLDNN}")
|
|
|
|
file(GLOB_RECURSE CUSTOMOPS_PLATFORM_SOURCES false ../../include/ops/declarable/platform/mkldnn/*.cpp)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message("CPU backend")
|
2019-06-06 14:21:15 +02:00
|
|
|
add_definitions(-D__CPUBLAS__=true)
|
|
|
|
|
2019-07-03 13:24:50 +02:00
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT(MINGW) AND NOT(APPLE))
|
2019-06-06 14:21:15 +02:00
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic -Wl,-export-dynamic")
|
|
|
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -export-dynamic")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2019-09-11 20:50:28 +02:00
|
|
|
# this function strips path from file name, basically making up short file name, i.e. file.cpp
|
|
|
|
function(SHORTNAME LONG_NAME OUTPUT)
|
|
|
|
SET(_TMP_STR "")
|
|
|
|
string (REGEX REPLACE ".*/" "" _TMP_STR "${LONG_NAME}")
|
|
|
|
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# now we ned to join two lists
|
|
|
|
# first of all we'll build truncated list of files in platform sources
|
|
|
|
# and list of priority implementations from platform helpers
|
|
|
|
#set(CUSTOMOPS_HELPERS_SOURCES "")
|
|
|
|
#set(SHORT_NAMES "")
|
|
|
|
#foreach(LONG_NAME ${CUSTOMOPS_PLATFORM_SOURCES})
|
|
|
|
# SHORTNAME("${LONG_NAME}" "SHORT_NAME")
|
|
|
|
# set(CUSTOMOPS_HELPERS_SOURCES ${CUSTOMOPS_HELPERS_SOURCES} ${LONG_NAME})
|
|
|
|
# set(SHORT_NAMES ${SHORT_NAMES} ${SHORT_NAME})
|
|
|
|
#endforeach()
|
|
|
|
|
|
|
|
# now we're going to filter generic helpers, to exclude platform implementations
|
|
|
|
#foreach(LONG_NAME ${CUSTOMOPS_GENERIC_SOURCES})
|
|
|
|
# SHORTNAME("${LONG_NAME}" "SHORT_NAME")
|
|
|
|
|
|
|
|
# and now we add this op ONLY if it wasn't announced in platform helpers
|
|
|
|
# string(FIND "${SHORT_NAMES}" "${SHORT_NAME}" "LOC")
|
|
|
|
# if (${LOC} EQUAL -1)
|
|
|
|
# set(CUSTOMOPS_HELPERS_SOURCES ${CUSTOMOPS_HELPERS_SOURCES} ${LONG_NAME})
|
|
|
|
# endif()
|
|
|
|
#endforeach()
|
|
|
|
|
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
file(GLOB_RECURSE TEST_SOURCES false ../layers_tests/*.cpp ../layers_tests/*.h)
|
|
|
|
|
|
|
|
|
|
|
|
# Filter out any source files from */CMakeFiles/* paths. these tend to cause problems such a multiple main definitions.
|
|
|
|
set (EXCLUDE_DIR "/CMakeFiles/")
|
|
|
|
foreach (TMP_PATH ${TEST_SOURCES})
|
|
|
|
string (FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
|
|
|
|
if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
|
|
|
|
list (REMOVE_ITEM TEST_SOURCES ${TMP_PATH})
|
|
|
|
endif ()
|
|
|
|
endforeach(TMP_PATH)
|
|
|
|
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
add_executable(runtests ${LOOPS_SOURCES} ${LEGACY_SOURCES} ${EXEC_SOURCES} ${HELPERS_SOURCES} ${ARRAY_SOURCES} ${TYPES_SOURCES}
|
2019-09-11 20:50:28 +02:00
|
|
|
${MEMORY_SOURCES} ${GRAPH_SOURCES} ${CUSTOMOPS_SOURCES} ${EXCEPTIONS_SOURCES} ${INDEXING_SOURCES} ${CUSTOMOPS_PLATFORM_SOURCES} ${CUSTOMOPS_GENERIC_SOURCES}
|
2020-02-17 08:23:05 +01:00
|
|
|
${OPS_SOURCES} ${TEST_SOURCES} ${PERF_SOURCES})
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
target_link_libraries(runtests gtest ${MKLDNN} gtest_main ${BLAS_LIBRARIES})
|
|
|
|
|