Commit 0886042c authored by lishen's avatar lishen
Browse files

dlib from github, version=19.24

parent 5b127120
Pipeline #262 failed with stages
in 0 seconds
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_SPECTRAL_CLUSTEr_H_
#define DLIB_SPECTRAL_CLUSTEr_H_
#include "spectral_cluster_abstract.h"
#include <vector>
#include "../matrix.h"
#include "../svm/kkmeans.h"
namespace dlib
{
template <
typename kernel_type,
typename vector_type
>
std::vector<unsigned long> spectral_cluster (
const kernel_type& k,
const vector_type& samples,
const unsigned long num_clusters
)
{
DLIB_CASSERT(num_clusters > 0,
"\t std::vector<unsigned long> spectral_cluster(k,samples,num_clusters)"
<< "\n\t num_clusters can't be 0."
);
if (num_clusters == 1)
{
// nothing to do, just assign everything to the 0 cluster.
return std::vector<unsigned long>(samples.size(), 0);
}
// compute the similarity matrix.
matrix<double> K(samples.size(), samples.size());
for (long r = 0; r < K.nr(); ++r)
for (long c = r+1; c < K.nc(); ++c)
K(r,c) = K(c,r) = (double)k(samples[r], samples[c]);
for (long r = 0; r < K.nr(); ++r)
K(r,r) = 0;
matrix<double,0,1> D(K.nr());
for (long r = 0; r < K.nr(); ++r)
D(r) = sum(rowm(K,r));
D = sqrt(reciprocal(D));
K = diagm(D)*K*diagm(D);
matrix<double> u,w,v;
// Use the normal SVD routine unless the matrix is really big, then use the fast
// approximate version.
if (K.nr() < 1000)
svd3(K,u,w,v);
else
svd_fast(K,u,w,v, num_clusters+100, 5);
// Pick out the eigenvectors associated with the largest eigenvalues.
rsort_columns(v,w);
v = colm(v, range(0,num_clusters-1));
// Now build the normalized spectral vectors, one for each input vector.
std::vector<matrix<double,0,1> > spec_samps, centers;
for (long r = 0; r < v.nr(); ++r)
{
spec_samps.push_back(trans(rowm(v,r)));
const double len = length(spec_samps.back());
if (len != 0)
spec_samps.back() /= len;
}
// Finally do the K-means clustering
pick_initial_centers(num_clusters, centers, spec_samps);
find_clusters_using_kmeans(spec_samps, centers);
// And then compute the cluster assignments based on the output of K-means.
std::vector<unsigned long> assignments;
for (unsigned long i = 0; i < spec_samps.size(); ++i)
assignments.push_back(nearest_center(centers, spec_samps[i]));
return assignments;
}
}
#endif // DLIB_SPECTRAL_CLUSTEr_H_
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_SPECTRAL_CLUSTEr_ABSTRACT_H_
#ifdef DLIB_SPECTRAL_CLUSTEr_ABSTRACT_H_
#include <vector>
namespace dlib
{
template <
typename kernel_type,
typename vector_type
>
std::vector<unsigned long> spectral_cluster (
const kernel_type& k,
const vector_type& samples,
const unsigned long num_clusters
);
/*!
requires
- samples must be something with an interface compatible with std::vector.
- The following expression must evaluate to a double or float:
k(samples[i], samples[j])
- num_clusters > 0
ensures
- Performs the spectral clustering algorithm described in the paper:
On spectral clustering: Analysis and an algorithm by Ng, Jordan, and Weiss.
and returns the results.
- This function clusters the input data samples into num_clusters clusters and
returns a vector that indicates which cluster each sample falls into. In
particular, we return an array A such that:
- A.size() == samples.size()
- A[i] == the cluster assignment of samples[i].
- for all valid i: 0 <= A[i] < num_clusters
- The "similarity" of samples[i] with samples[j] is given by
k(samples[i],samples[j]). This means that k() should output a number >= 0
and the number should be larger for samples that are more similar.
!*/
}
#endif // DLIB_SPECTRAL_CLUSTEr_ABSTRACT_H_
cmake_minimum_required(VERSION 3.8.0)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR} dlib_build)
# This script checks if your compiler and host processor can generate and then run programs with AVX instructions.
cmake_minimum_required(VERSION 3.8.0)
# Don't rerun this script if its already been executed.
if (DEFINED AVX_IS_AVAILABLE_ON_HOST)
return()
endif()
# Set to false unless we find out otherwise in the code below.
set(AVX_IS_AVAILABLE_ON_HOST 0)
try_compile(test_for_avx_worked ${PROJECT_BINARY_DIR}/avx_test_build ${CMAKE_CURRENT_LIST_DIR}/test_for_avx
avx_test)
if(test_for_avx_worked)
message (STATUS "AVX instructions can be executed by the host processor.")
set(AVX_IS_AVAILABLE_ON_HOST 1)
endif()
# This script checks if __ARM_NEON__ is defined for your compiler
cmake_minimum_required(VERSION 3.8.0)
# Don't rerun this script if its already been executed.
if (DEFINED ARM_NEON_IS_AVAILABLE)
return()
endif()
# Set to false unless we find out otherwise in the code below.
set(ARM_NEON_IS_AVAILABLE 0)
# test if __ARM_NEON__ is defined
try_compile(test_for_neon_worked ${PROJECT_BINARY_DIR}/neon_test_build ${CMAKE_CURRENT_LIST_DIR}/test_for_neon
neon_test)
if(test_for_neon_worked)
message (STATUS "__ARM_NEON__ defined.")
set(ARM_NEON_IS_AVAILABLE 1)
endif()
# This script checks if your compiler and host processor can generate and then run programs with SSE4 instructions.
cmake_minimum_required(VERSION 3.8.0)
# Don't rerun this script if its already been executed.
if (DEFINED SSE4_IS_AVAILABLE_ON_HOST)
return()
endif()
# Set to false unless we find out otherwise in the code below.
set(SSE4_IS_AVAILABLE_ON_HOST 0)
try_compile(test_for_sse4_worked ${PROJECT_BINARY_DIR}/sse4_test_build ${CMAKE_CURRENT_LIST_DIR}/test_for_sse4
sse4_test)
if(test_for_sse4_worked)
message (STATUS "SSE4 instructions can be executed by the host processor.")
set(SSE4_IS_AVAILABLE_ON_HOST 1)
endif()
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: @PROJECT_NAME@
Description: Numerical and networking C++ library
Version: @VERSION@
Libs: -L${libdir} -ldlib @pkg_config_dlib_needed_libraries@
Cflags: -I${includedir} @pkg_config_dlib_needed_includes@
# ===================================================================================
# The dlib CMake configuration file
#
# ** File generated automatically, do not modify **
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# find_package(dlib REQUIRED)
# target_link_libraries(MY_TARGET_NAME dlib::dlib)
#
# ===================================================================================
# Our library dependencies (contains definitions for IMPORTED targets)
if(NOT TARGET dlib-shared AND NOT dlib_BINARY_DIR)
# Compute paths
get_filename_component(dlib_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include("${dlib_CMAKE_DIR}/dlib.cmake")
# Check if Threads::Threads target is required and find it if necessary
get_target_property(dlib_deps_threads_check dlib::dlib INTERFACE_LINK_LIBRARIES)
list(FIND dlib_deps_threads_check "Threads::Threads" dlib_deps_threads_idx)
if (${dlib_deps_threads_idx} GREATER -1)
if (NOT TARGET Threads)
find_package(Threads REQUIRED)
endif()
endif()
unset(dlib_deps_threads_idx)
unset(dlib_deps_threads_check)
endif()
set(dlib_LIBRARIES dlib::dlib)
set(dlib_LIBS dlib::dlib)
set(dlib_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@" "@dlib_needed_includes@")
mark_as_advanced(dlib_LIBRARIES)
mark_as_advanced(dlib_LIBS)
mark_as_advanced(dlib_INCLUDE_DIRS)
# Mark these variables above as deprecated.
function(__deprecated_var var access)
if(access STREQUAL "READ_ACCESS")
message(WARNING "The variable '${var}' is deprecated! Instead, simply use target_link_libraries(your_app dlib::dlib). See http://dlib.net/examples/CMakeLists.txt.html for an example.")
endif()
endfunction()
variable_watch(dlib_LIBRARIES __deprecated_var)
variable_watch(dlib_LIBS __deprecated_var)
variable_watch(dlib_INCLUDE_DIRS __deprecated_var)
#
# This is a CMake makefile. You can find the cmake utility and
# information about it at http://www.cmake.org
#
#
# This cmake file tries to find installed BLAS and LAPACK libraries.
# It looks for an installed copy of the Intel MKL library first and then
# attempts to find some other BLAS and LAPACK libraries if you don't have
# the Intel MKL.
#
# blas_found - True if BLAS is available
# lapack_found - True if LAPACK is available
# found_intel_mkl - True if the Intel MKL library is available
# found_intel_mkl_headers - True if Intel MKL headers are available
# blas_libraries - link against these to use BLAS library
# lapack_libraries - link against these to use LAPACK library
# mkl_libraries - link against these to use the MKL library
# mkl_include_dir - add to the include path to use the MKL library
# openmp_libraries - Set to Intel's OpenMP library if and only if we
# find the MKL.
# setting this makes CMake allow normal looking if else statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
SET(blas_found 0)
SET(lapack_found 0)
SET(found_intel_mkl 0)
SET(found_intel_mkl_headers 0)
SET(lapack_with_underscore 0)
SET(lapack_without_underscore 0)
message(STATUS "Searching for BLAS and LAPACK")
INCLUDE(CheckFunctionExists)
if (UNIX OR MINGW)
message(STATUS "Searching for BLAS and LAPACK")
if (BUILDING_MATLAB_MEX_FILE)
# # This commented out stuff would link directly to MATLAB's built in
# BLAS and LAPACK. But it's better to not link to anything and do a
#find_library(MATLAB_BLAS_LIBRARY mwblas PATHS ${MATLAB_LIB_FOLDERS} )
#find_library(MATLAB_LAPACK_LIBRARY mwlapack PATHS ${MATLAB_LIB_FOLDERS} )
#if (MATLAB_BLAS_LIBRARY AND MATLAB_LAPACK_LIBRARY)
# add_subdirectory(external/cblas)
# set(blas_libraries ${MATLAB_BLAS_LIBRARY} cblas )
# set(lapack_libraries ${MATLAB_LAPACK_LIBRARY} )
# set(blas_found 1)
# set(lapack_found 1)
# message(STATUS "Found MATLAB's BLAS and LAPACK libraries")
#endif()
# We need cblas since MATLAB doesn't provide cblas symbols.
add_subdirectory(external/cblas)
set(blas_libraries cblas )
set(blas_found 1)
set(lapack_found 1)
message(STATUS "Will link with MATLAB's BLAS and LAPACK at runtime (hopefully!)")
## Don't try to link to anything other than MATLAB's own internal blas
## and lapack libraries because doing so generally upsets MATLAB. So
## we just end here no matter what.
return()
endif()
# First, search for libraries via pkg-config, which is the cleanest path
find_package(PkgConfig)
pkg_check_modules(BLAS_REFERENCE cblas)
pkg_check_modules(LAPACK_REFERENCE lapack)
# Make sure the cblas found by pkgconfig actually has cblas symbols.
SET(CMAKE_REQUIRED_LIBRARIES "${BLAS_REFERENCE_LDFLAGS}")
CHECK_FUNCTION_EXISTS(cblas_ddot PKGCFG_HAVE_CBLAS)
if (BLAS_REFERENCE_FOUND AND LAPACK_REFERENCE_FOUND AND PKGCFG_HAVE_CBLAS)
set(blas_libraries "${BLAS_REFERENCE_LDFLAGS}")
set(lapack_libraries "${LAPACK_REFERENCE_LDFLAGS}")
set(blas_found 1)
set(lapack_found 1)
set(REQUIRES_LIBS "${REQUIRES_LIBS} cblas lapack")
message(STATUS "Found BLAS and LAPACK via pkg-config")
return()
endif()
include(CheckTypeSize)
check_type_size( "void*" SIZE_OF_VOID_PTR)
if (SIZE_OF_VOID_PTR EQUAL 8)
set( mkl_search_path
/opt/intel/oneapi/mkl/latest/lib/intel64
/opt/intel/mkl/*/lib/em64t
/opt/intel/mkl/lib/intel64
/opt/intel/lib/intel64
/opt/intel/mkl/lib
/opt/intel/tbb/*/lib/em64t/gcc4.7
/opt/intel/tbb/lib/intel64/gcc4.7
/opt/intel/tbb/lib/gcc4.7
)
find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
mark_as_advanced(mkl_intel)
else()
set( mkl_search_path
/opt/intel/oneapi/mkl/latest/lib/ia32
/opt/intel/mkl/*/lib/32
/opt/intel/mkl/lib/ia32
/opt/intel/lib/ia32
/opt/intel/tbb/*/lib/32/gcc4.7
/opt/intel/tbb/lib/ia32/gcc4.7
)
find_library(mkl_intel mkl_intel ${mkl_search_path})
mark_as_advanced(mkl_intel)
endif()
include(CheckLibraryExists)
# Get mkl_include_dir
set(mkl_include_search_path
/opt/intel/oneapi/mkl/latest/include
/opt/intel/mkl/include
/opt/intel/include
)
find_path(mkl_include_dir mkl_version.h ${mkl_include_search_path})
mark_as_advanced(mkl_include_dir)
if(NOT DLIB_USE_MKL_SEQUENTIAL AND NOT DLIB_USE_MKL_WITH_TBB)
# Search for the needed libraries from the MKL. We will try to link against the mkl_rt
# file first since this way avoids linking bugs in some cases.
find_library(mkl_rt mkl_rt ${mkl_search_path})
find_library(openmp_libraries iomp5 ${mkl_search_path})
mark_as_advanced(mkl_rt openmp_libraries)
# if we found the MKL
if (mkl_rt)
set(mkl_libraries ${mkl_rt} )
set(blas_libraries ${mkl_rt} )
set(lapack_libraries ${mkl_rt} )
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
endif()
endif()
if (NOT found_intel_mkl)
# Search for the needed libraries from the MKL. This time try looking for a different
# set of MKL files and try to link against those.
find_library(mkl_core mkl_core ${mkl_search_path})
set(mkl_libs ${mkl_intel} ${mkl_core})
mark_as_advanced(mkl_libs mkl_intel mkl_core)
if (DLIB_USE_MKL_WITH_TBB)
find_library(mkl_tbb_thread mkl_tbb_thread ${mkl_search_path})
find_library(mkl_tbb tbb ${mkl_search_path})
mark_as_advanced(mkl_tbb_thread mkl_tbb)
list(APPEND mkl_libs ${mkl_tbb_thread} ${mkl_tbb})
elseif (DLIB_USE_MKL_SEQUENTIAL)
find_library(mkl_sequential mkl_sequential ${mkl_search_path})
mark_as_advanced(mkl_sequential)
list(APPEND mkl_libs ${mkl_sequential})
else()
find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
find_library(mkl_iomp iomp5 ${mkl_search_path})
find_library(mkl_pthread pthread ${mkl_search_path})
mark_as_advanced(mkl_thread mkl_iomp mkl_pthread)
list(APPEND mkl_libs ${mkl_thread} ${mkl_iomp} ${mkl_pthread})
endif()
# If we found the MKL
if (mkl_intel AND mkl_core AND ((mkl_tbb_thread AND mkl_tbb) OR (mkl_thread AND mkl_iomp AND mkl_pthread) OR mkl_sequential))
set(mkl_libraries ${mkl_libs})
set(blas_libraries ${mkl_libs})
set(lapack_libraries ${mkl_libs})
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
endif()
endif()
if (found_intel_mkl AND mkl_include_dir)
set(found_intel_mkl_headers 1)
endif()
# try to find some other LAPACK libraries if we didn't find the MKL
set(extra_paths
/usr/lib64
/usr/lib64/atlas-sse3
/usr/lib64/atlas-sse2
/usr/lib64/atlas
/usr/lib
/usr/lib/atlas-sse3
/usr/lib/atlas-sse2
/usr/lib/atlas
/usr/lib/openblas-base
/opt/OpenBLAS/lib
$ENV{OPENBLAS_HOME}/lib
)
if (NOT blas_found)
find_library(cblas_lib NAMES openblasp openblas PATHS ${extra_paths})
if (cblas_lib)
set(blas_libraries ${cblas_lib})
set(blas_found 1)
message(STATUS "Found OpenBLAS library")
set(CMAKE_REQUIRED_LIBRARIES ${blas_libraries})
# If you compiled OpenBLAS with LAPACK in it then it should have the
# sgetrf_single function in it. So if we find that function in
# OpenBLAS then just use OpenBLAS's LAPACK.
CHECK_FUNCTION_EXISTS(sgetrf_single OPENBLAS_HAS_LAPACK)
if (OPENBLAS_HAS_LAPACK)
message(STATUS "Using OpenBLAS's built in LAPACK")
# set(lapack_libraries gfortran)
set(lapack_found 1)
endif()
endif()
mark_as_advanced( cblas_lib)
endif()
if (NOT lapack_found)
find_library(lapack_lib NAMES lapack lapack-3 PATHS ${extra_paths})
if (lapack_lib)
set(lapack_libraries ${lapack_lib})
set(lapack_found 1)
message(STATUS "Found LAPACK library")
endif()
mark_as_advanced( lapack_lib)
endif()
# try to find some other BLAS libraries if we didn't find the MKL
if (NOT blas_found)
find_library(atlas_lib atlas PATHS ${extra_paths})
find_library(cblas_lib cblas PATHS ${extra_paths})
if (atlas_lib AND cblas_lib)
set(blas_libraries ${atlas_lib} ${cblas_lib})
set(blas_found 1)
message(STATUS "Found ATLAS BLAS library")
endif()
mark_as_advanced( atlas_lib cblas_lib)
endif()
# CentOS 7 atlas
if (NOT blas_found)
find_library(tatlas_lib tatlas PATHS ${extra_paths})
find_library(satlas_lib satlas PATHS ${extra_paths})
if (tatlas_lib AND satlas_lib )
set(blas_libraries ${tatlas_lib} ${satlas_lib})
set(blas_found 1)
message(STATUS "Found ATLAS BLAS library")
endif()
mark_as_advanced( tatlas_lib satlas_lib)
endif()
if (NOT blas_found)
find_library(cblas_lib cblas PATHS ${extra_paths})
if (cblas_lib)
set(blas_libraries ${cblas_lib})
set(blas_found 1)
message(STATUS "Found CBLAS library")
endif()
mark_as_advanced( cblas_lib)
endif()
if (NOT blas_found)
find_library(generic_blas blas PATHS ${extra_paths})
if (generic_blas)
set(blas_libraries ${generic_blas})
set(blas_found 1)
message(STATUS "Found BLAS library")
endif()
mark_as_advanced( generic_blas)
endif()
# Make sure we really found a CBLAS library. That is, it needs to expose
# the proper cblas link symbols. So here we test if one of them is present
# and assume everything is good if it is. Note that we don't do this check if
# we found the Intel MKL since for some reason CHECK_FUNCTION_EXISTS doesn't work
# with it. But it's fine since the MKL should always have cblas.
if (blas_found AND NOT found_intel_mkl)
set(CMAKE_REQUIRED_LIBRARIES ${blas_libraries})
CHECK_FUNCTION_EXISTS(cblas_ddot FOUND_BLAS_HAS_CBLAS)
if (NOT FOUND_BLAS_HAS_CBLAS)
message(STATUS "BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK")
set(blas_found 0)
set(lapack_found 0)
endif()
endif()
elseif(WIN32 AND NOT MINGW)
message(STATUS "Searching for BLAS and LAPACK")
include(CheckTypeSize)
check_type_size( "void*" SIZE_OF_VOID_PTR)
if (SIZE_OF_VOID_PTR EQUAL 8)
set( mkl_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/intel64/vc_mt"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/lib/intel64"
"C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64"
"C:/Program Files (x86)/Intel/Composer XE/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/Intel/Composer XE/compiler/lib/intel64"
"C:/Program Files/Intel/Composer XE/mkl/lib/intel64"
"C:/Program Files/Intel/Composer XE/tbb/lib/intel64/vc14"
"C:/Program Files/Intel/Composer XE/compiler/lib/intel64"
"C:/Program Files (x86)/Intel/oneAPI/mkl/*/lib/intel64"
"C:/Program Files (x86)/Intel/oneAPI/compiler/*/windows/compiler/lib/intel64_win"
)
set (mkl_redist_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/redist/intel64/compiler"
"C:/Program Files (x86)/Intel/oneAPI/compiler/*/windows/redist/intel64_win/compiler"
)
find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
else()
set( mkl_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/ia32/vc_mt"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/lib/ia32"
"C:/Program Files (x86)/Intel/Composer XE/mkl/lib/ia32"
"C:/Program Files (x86)/Intel/Composer XE/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/Intel/Composer XE/compiler/lib/ia32"
"C:/Program Files/Intel/Composer XE/mkl/lib/ia32"
"C:/Program Files/Intel/Composer XE/tbb/lib/ia32/vc14"
"C:/Program Files/Intel/Composer XE/compiler/lib/ia32"
"C:/Program Files (x86)/Intel/oneAPI/mkl/*/lib/ia32"
"C:/Program Files (x86)/Intel/oneAPI/compiler/*/windows/compiler/lib/ia32_win"
)
set (mkl_redist_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/redist/ia32/compiler"
"C:/Program Files (x86)/Intel/oneAPI/compiler/*/windows/redist/ia32_win/compiler"
)
find_library(mkl_intel mkl_intel_c ${mkl_search_path})
endif()
# Get mkl_include_dir
set(mkl_include_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/include"
"C:/Program Files (x86)/Intel/Composer XE/mkl/include"
"C:/Program Files (x86)/Intel/Composer XE/compiler/include"
"C:/Program Files/Intel/Composer XE/mkl/include"
"C:/Program Files/Intel/Composer XE/compiler/include"
"C:/Program Files (x86)/Intel/oneAPI/mkl/*/include"
)
find_path(mkl_include_dir mkl_version.h ${mkl_include_search_path})
mark_as_advanced(mkl_include_dir)
# Search for the needed libraries from the MKL.
find_library(mkl_core mkl_core ${mkl_search_path})
set(mkl_libs ${mkl_intel} ${mkl_core})
mark_as_advanced(mkl_libs mkl_intel mkl_core)
if (DLIB_USE_MKL_WITH_TBB)
find_library(mkl_tbb_thread mkl_tbb_thread ${mkl_search_path})
find_library(mkl_tbb tbb ${mkl_search_path})
mark_as_advanced(mkl_tbb_thread mkl_tbb)
list(APPEND mkl_libs ${mkl_tbb_thread} ${mkl_tbb})
elseif (DLIB_USE_MKL_SEQUENTIAL)
find_library(mkl_sequential mkl_sequential ${mkl_search_path})
mark_as_advanced(mkl_sequential)
list(APPEND mkl_libs ${mkl_sequential})
else()
find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
mark_as_advanced(mkl_thread)
if (mkl_thread)
find_library(mkl_iomp libiomp5md ${mkl_search_path})
mark_as_advanced(mkl_iomp)
list(APPEND mkl_libs ${mkl_thread} ${mkl_iomp})
# See if we can find the dll that goes with this, so we can copy it to
# the output folder, since a very large number of windows users don't
# understand that they need to add the Intel MKL's folders to their
# PATH to use the Intel MKL. They then complain on the dlib forums.
# Copying the Intel MKL dlls to the output directory removes the need
# to add the Intel MKL to the PATH.
find_file(mkl_iomp_dll "libiomp5md.dll" ${mkl_redist_path})
if (mkl_iomp_dll)
message(STATUS "FOUND libiomp5md.dll: ${mkl_iomp_dll}")
endif()
endif()
endif()
# If we found the MKL
if (mkl_intel AND mkl_core AND ((mkl_tbb_thread AND mkl_tbb) OR mkl_sequential OR (mkl_thread AND mkl_iomp)))
set(blas_libraries ${mkl_libs})
set(lapack_libraries ${mkl_libs})
set(blas_found 1)
set(lapack_found 1)
set(found_intel_mkl 1)
message(STATUS "Found Intel MKL BLAS/LAPACK library")
# Make sure the version of the Intel MKL we found is compatible with
# the compiler we are using. One way to do this check is to see if we can
# link to it right now.
set(CMAKE_REQUIRED_LIBRARIES ${blas_libraries})
CHECK_FUNCTION_EXISTS(cblas_ddot MKL_HAS_CBLAS)
if (NOT MKL_HAS_CBLAS)
message("BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK")
set(blas_found 0)
set(lapack_found 0)
endif()
endif()
if (found_intel_mkl AND mkl_include_dir)
set(found_intel_mkl_headers 1)
endif()
endif()
# When all else fails use CMake's built in functions to find BLAS and LAPACK
if (NOT blas_found)
find_package(BLAS QUIET)
if (${BLAS_FOUND})
set(blas_libraries ${BLAS_LIBRARIES})
set(blas_found 1)
if (NOT lapack_found)
find_package(LAPACK QUIET)
if (${LAPACK_FOUND})
set(lapack_libraries ${LAPACK_LIBRARIES})
set(lapack_found 1)
endif()
endif()
endif()
endif()
# If using lapack, determine whether to mangle functions
if (lapack_found)
include(CheckFortranFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ${lapack_libraries})
check_function_exists("sgesv" LAPACK_FOUND_C_UNMANGLED)
check_function_exists("sgesv_" LAPACK_FOUND_C_MANGLED)
if (CMAKE_Fortran_COMPILER_LOADED)
check_fortran_function_exists("sgesv" LAPACK_FOUND_FORTRAN_UNMANGLED)
check_fortran_function_exists("sgesv_" LAPACK_FOUND_FORTRAN_MANGLED)
endif ()
if (LAPACK_FOUND_C_MANGLED OR LAPACK_FOUND_FORTRAN_MANGLED)
set(lapack_with_underscore 1)
elseif (LAPACK_FOUND_C_UNMANGLED OR LAPACK_FOUND_FORTRAN_UNMANGLED)
set(lapack_without_underscore 1)
endif ()
endif()
if (UNIX OR MINGW)
if (NOT blas_found)
message(" *****************************************************************************")
message(" *** No BLAS library found so using dlib's built in BLAS. However, if you ***")
message(" *** install an optimized BLAS such as OpenBLAS or the Intel MKL your code ***")
message(" *** will run faster. On Ubuntu you can install OpenBLAS by executing: ***")
message(" *** sudo apt-get install libopenblas-dev liblapack-dev ***")
message(" *** Or you can easily install OpenBLAS from source by downloading the ***")
message(" *** source tar file from http://www.openblas.net, extracting it, and ***")
message(" *** running: ***")
message(" *** make; sudo make install ***")
message(" *****************************************************************************")
endif()
endif()
cmake_minimum_required(VERSION 3.8.0)
message(STATUS "Searching for FFMPEG/LIBAV")
find_package(PkgConfig)
if (PkgConfig_FOUND)
pkg_check_modules(FFMPEG IMPORTED_TARGET
libavdevice
libavfilter
libavformat
libavcodec
libswresample
libswscale
libavutil
)
if (FFMPEG_FOUND)
message(STATUS "Found FFMPEG/LIBAV via pkg-config in `${FFMPEG_LIBRARY_DIRS}`")
else()
message(" *****************************************************************************")
message(" *** No FFMPEG/LIBAV libraries found. ***")
message(" *** On Ubuntu you can install them by executing ***")
message(" *** sudo apt install libavdevice-dev libavfilter-dev libavformat-dev ***")
message(" *** sudo apt install libavcodec-dev libswresample-dev libswscale-dev ***")
message(" *** sudo apt install libavutil-dev ***")
message(" *****************************************************************************")
endif()
else()
message(STATUS "PkgConfig could not be found, FFMPEG won't be available")
set(FFMPEG_FOUND 0)
endif()
#This script just runs CMake's built in JPEG finding tool. But it also checks that the
#copy of libjpeg that cmake finds actually builds and links.
cmake_minimum_required(VERSION 3.8.0)
if (BUILDING_PYTHON_IN_MSVC)
# Never use any system copy of libjpeg when building python in visual studio
set(JPEG_FOUND 0)
return()
endif()
# Don't rerun this script if its already been executed.
if (DEFINED JPEG_FOUND)
return()
endif()
find_package(JPEG QUIET)
if(JPEG_FOUND)
set(JPEG_TEST_CMAKE_FLAGS
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}"
"-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}")
try_compile(test_for_libjpeg_worked
${PROJECT_BINARY_DIR}/test_for_libjpeg_build
${CMAKE_CURRENT_LIST_DIR}/test_for_libjpeg
test_if_libjpeg_is_broken
CMAKE_FLAGS "${JPEG_TEST_CMAKE_FLAGS}")
message (STATUS "Found system copy of libjpeg: ${JPEG_LIBRARY}")
if(NOT test_for_libjpeg_worked)
set(JPEG_FOUND 0)
message (STATUS "System copy of libjpeg is broken or too old. Will build our own libjpeg and use that instead.")
endif()
endif()
#This script just runs CMake's built in PNG finding tool. But it also checks that the
#copy of libpng that cmake finds actually builds and links.
cmake_minimum_required(VERSION 3.8.0)
if (BUILDING_PYTHON_IN_MSVC)
# Never use any system copy of libpng when building python in visual studio
set(PNG_FOUND 0)
return()
endif()
# Don't rerun this script if its already been executed.
if (DEFINED PNG_FOUND)
return()
endif()
find_package(PNG QUIET)
if(PNG_FOUND)
set(PNG_TEST_CMAKE_FLAGS
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}"
"-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}")
try_compile(test_for_libpng_worked
${PROJECT_BINARY_DIR}/test_for_libpng_build
${CMAKE_CURRENT_LIST_DIR}/test_for_libpng
test_if_libpng_is_broken
CMAKE_FLAGS "${PNG_TEST_CMAKE_FLAGS}")
message (STATUS "Found system copy of libpng: ${PNG_LIBRARIES}")
if(NOT test_for_libpng_worked)
set(PNG_FOUND 0)
message (STATUS "System copy of libpng is broken. Will build our own libpng and use that instead.")
endif()
endif()
#=============================================================================
# Find WebP library
# From OpenCV
#=============================================================================
# Find the native WebP headers and libraries.
#
# WEBP_INCLUDE_DIRS - where to find webp/decode.h, etc.
# WEBP_LIBRARIES - List of libraries when using webp.
# WEBP_FOUND - True if webp is found.
#=============================================================================
# Look for the header file.
unset(WEBP_FOUND)
find_path(WEBP_INCLUDE_DIR NAMES webp/decode.h)
if(NOT WEBP_INCLUDE_DIR)
unset(WEBP_FOUND)
else()
mark_as_advanced(WEBP_INCLUDE_DIR)
# Look for the library.
find_library(WEBP_LIBRARY NAMES webp)
mark_as_advanced(WEBP_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set WEBP_FOUND to TRUE if
# all listed variables are TRUE
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(WebP DEFAULT_MSG WEBP_LIBRARY WEBP_INCLUDE_DIR)
set(WEBP_LIBRARIES ${WEBP_LIBRARY})
set(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
endif()
if(WEBP_FOUND)
set(WEBP_TEST_CMAKE_FLAGS
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}"
"-DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}")
try_compile(test_for_libwebp_worked
${PROJECT_BINARY_DIR}/test_for_libwebp_build
${CMAKE_CURRENT_LIST_DIR}/test_for_libwebp
test_if_libwebp_is_broken
CMAKE_FLAGS "${WEBP_TEST_CMAKE_FLAGS}")
if(NOT test_for_libwebp_worked)
set(WEBP_FOUND 0)
message (STATUS "System copy of libwebp is either too old or broken. Will disable WebP support.")
endif()
endif()
#set default build type to Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel." FORCE)
endif()
cmake_minimum_required(VERSION 3.8.0)
# Check if we are being built as part of a pybind11 module.
if (COMMAND pybind11_add_module)
# For python users, enable SSE4 and AVX if they have these instructions.
include(${CMAKE_CURRENT_LIST_DIR}/check_if_sse4_instructions_executable_on_host.cmake)
if (SSE4_IS_AVAILABLE_ON_HOST)
set(USE_SSE4_INSTRUCTIONS ON CACHE BOOL "Compile your program with SSE4 instructions")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/check_if_avx_instructions_executable_on_host.cmake)
if (AVX_IS_AVAILABLE_ON_HOST)
set(USE_AVX_INSTRUCTIONS ON CACHE BOOL "Compile your program with AVX instructions")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/check_if_neon_available.cmake)
if (ARM_NEON_IS_AVAILABLE)
set(USE_NEON_INSTRUCTIONS ON CACHE BOOL "Compile your program with ARM-NEON instructions")
endif()
endif()
set(gcc_like_compilers GNU Clang Intel)
set(intel_archs x86_64 i386 i686 AMD64 amd64 x86)
# Setup some options to allow a user to enable SSE and AVX instruction use.
if ((";${gcc_like_compilers};" MATCHES ";${CMAKE_CXX_COMPILER_ID};") AND
(";${intel_archs};" MATCHES ";${CMAKE_SYSTEM_PROCESSOR};") AND NOT USE_AUTO_VECTOR)
option(USE_SSE2_INSTRUCTIONS "Compile your program with SSE2 instructions" OFF)
option(USE_SSE4_INSTRUCTIONS "Compile your program with SSE4 instructions" OFF)
option(USE_AVX_INSTRUCTIONS "Compile your program with AVX instructions" OFF)
if(USE_AVX_INSTRUCTIONS)
list(APPEND active_compile_opts -mavx)
message(STATUS "Enabling AVX instructions")
elseif (USE_SSE4_INSTRUCTIONS)
list(APPEND active_compile_opts -msse4)
message(STATUS "Enabling SSE4 instructions")
elseif(USE_SSE2_INSTRUCTIONS)
list(APPEND active_compile_opts -msse2)
message(STATUS "Enabling SSE2 instructions")
endif()
elseif (MSVC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # else if using Visual Studio
# Use SSE2 by default when using Visual Studio.
option(USE_SSE2_INSTRUCTIONS "Compile your program with SSE2 instructions" ON)
option(USE_SSE4_INSTRUCTIONS "Compile your program with SSE4 instructions" OFF)
option(USE_AVX_INSTRUCTIONS "Compile your program with AVX instructions" OFF)
include(CheckTypeSize)
check_type_size( "void*" SIZE_OF_VOID_PTR)
if(USE_AVX_INSTRUCTIONS)
list(APPEND active_compile_opts /arch:AVX)
message(STATUS "Enabling AVX instructions")
elseif (USE_SSE4_INSTRUCTIONS)
# Visual studio doesn't have an /arch:SSE2 flag when building in 64 bit modes.
# So only give it when we are doing a 32 bit build.
if (SIZE_OF_VOID_PTR EQUAL 4)
list(APPEND active_compile_opts /arch:SSE2)
endif()
message(STATUS "Enabling SSE4 instructions")
list(APPEND active_preprocessor_switches "-DDLIB_HAVE_SSE2")
list(APPEND active_preprocessor_switches "-DDLIB_HAVE_SSE3")
list(APPEND active_preprocessor_switches "-DDLIB_HAVE_SSE41")
elseif(USE_SSE2_INSTRUCTIONS)
# Visual studio doesn't have an /arch:SSE2 flag when building in 64 bit modes.
# So only give it when we are doing a 32 bit build.
if (SIZE_OF_VOID_PTR EQUAL 4)
list(APPEND active_compile_opts /arch:SSE2)
endif()
message(STATUS "Enabling SSE2 instructions")
list(APPEND active_preprocessor_switches "-DDLIB_HAVE_SSE2")
endif()
elseif((";${gcc_like_compilers};" MATCHES ";${CMAKE_CXX_COMPILER_ID};") AND
("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^arm"))
option(USE_NEON_INSTRUCTIONS "Compile your program with ARM-NEON instructions" OFF)
if(USE_NEON_INSTRUCTIONS)
list(APPEND active_compile_opts -mfpu=neon)
message(STATUS "Enabling ARM-NEON instructions")
endif()
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
# By default, g++ won't warn or error if you forget to return a value in a
# function which requires you to do so. This option makes it give a warning
# for doing this.
list(APPEND active_compile_opts "-Wreturn-type")
endif()
if ("Clang" MATCHES ${CMAKE_CXX_COMPILER_ID} AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
# Clang 6 had a default template recursion depth of 256. This was changed to 1024 in Clang 7.
# It must be increased on Clang 6 and below to ensure that the dnn examples don't error out.
list(APPEND active_compile_opts "-ftemplate-depth=500")
endif()
if (MSVC)
# By default Visual Studio does not support .obj files with more than 65k sections.
# However, code generated by file_to_code_ex and code using DNN module can have
# them. So this flag enables > 65k sections, but produces .obj files
# that will not be readable by VS 2005.
list(APPEND active_compile_opts "/bigobj")
# Build dlib with all cores. Don't propagate the setting to client programs
# though since they might compile large translation units that use too much
# RAM.
list(APPEND active_compile_opts_private "/MP")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.3)
# Clang can compile all Dlib's code at Windows platform. Tested with Clang 5
list(APPEND active_compile_opts -Xclang)
list(APPEND active_compile_opts -fcxx-exceptions)
endif()
endif()
# Including this cmake script into your cmake project will cause visual studio
# to build your project against the static C runtime.
cmake_minimum_required(VERSION 3.8.0)
if (MSVC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
option (DLIB_FORCE_MSVC_STATIC_RUNTIME "use static runtime" ON)
if (DLIB_FORCE_MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif ()
endif()
cmake_minimum_required(VERSION 3.8.0)
project(avx_test)
set(USE_AVX_INSTRUCTIONS ON CACHE BOOL "Use AVX instructions")
# Pull this in since it sets the AVX compile options by putting that kind of stuff into the active_compile_opts list.
include(../set_compiler_specific_options.cmake)
try_run(run_result compile_result ${PROJECT_BINARY_DIR}/avx_test_try_run_build ${CMAKE_CURRENT_LIST_DIR}/avx_test.cpp
COMPILE_DEFINITIONS ${active_compile_opts})
message(STATUS "run_result = ${run_result}")
message(STATUS "compile_result = ${compile_result}")
if ("${run_result}" EQUAL 0 AND compile_result)
message(STATUS "Ran AVX test program successfully, you have AVX available.")
else()
message(STATUS "Unable to run AVX test program, you don't seem to have AVX instructions available.")
# make this build fail so that calling try_compile statements will error in this case.
add_library(make_this_build_fail ${CMAKE_CURRENT_LIST_DIR}/this_file_doesnt_compile.cpp)
endif()
#include <immintrin.h>
int main()
{
__m256 x;
x = _mm256_set1_ps(1.23);
x = _mm256_add_ps(x,x);
return 0;
}
// ------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.8.0)
project(cuda_test)
include_directories(../../cuda)
add_definitions(-DDLIB_USE_CUDA)
# Override the FindCUDA.cmake setting to avoid duplication of host flags if using a toolchain:
option(CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" OFF)
find_package(CUDA 7.5 REQUIRED)
set(CUDA_HOST_COMPILATION_CPP ON)
list(APPEND CUDA_NVCC_FLAGS "-arch=sm_50;-std=c++14;-D__STRICT_ANSI__;-D_MWAITXINTRIN_H_INCLUDED;-D_FORCE_INLINES")
cuda_add_library(cuda_test STATIC cuda_test.cu )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment