Hi Siebren,
I tried to link statically and it did not work for me, similar errors as to
what you are getting.
The way the macro is supposed to work -- it checks for the MKL link tool and if
it is available, it uses and provides the libraries needed. If it is
unavailable (or throws errors or whatever else the case may be), then FindBLAS
reverts back to the way it handles MKL currently.
I have attached the module that provides the interface to the MKL command line
tool as well as the changed FindBLAS module that uses it. Major caveat here --
I have not used these since 2012, with one of the Intel 12.something compilers
and CMake 2.8. I did a quick diff on the FindBLAS in the current version and
the CMake 2.8 version and there's only very minor changes that shouldn't affect
this working. If it turns out this is useful and close to functional, then we
can work on getting it current.
Tim
----- Original Message -----
From: "Siebren Reker" <[email protected]>
To: "tim gallagher" <[email protected]>
Cc: [email protected]
Sent: Thursday, August 27, 2015 11:16:34 AM
Subject: Re: [cmake-developers] Is there an official FindMKL module?
Hi Tim,
On Thu, Aug 27, 2015 at 4:32 PM, Tim Gallagher < [email protected] >
wrote:
Siebren,
We've never really used static linking so I am not sure if it ever really
worked. I can try and let you know.
Could you please do so? Just to verify that I'm not doing something obviously
wrong
<blockquote>
However, I'm having flashbacks here to something I thought I had done before. I
dug through my emails and back in 2012 I had signed up to maintain a new module
that provided a macro to interface with the MKL tool and generated the proper
linking based on what it reported. My colleague and I had written it because we
were tired of the difficulties in the current modules. This new module provided
a macro and the FindBLAS and FindLAPACK modules would call the macro to get the
link information.
</blockquote>
Sounds clean, but are you sure the tool is always available?
<blockquote>
I got push access to create the topic branch but then I don't know what
happened. I don't know if I never pushed it, or it never got
tested/approved/checked, no clue. I actually still have all of the modules and
changes I had made, but it was in version 2.8. I wish I could remember if I had
actually pushed it to CMake or not, but I really don't remember why it never
happened.
So anyway, now that we're discussing it again, if the CMake community wants the
MKL support improved, I can dust off the modules and see what it would take to
get it officially in the stream.
</blockquote>
I'd be more than happy to test this. I've found a number of hits on Google for
FindMKL.cmake files. I certainly wasn't alone in having trouble to get this to
work (doesn't mean much of course).
best,
Siebren
<blockquote>
Tim
From: "Siebren Reker" < [email protected] >
To: "tim gallagher" < [email protected] >
Cc: [email protected]
Sent: Thursday, August 27, 2015 6:32:17 AM
Subject: Re: [cmake-developers] Is there an official FindMKL module?
Hi Tim,
Quick add-on to my previous email. With BLA_STATIC ON, I see from the
CMakeError.log that the static libraries ARE found (I was trusting the), but
the linking of the test program goes wrong:
undefined reference to `mkl_blas_sgemv`
But that function IS implemented in one of the three libraries that is found,
in my case in libmkl_sequential.a
So this is probably a linking/ library ordering error.
Indeed, Intel fora and the link advisor I mentioned earlier also report the
need for grouping these as in
-Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a
${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_sequential.a
-Wl,--end-group
Is my understanding correct, and can this be fixed?
kind regards,
Siebren
On Thu, Aug 27, 2015 at 11:50 AM, Siebren Reker < [email protected] >
wrote:
<blockquote>
Hi Tim,
That is encouraging, thanks. I went back and tried harder this time, when I
specified BLA_VENDOR precisely and leave BLA_STATIC off, I am able to get to
the correct versions.
In the very same directory where the shared libraries are found, I have the
static libraries as well, but BLA_STATIC on in that case does not find the
libraries.
I've read up a bit on this now, so maybe the following information is helpful:
This is a CMake 3.3.0 installation
My project has both C and Fortran enabled
I call it as follows:
set( BLA_STATIC ON)
set( BLA_VENDOR "Intel10_64lp_seq")
find_package( BLAS )
Is BLA_STATIC = ON working for you?
A separate question I have is if the linker command that will be produced
afterwards is of course different from the one supplied by Intel in their tool.
Should that not concern me?
kind regards,
Siebren
On Wed, Aug 26, 2015 at 4:59 PM, Tim Gallagher < [email protected] >
wrote:
<blockquote>
We sometime struggled to get it working, but we never had to resort to using a
FindMKL -- FindBLAS and FindLAPACK work just fine for us, provided we do things
"correctly."
So long as we have sourced the mklvars script that ships with Intel MKL and we
put:
BLA_VENDOR =Intel10_64lp_seq ccmake /path/to/source/dir
Then everything works fine and we have no issues. So we have to give CMake a
hint that we want to pick the Intel version rather than the generic one (and
we're using the sequential, 64bit MKL -- if you look in FindBLAS you can see
other vendor types).
Have you had things fail when you setup your environment variables using the
scripts Intel provides and when you set the BLA_VENDOR hint as an environment
variable?
Tim
From: "Siebren Reker" < [email protected] >
To: [email protected]
Sent: Wednesday, August 26, 2015 10:18:44 AM
Subject: [cmake-developers] Is there an official FindMKL module?
Hello,
I am using the find_package() command to load settings for the Intel Math
Kernel Library (MKL). This works through a custom FindMKL.cmake module that
I've made for myself.
However, when looking at:
https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/
I can tell that what I've done is likely only correct for my specific case, and
certainly not robust against library version changes and various other changes
(openmp, static vs dynamic linking etc.).
Instead of a FindMKL.cmake module, an alternative is to have MKL be discovered
in the FindBLAS or FindLAPACK modules, but according to what I can find on the
bug tracker, that solution is also in a fairly broken state:
Bug 14138: http://www.cmake.org/Bug/view.php?id=14138
Bug 13543: http://www.cmake.org/Bug/view.php?id=13543
Bug 13528: http://www.cmake.org/Bug/view.php?id=13528
Google tells me that many people have (like me) created their own FindMKL.cmake
module, which are equally specific and tailored.
Is anyone aware of a more "official" FindMKL module available somewhere, or at
least something that is being somewhat maintained, either by someone at Kitware
or Intel? Or of a plan to develop something like that?
kind regards,
Siebren Reker
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers
</blockquote>
</blockquote>
</blockquote>
# - Find BLAS library
# This module finds an installed fortran library that implements the BLAS
# linear-algebra interface (see http://www.netlib.org/blas/).
# The list of libraries searched for is taken
# from the autoconf macro file, acx_blas.m4 (distributed at
# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
#
# This module sets the following variables:
# BLAS_FOUND - set to true if a library implementing the BLAS interface
# is found
# BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
# and -L).
# BLAS_LIBRARIES - uncached list of libraries (using full path name) to
# link against to use BLAS
# BLAS95_LIBRARIES - uncached list of libraries (using full path name)
# to link against to use BLAS95 interface
# BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
# is found
# BLA_STATIC if set on this determines what kind of linkage we do (static)
# BLA_VENDOR if set checks only the specified vendor, if not set checks
# all the possibilities
# BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
##########
### List of vendors (BLA_VENDOR) valid in this module
## Goto,ATLAS PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
## Intel( older versions of mkl 32 and 64 bit), ACML,ACML_MP,ACML_GPU,Apple, NAS, Generic
# C/CXX should be enabled to use Intel mkl
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
include(CheckFunctionExists)
include(CheckFortranFunctionExists)
include(GetIntelMKLInfo)
set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# Check the language being used
get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
if( _LANGUAGES_ MATCHES Fortran )
set( _CHECK_FORTRAN TRUE )
elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
set( _CHECK_FORTRAN FALSE )
else()
if(BLAS_FIND_REQUIRED)
message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
else(BLAS_FIND_REQUIRED)
message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
return()
endif(BLAS_FIND_REQUIRED)
endif( )
macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _threads _math)
# This macro checks for the existence of the combination of fortran libraries
# given by _list. If the combination is found, this macro checks (using the
# Check_Fortran_Function_Exists macro) whether can link against that library
# combination using the name of a routine given by _name using the linker
# flags given by _flags. If the combination of libraries is found and passes
# the link test, LIBRARIES is set to the list of complete library paths that
# have been found. Otherwise, LIBRARIES is set to FALSE.
# N.B. _prefix is the prefix applied to the names of all cached variables that
# are generated internally and marked advanced by this macro.
set(_libdir ${ARGN})
set(_libraries_work TRUE)
set(${LIBRARIES})
set(_combined_name)
if (NOT _libdir)
if (WIN32)
set(_libdir ENV LIB)
elseif (APPLE)
set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH)
else ()
set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH)
endif ()
endif ()
foreach(_library ${_list})
set(_combined_name ${_combined_name}_${_library})
if(_libraries_work)
if (BLA_STATIC)
if (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif ( WIN32 )
if (APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else (APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif (APPLE)
else (BLA_STATIC)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# for ubuntu's libblas3gf and liblapack3gf packages
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
endif ()
endif (BLA_STATIC)
find_library(${_prefix}_${_library}_LIBRARY
NAMES ${_library}
PATHS ${_libdir}
)
mark_as_advanced(${_prefix}_${_library}_LIBRARY)
set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
endif(_libraries_work)
endforeach(_library ${_list})
if(_libraries_work)
# Test this combination of libraries.
set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads} ${_math})
#message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
if (_CHECK_FORTRAN)
check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
else()
check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
endif()
set(CMAKE_REQUIRED_LIBRARIES)
mark_as_advanced(${_prefix}${_combined_name}_WORKS)
set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
endif(_libraries_work)
if(NOT _libraries_work)
set(${LIBRARIES} FALSE)
endif(NOT _libraries_work)
#message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
endmacro(Check_Fortran_Libraries)
set(BLAS_LINKER_FLAGS)
set(BLAS_LIBRARIES)
set(BLAS95_LIBRARIES)
if ($ENV{BLA_VENDOR} MATCHES ".+")
set(BLA_VENDOR $ENV{BLA_VENDOR})
else ($ENV{BLA_VENDOR} MATCHES ".+")
if(NOT BLA_VENDOR)
set(BLA_VENDOR "All")
endif(NOT BLA_VENDOR)
endif ($ENV{BLA_VENDOR} MATCHES ".+")
if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
# gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"goto2"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
# BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
dgemm
""
"f77blas;atlas"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"sgemm;dgemm;blas"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
# BLAS in Alpha CXML library?
if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"cxml"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
# BLAS in Alpha DXML library? (now called CXML, see above)
if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"dxml"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
# BLAS in Sun Performance library?
if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
"-xlic_lib=sunperf"
"sunperf;sunmath"
""
""
)
if(BLAS_LIBRARIES)
set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
endif(BLAS_LIBRARIES)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
# BLAS in SCSL library? (SGI/Cray Scientific Library)
if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"scsl"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
# BLAS in SGIMATH library?
if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"complib.sgimath"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
# BLAS in IBM ESSL library? (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"essl;blas"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
#BLAS in acml library?
if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
)
# try to find acml in "standard" paths
if( WIN32 )
file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
else()
file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
endif()
if( WIN32 )
file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
else()
file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
endif()
list(GET _ACML_ROOT 0 _ACML_ROOT)
list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
if( _ACML_ROOT )
get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
if( SIZEOF_INTEGER EQUAL 8 )
set( _ACML_PATH_SUFFIX "_int64" )
else()
set( _ACML_PATH_SUFFIX "" )
endif()
if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
set( _ACML_COMPILER32 "ifort32" )
set( _ACML_COMPILER64 "ifort64" )
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
set( _ACML_COMPILER32 "sun32" )
set( _ACML_COMPILER64 "sun64" )
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
set( _ACML_COMPILER32 "pgi32" )
if( WIN32 )
set( _ACML_COMPILER64 "win64" )
else()
set( _ACML_COMPILER64 "pgi64" )
endif()
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
# 32 bit builds not supported on Open64 but for code simplicity
# We'll just use the same directory twice
set( _ACML_COMPILER32 "open64_64" )
set( _ACML_COMPILER64 "open64_64" )
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
set( _ACML_COMPILER32 "nag32" )
set( _ACML_COMPILER64 "nag64" )
else() #if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
set( _ACML_COMPILER32 "gfortran32" )
set( _ACML_COMPILER64 "gfortran64" )
endif()
if( BLA_VENDOR STREQUAL "ACML_MP" )
set(_ACML_MP_LIB_DIRS
"${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
"${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
else() #if( _BLAS_VENDOR STREQUAL "ACML" )
set(_ACML_LIB_DIRS
"${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
"${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
endif()
endif()
elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
endif()
if( BLA_VENDOR STREQUAL "ACML_MP" )
foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
check_fortran_libraries (
BLAS_LIBRARIES
BLAS
sgemm
""
"acml_mp;acml_mv"
""
${BLAS_ACML_MP_LIB_DIRS}
""
)
if( BLAS_LIBRARIES )
break()
endif()
endforeach()
elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
check_fortran_libraries (
BLAS_LIBRARIES
BLAS
sgemm
""
"acml;acml_mv;CALBLAS"
""
${BLAS_ACML_GPU_LIB_DIRS}
""
)
if( BLAS_LIBRARIES )
break()
endif()
endforeach()
else() #if( _BLAS_VENDOR STREQUAL "ACML" )
foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
check_fortran_libraries (
BLAS_LIBRARIES
BLAS
sgemm
""
"acml;acml_mv"
""
${BLAS_ACML_LIB_DIRS}
""
)
if( BLAS_LIBRARIES )
break()
endif()
endforeach()
endif()
# Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"acml;acml_mv"
""
""
)
endif(NOT BLAS_LIBRARIES)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"acml_mp;acml_mv"
""
""
)
endif(NOT BLAS_LIBRARIES)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"acml;acml_mv;CALBLAS"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif () # ACML
# Apple BLAS library?
if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
dgemm
""
"Accelerate"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
if ( NOT BLAS_LIBRARIES )
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
dgemm
""
"vecLib"
""
""
)
endif ( NOT BLAS_LIBRARIES )
endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
# Generic BLAS library?
if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"blas"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
#BLAS in intel mkl 10 library? (em64t 64bit)
if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
if((NOT BLAS_LIBRARIES) AND (NOT BLAS95_LIBRARIES))
message("Using tool!")
if(BLA_STATIC)
set(mkl_static 1)
else()
set(mkl_static 0)
endif()
if(BLA_F95)
set(mkl_blas95 1)
else()
set(mkl_blas95 0)
endif()
# Try intel64, mkl version 10.3, and lp64 (defaults for mkl_link_tool)
get_intel_mkl_info(mkl_flags
mkl_libs
mkl_threads
mkl_math
"intel64"
"lp64"
"10.3"
"${mkl_blas95}"
0
${mkl_static}
)
if(mkl_libs)
message("Tool1 worked!")
message("mkl_flags: ${mkl_flags}")
message("mkl_libs: ${mkl_libs}")
message("mkl_threads: ${mkl_threads}")
message("mkl_math: ${mkl_math}")
if (BLA_F95)
check_fortran_libraries(
BLAS95_LIBRARIES
BLAS
sgemm
"${mkl_flags}"
"${mkl_libs}"
"${mkl_threads}"
"${mkl_math}"
)
else()
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
"${mkl_flags}"
"${mkl_libs}"
"${mkl_threads}"
"${mkl_math}"
)
endif()
if(BLAS_LIBRARIES OR BLAS95_LIBRARIES)
message("We found something!")
set(BLAS_LINKER_FLAGS ${mkl_flags})
endif()
endif()
endif()
if((NOT BLAS_LIBRARIES) AND (NOT BLAS95_LIBRARIES))
message("Using tool2!")
# Try intel64, mkl version 10.3, and ilp64 (defaults for mkl_link_tool)
get_intel_mkl_info(mkl_flags
mkl_libs
mkl_threads
mkl_math
"intel64"
"ilp64"
"10.3"
"${mkl_blas95}"
0
${mkl_static}
)
if(mkl_libs)
if (BLA_F95)
check_fortran_libraries(
BLAS95_LIBRARIES
BLAS
sgemm
"${mkl_flags}"
"${mkl_libs}"
"${mkl_threads}"
"${mkl_math}"
)
else()
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
"${mkl_flags}"
"${mkl_libs}"
"${mkl_threads}"
"${mkl_math}"
)
endif()
if(BLAS_LIBRARIES OR BLAS95_LIBRARIES)
set(BLAS_LINKER_FLAGS ${mkl_flags})
endif()
endif()
endif()
# The new tool search failed, so proceed like it used to
if((NOT BLAS_LIBRARIES) AND (NOT BLAS95_LIBRARIES))
if (NOT WIN32)
set(LM "-lm")
endif ()
if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
find_package(Threads)
else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
find_package(Threads REQUIRED)
endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
if (WIN32)
if(BLA_F95)
if(NOT BLAS95_LIBRARIES)
check_fortran_libraries(
BLAS95_LIBRARIES
BLAS
sgemm
""
"mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
""
""
)
endif(NOT BLAS95_LIBRARIES)
else(BLA_F95)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
SGEMM
""
"mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
""
""
)
endif(NOT BLAS_LIBRARIES)
endif(BLA_F95)
else(WIN32)
if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
if(BLA_F95)
if(NOT BLAS95_LIBRARIES)
check_fortran_libraries(
BLAS95_LIBRARIES
BLAS
sgemm
""
"mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS95_LIBRARIES)
else(BLA_F95)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"mkl_intel;mkl_intel_thread;mkl_core;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS_LIBRARIES)
endif(BLA_F95)
endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
if(BLA_F95)
if(NOT BLAS95_LIBRARIES)
check_fortran_libraries(
BLAS95_LIBRARIES
BLAS
sgemm
""
"mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS95_LIBRARIES)
else(BLA_F95)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS_LIBRARIES)
endif(BLA_F95)
endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
endif (WIN32)
#older vesions of intel mkl libs
# BLAS in intel mkl library? (shared)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"mkl;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS_LIBRARIES)
#BLAS in intel mkl library? (static, 32bit)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"mkl_ia32;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS_LIBRARIES)
#BLAS in intel mkl library? (static, em64t 64bit)
if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"mkl_em64t;guide"
"${CMAKE_THREAD_LIBS_INIT}"
"${LM}"
)
endif(NOT BLAS_LIBRARIES)
endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
endif((NOT BLAS_LIBRARIES) AND (NOT BLAS95_LIBRARIES))
endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
if(BLA_F95)
if(BLAS95_LIBRARIES)
set(BLAS95_FOUND TRUE)
else(BLAS95_LIBRARIES)
set(BLAS95_FOUND FALSE)
endif(BLAS95_LIBRARIES)
if(NOT BLAS_FIND_QUIETLY)
if(BLAS95_FOUND)
message(STATUS "A library with BLAS95 API found.")
else(BLAS95_FOUND)
if(BLAS_FIND_REQUIRED)
message(FATAL_ERROR
"A required library with BLAS95 API not found. Please specify library location.")
else(BLAS_FIND_REQUIRED)
message(STATUS
"A library with BLAS95 API not found. Please specify library location.")
endif(BLAS_FIND_REQUIRED)
endif(BLAS95_FOUND)
endif(NOT BLAS_FIND_QUIETLY)
set(BLAS_FOUND TRUE)
set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
else(BLA_F95)
if(BLAS_LIBRARIES)
set(BLAS_FOUND TRUE)
else(BLAS_LIBRARIES)
set(BLAS_FOUND FALSE)
endif(BLAS_LIBRARIES)
if(NOT BLAS_FIND_QUIETLY)
if(BLAS_FOUND)
message(STATUS "A library with BLAS API found.")
else(BLAS_FOUND)
if(BLAS_FIND_REQUIRED)
message(FATAL_ERROR
"A required library with BLAS API not found. Please specify library location."
)
else(BLAS_FIND_REQUIRED)
message(STATUS
"A library with BLAS API not found. Please specify library location."
)
endif(BLAS_FIND_REQUIRED)
endif(BLAS_FOUND)
endif(NOT BLAS_FIND_QUIETLY)
endif(BLA_F95)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# - Provides a macro to interface with mkl_link_tool
# This module looks for the mkl_link_tool that is shipped with
# Intel 12 and newer compiler versions. The tool allows easy
# generation of link flags and libraries required for using MKL
# with various compilers. If found, the macro will return the
# required information to use MKL.
#
# Defines the following macro:
# get_intel_mkl_info(mkl_flags_out mkl_libs_out mkl_threads_out mkl_math_out blas95 lapack95 static)
# where
# mkl_flags_out - variable used to store the compiler flags for MKL
# mkl_libs_out - variable used to store the required libraries for MKL
# mkl_threads_out - variable used to store the thread library for MKL
# mkl_math_out - variable used to store the math library for MKL
# blas95 - if set, look for the F95 BLAS bindings
# lapack95 - if set, look for the F95 LAPACK bindings (can be set along with blas95 for both)
# static - if set, look for the static libraries for MKL
#
# The mkl_link_tool works for various compilers, but note: F95 bindings will only be found for
# the Intel compiler! Also, the mkl_threads_out and mkl_math_out variables are used because
# it may be desirable (in FindBLAS and FindLAPACK for example) to treat those libraries
# uniquely.
#
# TODO:
# Implement parallel options for mkl_link_tool to allow BLACS/scaLAPACK
#
#=============================================================================
# Copyright 2012 Andy Smith, Tim Gallagher
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
macro(get_intel_mkl_info
mkl_flags_out
mkl_libs_out
mkl_threads_out
mkl_math_out
blas95
lapack95
static)
set(${mkl_flags_out})
set(${mkl_libs_out})
set(${mkl_threads_out})
set(${mkl_math_out})
find_program(MKL_LINK_TOOL mkl_link_tool
HINTS $ENV{MKLROOT}/tools)
if (MKL_LINK_TOOL)
get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
if( _LANGUAGES_ MATCHES Fortran )
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")
set(mkl_compiler "intel_f")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU")
set(mkl_compiler "gnu_f")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "PGI")
set(mkl_compiler "pgi_f")
endif()
else()
if(${CMAKE_C_COMPILER_ID} STREQUAL "Intel")
set(mkl_compiler "intel_c")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
set(mkl_compiler "gnu_c")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "PGI")
set(mkl_compiler "pgi_c")
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "MSVC")
set(mkl_compiler "ms_c")
endif()
endif()
if(WIN32)
set(mkl_os "win")
elseif(APPLE)
set(mkl_os "mac")
else()
set(mkl_os "lnx")
endif()
# Set up the flags for the tool
set(mkl_tool_opts "-libs")
list(APPEND mkl_tool_opts "--compiler=${mkl_compiler}")
list(APPEND mkl_tool_opts "--os=${mkl_os}")
if(${blas95} AND ${lapack95})
list(APPEND mkl_tool_opts "--f95")
elseif(${lapack95})
list(APPEND mkl_tool_opts "--f95=lapack")
elseif(${blas95})
list(APPEND mkl_tool_opts "--f95=blas")
endif()
if(${static})
execute_process(COMMAND ${MKL_LINK_TOOL} ${mkl_tool_opts} "-l" "static"
OUTPUT_VARIABLE _mkl_libs ERROR_VARIABLE myerr)
# If a bad set of options is chosen, such as non-Intel compiler with F95,
# then the output is empty and we don't want to return anything. So if the
# variable is defined, proceed through the process.
if(_mkl_libs)
# Search for pthreads because it has to be treated specially.
# It is ill-advised to statically link against pthreads, and
# the mkl_link_tool gives the dynamic version.
string(FIND "${_mkl_libs}" "-lpthread" pthreads_present)
if(pthreads_present GREATER -1)
string(REGEX REPLACE "-lpthread" " " _mkl_libs ${_mkl_libs})
set(pthreads_lib "-lpthread")
endif()
# Search for math because it has to be treated specially.
# It is ill-advised to statically link this too.
string(FIND "${_mkl_libs}" "-lm" math_present)
if(math_present GREATER -1)
string(REGEX REPLACE "-lm" " " _mkl_libs ${_mkl_libs})
set(math_lib "-lm")
endif()
# The tool sends out some information with $(MKLROOT) in it, but this
# needs to be replaced with the actual value of MKLROOT in the environment
string(REGEX REPLACE "\\$\\(MKLROOT\\)" "$ENV{MKLROOT}" _mkl_libs ${_mkl_libs})
string(STRIP ${_mkl_libs} _mkl_libs)
# There is a set of libraries that are passed as flags to the linker, so
# we need to find the bounds of that section and extract it
string(FIND "${_mkl_libs}" "-Wl,--start-group" FLAG_START)
string(FIND "${_mkl_libs}" "-Wl,--end-group" FLAG_END)
string(LENGTH "-Wl,--end-group" END_GROUP_LENGTH)
math(EXPR FLAG_LENGTH "${FLAG_END} - ${FLAG_START} + ${END_GROUP_LENGTH}")
string(SUBSTRING "${_mkl_libs}" ${FLAG_START} ${FLAG_LENGTH} static_flags)
# Strip out stuff between the -Wl,
string(REGEX REPLACE "${static_flags}" " " _mkl_libs ${_mkl_libs})
# If there is anything left, we need to parse it for either flags
# or fully-resolved libraries
string(LENGTH ${_mkl_libs} FLAG_START)
if(FLAG_START GREATER 0)
if (WIN32)
set(SUFFIX .lib ${SUFFIX})
endif ( WIN32 )
if (APPLE)
set(SUFFIX .lib ${SUFFIX})
else (APPLE)
set(SUFFIX .a ${SUFFIX})
endif (APPLE)
set(f95_libs_out)
set(f95_flags_out)
# Pull out all the flags like openmp, pgf90libs, etc
string(REGEX MATCHALL "[, ]-([^\", ]+)" extra_flags
"${_mkl_libs}")
foreach(_flag ${extra_flags})
string(REGEX REPLACE "${_flag}" " " _mkl_libs ${_mkl_libs})
STRING(STRIP ${_flag} _flag)
list(APPEND f95_flags_out ${_flag})
endforeach()
# All that should be left now is fully-resolved libraries
string(REGEX REPLACE "[ ]+" ";" f95_libs ${_mkl_libs})
foreach(_lib ${f95_libs})
string(REGEX REPLACE "^.*\\/lib" "" stripped_lib ${_lib})
foreach(suf ${SUFFIX})
set(matcher "${suf}+$")
string(REGEX REPLACE "${matcher}" "" stripped_lib ${stripped_lib})
endforeach()
list(APPEND f95_libs_out ${stripped_lib})
endforeach()
endif()
endif()
else()
execute_process(COMMAND ${MKL_LINK_TOOL} ${mkl_tool_opts}
OUTPUT_VARIABLE _mkl_libs ERROR_VARIABLE myerr)
# Just as before, if the _mkl_libs variable exists, we actually have data to process
if(_mkl_libs)
# The tool sends out some information with $(MKLROOT) in it, but this
# needs to be replaced with the actual value of MKLROOT in the environment
string(REGEX REPLACE "\\$\\(MKLROOT\\)" "$ENV{MKLROOT}" _mkl_libs ${_mkl_libs})
# Search for pthreads because it has to be treated specially
string(FIND "${_mkl_libs}" "-lpthreads" pthreads_present)
if(pthreads_present GREATER -1)
string(REGEX REPLACE "-lpthreads" " " _mkl_libs ${_mkl_libs})
set(pthreads_lib "-lpthreads")
endif()
# Search for math because it has to be treated specially.
string(FIND "${_mkl_libs}" "-lm" math_present)
if(math_present GREATER -1)
string(REGEX REPLACE "-lm" " " _mkl_libs ${_mkl_libs})
set(math_lib "-lm")
endif()
# It provides the full path to link with using -L, but the way
# FindBLAS and FindLAPACK are done, this is uneeded so it's removed
string(REGEX MATCHALL "[, ]-L([^\", ]+)" lib_dirs
"${_mkl_libs}")
foreach(_libdir ${lib_dirs})
string(REGEX REPLACE "${_libdir}" "" _mkl_libs ${_mkl_libs})
endforeach()
# Find any remaining -llibraries
string(REGEX MATCHALL "[, ]-l([^\", ]+)" library_name_flags
"${_mkl_libs}")
foreach(_lib ${library_name_flags})
string(REGEX REPLACE "${_lib}" " " _mkl_libs ${_mkl_libs})
endforeach()
# Find any flags needed
set(f95_flags_out)
string(REGEX MATCHALL "[, ]-([^\", ]+)" extra_flags
"${_mkl_libs}")
foreach(_flag ${extra_flags})
string(REGEX REPLACE "${_flag}" " " _mkl_libs ${_mkl_libs})
STRING(STRIP ${_flag} _flag)
list(APPEND f95_flags_out ${_flag})
endforeach()
endif()
endif()
# Output all of the data we found
set(_mkl_libs)
foreach( LIB ${library_name_flags} )
string( REGEX REPLACE "^[, ]-l|[\t \n]+$" "" LIB ${LIB})
list(APPEND _mkl_libs ${LIB} )
endforeach()
if(NOT static_flags)
set(static_flags "")
endif()
if(NOT f95_flags_out)
set(f95_flags_out "")
endif()
set(_mkl_flags ${static_flags} ${f95_flags_out})
if(f95_libs_out)
list(APPEND ${mkl_libs_out} ${f95_libs_out})
endif()
set(${mkl_flags_out} ${_mkl_flags})
list(APPEND ${mkl_libs_out} ${_mkl_libs})
set(${mkl_threads_out} ${pthreads_lib})
set(${mkl_math_out} ${math_lib})
endif(MKL_LINK_TOOL)
endmacro()
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers