Skip to content

Commit 656d07a

Browse files
authored
Merge pull request #21 from jfdev001/mkl-config
Mkl config and doxygen
2 parents f78d1a6 + 0487023 commit 656d07a

17 files changed

+173
-2747
lines changed

CMakeLists.txt

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
44
option(BUILD_TESTING "Build tests" OFF)
55

66
option(ENABLE_SPBLAS "Build with SPBLAS" ON)
7+
option(ENABLE_FIND_INTEL_MKL "Find intel MKL config" OFF)
78

89
option(ENABLE_FFTPACK "Build with fftpack" OFF)
910
option(ENABLE_PFUNIT "Build with pFUnit" OFF)
1011
option(ENABLE_TEST_DRIVE "Build with test-drive" OFF)
1112

12-
1313
project(
1414
HelloSPBLAS
1515
VERSION 0.1.0
@@ -19,24 +19,62 @@ project(
1919

2020
# Set paths to Intel oneAPI MKL
2121
if(${ENABLE_SPBLAS})
22-
set(MKLROOT $ENV{MKLROOT} CACHE PATH "Installation directory of Intel MKL")
23-
if (NOT MKLROOT)
24-
message(FATAL_ERROR "MKLROOT environment variable is not set.")
22+
if (${ENABLE_FIND_INTEL_MKL})
23+
find_package(MKL CONFIG)
24+
get_target_property(MKLINCLUDE MKL::MKL INTERFACE_INCLUDE_DIRECTORIES)
25+
endif()
26+
27+
# manually set MKL vars
28+
if (NOT MKL_FOUND)
29+
message(STATUS "Did not find MKL, trying to use env vars/user input")
30+
set(MKLROOT $ENV{MKLROOT} CACHE PATH "Installation directory of Intel MKL")
31+
if (NOT MKLROOT)
32+
message(FATAL_ERROR "MKLROOT environment variable is not set.")
33+
endif()
34+
set(MKLLIB ${MKLROOT}/lib CACHE PATH "Path to Intel MKL Libraries")
35+
set(MKLINCLUDE ${MKLROOT}/include/ CACHE PATH "Path to Intel MKL include files")
36+
else()
37+
message(STATUS "Found MKL")
38+
endif()
39+
40+
if(NOT EXISTS "${MKLINCLUDE}/mkl_spblas.mod")
41+
set(NO_MKL_SPBLAS_MOD "
42+
=======================================================================
43+
${MKLINCLUDE} does not contain mkl_spblas.mod
44+
If you installed Intel MKL to a directory
45+
that requires root permissions,
46+
(e.g., /opt/intel/oneapi/mkl/latest/)
47+
```
48+
# alternatively... you could update secure path in sudo visudo
49+
sudo -i
50+
echo 'source /opt/intel/oneapi/setvars.sh > /dev/null' >> ~/.bashrc
51+
source ~/.bashrc
52+
your_mkl_include=/opt/intel/oneapi/mkl/latest/include
53+
ifx -c your_mkl_include/mkl_spblas.f90
54+
```
55+
otherwise if you installed to a directory
56+
that does not require root permissions, it
57+
should be sufficient to call
58+
```
59+
cd /your/mkl/include # replace with your local path
60+
ifx -c mkl_spblas.f90
61+
```
62+
=======================================================================
63+
")
64+
message(FATAL_ERROR "${NO_MKL_SPBLAS_MOD}")
2565
endif()
26-
set(MKLLIB ${MKLROOT}/lib CACHE PATH "Path to Intel MKL Libraries")
27-
set(MKLINCLUDE ${MKLROOT}/include CACHE PATH "Path to Intel MKL include files")
2866
endif()
2967

3068
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
3169
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3270

33-
# build externals with specified version corresponding to git tag
71+
# build dependenciesals with specified version corresponding to git tag
3472
include(FetchContent)
35-
message(STATUS "Build extern")
73+
message(STATUS "Build dependencies")
3674
set(fftpack_GIT_TAG main)
3775
set(pFUnit_GIT_TAG cf37fb694f7c015d3718c1b4f7f3e9a56613067a) # fixes fetch content
3876
set(test-drive_GIT_TAG main)
39-
add_subdirectory(extern)
77+
add_subdirectory(dependencies)
4078

4179
message(STATUS "Build src")
4280
include(GNUInstallDirs)

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Can easily use `pFUnit` or `test-drive` for unit testing.
88

99
Make sure you have the [Intel oneAPI HPC Toolkit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html?packages=hpc-toolkit&hpc-toolkit-os=linux&hpc-toolkit-lin=apt) or [Intel Fortran Essentials](https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit-download.html?packages=fortran-essentials&fortran-essentials-os=linux&fortran-essentials-lin=apt).
1010

11+
Make sure also that in your `${MKLROOT}/include` directory there is a file
12+
called `mkl_spblas.mod`. The most up to date version of Intel MKL does not
13+
ship with `mkl_spblas.mod` by default, so you have to compile it separately
14+
via `ifx -c /path/to/mkl_spblas.f90`.
15+
1116
Then, you can configure, build, and run tests for the project.
1217

1318
```shell
@@ -29,9 +34,7 @@ You can build the documentation separately with
2934
cmake --build build --target doxygen_docs
3035
```
3136

32-
Note that `doc/Doxygen.in` was generated using `doxygen -g doc/Doxygen.in`
33-
(see [doxygen tutorial](https://www.doxygen.nl/manual/starting.html)) and
34-
see [Documenting Fotran with Doxygen](https://en.wikibooks.org/wiki/Fortran/Documenting_Fortran) for more details.
37+
See [Documenting Fotran with Doxygen](https://en.wikibooks.org/wiki/Fortran/Documenting_Fortran) for some more details.
3538

3639
You can also check to see if a downstream project can find/fetch this package.
3740

cmake/helper.cmake

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,45 @@
66
# modified from fftpack
77

88
function(link_spblas targ)
9-
# Add include directories
10-
target_include_directories(
11-
${targ}
12-
PRIVATE ${MKLINCLUDE}
13-
)
9+
if (MKL_FOUND)
10+
# https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-macos/2023-0/cmake-config-for-onemkl.html
11+
target_compile_options(
12+
${targ} PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS>)
13+
target_include_directories(
14+
${targ} PUBLIC $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
15+
target_link_libraries(
16+
${targ} PUBLIC $<LINK_ONLY:MKL::MKL>)
17+
else()
18+
# Add include directories
19+
target_include_directories(
20+
${targ}
21+
PUBLIC ${MKLINCLUDE}
22+
)
1423

15-
# Specify the MKL libraries for linking
16-
target_link_libraries(
17-
${targ}
18-
PRIVATE
19-
# must be static
20-
${MKLLIB}/libmkl_blas95_ilp64.a
21-
22-
# must shared
23-
${MKLLIB}/libmkl_intel_ilp64.so
24-
${MKLLIB}/libmkl_sequential.so # or libmkl_intel_thread.so
25-
${MKLLIB}/libmkl_core.so
24+
# Specify the MKL libraries for linking
25+
target_link_libraries(
26+
${targ}
27+
PRIVATE
28+
# must be static
29+
${MKLLIB}/libmkl_blas95_ilp64.a
30+
31+
# must shared
32+
${MKLLIB}/libmkl_intel_ilp64.so
33+
${MKLLIB}/libmkl_sequential.so # or libmkl_intel_thread.so
34+
${MKLLIB}/libmkl_core.so
2635

27-
# standard shared libs
28-
pthread
29-
m
30-
dl
31-
)
36+
# standard shared libs
37+
pthread
38+
m
39+
dl
40+
)
3241

33-
target_compile_options(
34-
${targ}
35-
PRIVATE
36-
-i8 # required, otherwise segfaults
37-
)
42+
target_compile_options(
43+
${targ}
44+
PRIVATE
45+
-i8 # required, otherwise segfaults
46+
)
47+
endif()
3848
endfunction()
3949

4050
# Use to include and export headers

cmake/template.pc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
prefix = @CMAKE_INSTALL_PREFIX@
2-
libdir = ${prefix}/@CMAKE_INSTALL_FULL_LIBDIR@
2+
libdir = ${prefix}/@CMAKE_INSTALL_LIBDIR@
33
includedir = ${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
44

55
Name: @PROJECT_NAME@

config/intel_ubuntu_spblas

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/usr/bin/bash
2+
# @brief intel_ubunt_spblas [builddocs]
3+
# where buildodcs is any nonempty string to trigger doc build
4+
builddocs=$1
25
[[ -d build-spblas ]] && rm -rf build-spblas
3-
cmake -S . -B build-spblas -DCMAKE_Fortran_COMPILER=ifx -DBUILD_TESTING=ON
6+
cmake -S . -B build-spblas\
7+
-DCMAKE_Fortran_COMPILER=ifx\
8+
-DBUILD_TESTING=ON\
9+
-DENABLE_SPBLAS=ON\
10+
-DENABLE_FIND_INTEL_MKL=ON
411
cmake --build build-spblas
512
./build-spblas/test/test_spblas
13+
[[ -n $builddocs ]] && cmake --build build-spblas --target doxygen_docs

config/intel_ubuntu_test_drive

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/bash
22
# @brief Baseline configuration assuming standard oneapi installation via apt.
3+
builddocs=$1
34
(
45
curdir=$(pwd)
56
[[ $curdir == *"config"* ]] && echo "must be in root project dir" && exit 1
67
#[[ -d build ]] && rm -rf build
78
cmake -S . -B build\
89
-DBUILD_TESTING=ON\
9-
-DENABLE_SPBLAS=ON\
10+
-DENABLE_SPBLAS=OFF\
1011
-DENABLE_PFUNIT=OFF\
1112
-DENABLE_TEST_DRIVE=ON\
1213
-DCMAKE_Fortran_COMPILER=ifx\
@@ -15,8 +16,8 @@ cmake --build build
1516
cd build
1617
# name from test/CMakeLists.txt build_tests(FIRST_ARG ...)
1718
ctest -R test_drive_square_tests
18-
./build/test/test_spblas
19+
# test/test_spblas
1920
# build docs
20-
#cmake --build . --target doxygen_docs
21+
[[ -n $builddocs ]] && cmake --build . --target doxygen_docs
2122
)
2223

File renamed without changes.
File renamed without changes.

dependencies/pFUnit/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
message(STATUS "Downloading pFUnit")
2+
FetchContent_Declare(
3+
PFUNIT
4+
GIT_REPOSITORY "https://github.com/Goddard-Fortran-Ecosystem/pFUnit"
5+
GIT_TAG ${pFUnit_GIT_TAG}
6+
)
7+
FetchContent_MakeAvailable(PFUNIT)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
message(STATUS "Downloading test-drive")
2+
FetchContent_Declare(
3+
test-drive
4+
GIT_REPOSITORY "https://github.com/fortran-lang/test-drive"
5+
GIT_TAG ${test-drive_GIT_TAG}
6+
)
7+
FetchContent_MakeAvailable(test-drive)
8+
9+
set(test-drive_LIBRARY test-drive)
10+
set(test-drive_LIBRARY ${test-drive_LIBRARY} PARENT_SCOPE)
11+
12+
set(test-drive_INCLUDE_DIR ${test-drive_BINARY_DIR}/include)
13+
set(test-drive_INCLUDE_DIR ${test-drive_INCLUDE_DIR} PARENT_SCOPE)
14+

doc/CMakeLists.txt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
2-
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
3-
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
1+
set(DOXYGEN_OPTIMIZE_FOR_FORTRAN YES)
2+
set(DOXYGEN_WARNINGS YES) # ignored if EXTRACT_ALL YES
3+
4+
## https://stackoverflow.com/questions/8887810/how-to-get-doxygen-to-produce-call-caller-graphs-for-c-functions
5+
set(DOXYGEN_HAVE_DOT YES)
6+
set(DOXYGEN_EXTRACT_ALL YES)
7+
set(DOXYGEN_EXTRACT_PRIVATE YES)
8+
set(DOXYGEN_CALL_GRAPH YES)
9+
set(DOXYGEN_CALLER_GRAPH YES)
10+
set(DOXYGEN_GENERATE_TREEVIEW YES)
11+
set(DOXYGEN_RECURSIVE YES)
12+
13+
## https://stackoverflow.com/questions/52312850/no-modules-item-in-doxygen-for-fortran
14+
#set(DOXYGEN_EXTENSION_MAPPING "f90=Fortran f95=Fortran f03=Fortran f08=Fortran")
15+
set(DOXYGEN_SOURCE_BROWSER YES)
16+
# Text version of caller/call graph
17+
set(DOXYGEN_REFERENCED_BY_RELATION NO)
18+
set(DOXYGEN_REFERENCES_RELATION NO)
19+
20+
set(DOXYGEN_ENABLE_PREPROCESSING NO) # https://stackoverflow.com/questions/26043007/make-doxygen-document-the-ifdef-parts-too
421

522
doxygen_add_docs(doxygen_docs
623
${PROJECT_SOURCE_DIR}/src
724
${CMAKE_CURRENT_SOURCE_DIR}/mainpage.md
8-
CONFIG ${DOXYGEN_IN}
9-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
1025
COMMENT "Generating API documentation with Doxygen"
1126
)

0 commit comments

Comments
 (0)