Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/unix_cpu_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ jobs:
branch=$(git rev-parse --abbrev-ref HEAD)
buildname=$(if [ -z "$prnum" ]; then echo "$branch"; else echo "PR-$prnum"; fi)
dashboard=$(if [ -z "$prnum" ]; then echo "Continuous"; else echo "Experimental"; fi)
backend=$(if [ "$USE_MKL" == 1 ]; then echo "Intel-MKL"; else echo "FFTW/LAPACK/BLAS"; fi)
buildname="$buildname-cpu-$BLAS_BACKEND"
mkdir build && cd build
${CMAKE_PROGRAM} -G Ninja \
-DCMAKE_MAKE_PROGRAM:FILEPATH=${GITHUB_WORKSPACE}/ninja \
-DAF_BUILD_CUDA:BOOL=OFF -DAF_BUILD_OPENCL:BOOL=OFF \
-DAF_BUILD_UNIFIED:BOOL=OFF -DAF_BUILD_EXAMPLES:BOOL=ON \
-DAF_BUILD_FORGE:BOOL=ON \
-DUSE_CPU_MKL:BOOL=$USE_MKL \
-DAF_COMPUTE_LIBRARY:STRING=$backend \
-DBUILDNAME:STRING=${buildname} ..
echo "CTEST_DASHBOARD=${dashboard}" >> $GITHUB_ENV

Expand Down
40 changes: 23 additions & 17 deletions .github/workflows/win_cpu_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,50 @@ jobs:
runs-on: windows-latest
env:
VCPKG_HASH: 5568f110b509a9fd90711978a7cb76bae75bb092 # vcpkg release tag 2021.05.12 with Forge v1.0.7 update
VCPKG_DEFAULT_TRIPLET: x64-windows
steps:
- name: Checkout Repository
uses: actions/checkout@master

- name: VCPKG Binary Cache
- name: VCPKG Cache
uses: actions/cache@v2
id: vcpkg-bin-cache
id: vcpkg-cache
with:
path: vcpkg_cache
key: vcpkg_bin_cache_${{ env.VCPKG_HASH }} # vcpkg manifest baseline
path: ~/vcpkg
key: vcpkg-deps-${{ env.VCPKG_HASH }}

- name: Install VCPKG Dependencies
if: steps.vcpkg-cache.outputs.cache-hit != 'true'
run: |
cd ~
git clone --quiet --recursive https://github.com/microsoft/vcpkg.git
cd vcpkg
git checkout $env:VCPKG_HASH
.\bootstrap-vcpkg.bat
.\vcpkg.exe install boost-compute boost-functional boost-stacktrace fftw3 forge freeimage freetype glfw3 openblas
Remove-Item .\downloads,.\buildtrees,.\packages -Recurse -Force

- name: CMake Configure
run: |
$cwd = (Get-Item -Path ".\").FullName
Set-Location -Path ${env:VCPKG_INSTALLATION_ROOT}
git pull
.\bootstrap-vcpkg.bat
.\vcpkg.exe install --triplet x64-windows boost-compute boost-functional boost-stacktrace fftw3 forge freeimage freetype glfw3 openblas
Set-Location -Path $cwd
$ref = $env:GITHUB_REF | %{ if ($_ -match "refs/pull/[0-9]+/merge") { $_;} }
$prnum = $ref | %{$_.Split("/")[2]}
$branch = git branch --show-current
$buildname = if($prnum -eq $null) { $branch } else { "PR-$prnum" }
$dashboard = if($prnum -eq $null) { "Continuous" } else { "Experimental" }
$buildname = "$buildname-cpu-openblas"
mkdir build && cd build
New-Item -Path "${cwd}/vcpkg_cache" -ItemType "directory" -Force
$env:VCPKG_DEFAULT_BINARY_CACHE="${cwd}/vcpkg_cache"
cmake .. -G "Visual Studio 16 2019" -A x64 `
-DVCPKG_ROOT:PATH="~/vcpkg" `
-DVCPKG_MANIFEST_MODE:BOOL=OFF `
-DAF_BUILD_CUDA:BOOL=OFF -DAF_BUILD_OPENCL:BOOL=OFF `
-DAF_BUILD_UNIFIED:BOOL=OFF -DAF_BUILD_FORGE:BOOL=ON `
-DBUILDNAME:STRING="$buildname" `
-DVCPKG_ROOT:PATH="${env:VCPKG_INSTALLATION_ROOT}" `
-DVCPKG_MANIFEST_MODE:BOOL=OFF
-DAF_COMPUTE_LIBRARY:STRING="FFTW/LAPACK/BLAS"
echo "CTEST_DASHBOARD=${dashboard}" >> $env:GITHUB_ENV

- name: Build and Test
run: |
Set-Location -Path .\build
$Env:PATH += ";${env:VCPKG_INSTALLATION_ROOT}/installed/x64-windows/bin"
ctest -D Experimental --track ${CTEST_DASHBOARD} -T Test -T Submit -C Release -R cpu -E pinverse -j2
cd build
$vcpkg_path = (Resolve-Path ~).Path
$Env:PATH += ";${vcpkg_path}/vcpkg/installed/x64-windows/bin"
ctest -D Experimental --track ${CTEST_DASHBOARD} -T Test -T Submit -C RelWithDebInfo -R cpu -E pinverse -j2
44 changes: 43 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ option(AF_WITH_STACKTRACE "Add stacktraces to the error messages." ON)
option(AF_CACHE_KERNELS_TO_DISK "Enable caching kernels to disk" ON)
option(AF_WITH_STATIC_MKL "Link against static Intel MKL libraries" OFF)

set(AF_COMPUTE_LIBRARY "Intel-MKL"
CACHE STRING "Compute library for signal processing and linear algebra routines")
set_property(CACHE AF_COMPUTE_LIBRARY
PROPERTY STRINGS "Intel-MKL" "FFTW/LAPACK/BLAS")

if(WIN32)
set(AF_STACKTRACE_TYPE "Windbg" CACHE STRING "The type of backtrace features. Windbg(simple), None")
set_property(CACHE AF_STACKTRACE_TYPE PROPERTY STRINGS "Windbg" "None")
Expand Down Expand Up @@ -105,6 +110,21 @@ af_deprecate(BUILD_EXAMPLES AF_BUILD_EXAMPLES)
af_deprecate(USE_RELATIVE_TEST_DIR AF_WITH_RELATIVE_TEST_DIR)
af_deprecate(USE_FREEIMAGE_STATIC AF_WITH_STATIC_FREEIMAGE)
af_deprecate(USE_CPUID AF_WITH_CPUID)
if(DEFINED USE_CPU_MKL OR DEFINED USE_OPENCL_MKL)
# Cannot use af_deprecated as it expects the new and old variables to store values of
# same type. In this case, USE_*_MKL variables are BOOLs and AF_COMPUTE_LIBRARY is a STRING
message(DEPRECATION
"Variables USE_CPU_MKL/USE_OPENCL_MKL are deprecated. Use AF_COMPUTE_LIBRARY instead.")
message(WARNING
"USE_CPU_MKL/USE_OPENCL_MKL defined. These values take precendence over the value of
AF_COMPUTE_LIBRARY until they are removed to preserve existing build behavior.")
# Until USE_CPU_MKL and USE_OPENCL_MKL are removed, if they are defined, they take
# precendence and cmake will check and report error if Intel-MKL is not found
if(USE_CPU_MKL OR USE_OPENCL_MKL)
get_property(doc CACHE AF_COMPUTE_LIBRARY PROPERTY HELPSTRING)
set(AF_COMPUTE_LIBRARY "Intel-MKL" CACHE STRING "${doc}" FORCE)
endif()
endif()

mark_as_advanced(
AF_BUILD_FRAMEWORK
Expand All @@ -117,6 +137,7 @@ mark_as_advanced(
AF_WITH_STATIC_FREEIMAGE
AF_WITH_NONFREE
AF_WITH_IMAGEIO
AF_WITH_RELATIVE_TEST_DIR
AF_TEST_WITH_MTX_FILES
ArrayFire_DIR
Boost_INCLUDE_DIR
Expand All @@ -136,6 +157,27 @@ mark_as_advanced(
)
mark_as_advanced(CLEAR CUDA_VERSION)

# IF: the old USE_CPU_MKL/USE_OPENCL_MKL flags are present,
# THEN Irrespective of AF_COMPUTE_LIBRARY value, continue with MKL to preserve old
# behavior. Once the deprecated USE_CPU_MKL/USE_OPENCL_MKL are removed in later
# versions AF_COMPUTE_LIBRARY will take over total control of selecting CPU
# compute backend.
#
# Note that the default value of AF_COMPUTE_LIBRARY is Intel-MKL.
# Also, cmake doesn't have short-circuit of OR/AND conditions in if
if(${AF_BUILD_CPU} OR ${AF_BUILD_OPENCL})
if("${AF_COMPUTE_LIBRARY}" STREQUAL "Intel-MKL")
dependency_check(MKL_FOUND "Please ensure Intel-MKL / oneAPI-oneMKL is installed")
set(BUILD_WITH_MKL ON)
elseif("${AF_COMPUTE_LIBRARY}" STREQUAL "FFTW/LAPACK/BLAS")
dependency_check(FFTW_FOUND "FFTW not found")
dependency_check(CBLAS_FOUND "CBLAS not found")
if(UNIX AND NOT APPLE)
dependency_check(LAPACK_FOUND "LAPACK not found")
endif()
endif()
endif()

#Configure forge submodule
#forge is included in ALL target if AF_BUILD_FORGE is ON
#otherwise, forge is not built at all
Expand Down Expand Up @@ -373,7 +415,7 @@ install(FILES ${ArrayFire_BINARY_DIR}/cmake/install/ArrayFireConfig.cmake
DESTINATION ${AF_INSTALL_CMAKE_DIR}
COMPONENT cmake)

if((USE_CPU_MKL OR USE_OPENCL_MKL) AND AF_INSTALL_STANDALONE)
if(BUILD_WITH_MKL AND AF_INSTALL_STANDALONE)
if(TARGET MKL::ThreadingLibrary)
get_filename_component(mkl_tl ${MKL_ThreadingLibrary_LINK_LIBRARY} REALPATH)
install(FILES
Expand Down
5 changes: 5 additions & 0 deletions CMakeModules/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,8 @@ if(MKL_Static_FOUND AND NOT TARGET MKL::Static)
endif()
endif()
endif()

set(MKL_FOUND OFF)
if(MKL_Shared_FOUND OR MKL_Static_FOUND)
set(MKL_FOUND ON)
endif()
75 changes: 39 additions & 36 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"type": "String",
"value": "Debug"
},
"AF_COMPUTE_LIBRARY": {
"type": "String",
"value": "Intel-MKL"
},
"AF_BUILD_CPU": {
"type": "BOOL",
"value": "OFF"
Expand Down Expand Up @@ -56,33 +60,33 @@
}
},
{
"name": "ninja-cpu-debug",
"description": "Build CPU Backend with FFTW and a BLAS library using Ninja Generator in Debug Configuration",
"name": "ninja-cpu-mkl-debug",
"description": "Build CPU Backend using Intel MKL in Debug Configuration with Ninja Generator",
"inherits": "ninja-all-off-debug",
"cacheVariables": {
"AF_BUILD_CPU": "ON"
}
},
{
"name": "ninja-cpu-relwithdebinfo",
"description": "Build CPU Backend with FFTW and a BLAS library using Ninja Generator in RelWithDebInfo Configuration",
"inherits": "ninja-cpu-debug",
"name": "ninja-cpu-mkl-relwithdebinfo",
"description": "Build CPU Backend using Intel MKL in RelWithDebInfo Configuration with Ninja Generator",
"inherits": "ninja-cpu-mkl-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "ninja-cpu-mkl-debug",
"description": "Build CPU Backend using Intel MKL in Debug Configuration with Ninja Generator",
"inherits": "ninja-cpu-debug",
"name": "ninja-cpu-debug",
"description": "Build CPU Backend with FFTW and a BLAS library using Ninja Generator in Debug Configuration",
"inherits": "ninja-cpu-mkl-debug",
"cacheVariables": {
"USE_CPU_MKL": "ON"
"AF_COMPUTE_LIBRARY": "FFTW/LAPCK/BLAS"
}
},
{
"name": "ninja-cpu-mkl-relwithdebinfo",
"description": "Build CPU Backend using Intel MKL in RelWithDebInfo Configuration with Ninja Generator",
"inherits": "ninja-cpu-mkl-debug",
"name": "ninja-cpu-relwithdebinfo",
"description": "Build CPU Backend with FFTW and a BLAS library using Ninja Generator in RelWithDebInfo Configuration",
"inherits": "ninja-cpu-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
Expand All @@ -104,39 +108,39 @@
}
},
{
"name": "ninja-opencl-debug",
"name": "ninja-opencl-mkl-debug",
"description": "Build OpenCL Backend in debug configuration using Ninja Generator",
"inherits": "ninja-all-off-debug",
"cacheVariables": {
"AF_BUILD_OPENCL": "ON"
}
},
{
"name": "ninja-opencl-mkl-debug",
"description": "Build OpenCL Backend in debug configuration using Ninja Generator",
"inherits": "ninja-opencl-debug",
"name": "ninja-opencl-mkl-relwithdebinfo",
"description": "Build OpenCL Backend in RelWithDebInfo configuration using Ninja Generator. This preset uses Intel MKL for CPU fallback code.",
"inherits": "ninja-opencl-mkl-debug",
"cacheVariables": {
"USE_OPENCL_MKL": "ON"
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "ninja-opencl-relwithdebinfo",
"description": "Build OpenCL Backend in RelWithDebInfo configuration using Ninja Generator",
"inherits": "ninja-opencl-debug",
"name": "ninja-opencl-debug",
"description": "Build OpenCL Backend in debug configuration using Ninja Generator",
"inherits": "ninja-opencl-mkl-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"AF_COMPUTE_LIBRARY": "FFTW/LAPCK/BLAS"
}
},
{
"name": "ninja-opencl-mkl-relwithdebinfo",
"description": "Build OpenCL Backend in RelWithDebInfo configuration using Ninja Generator. This preset uses Intel MKL for CPU fallback code.",
"inherits": "ninja-opencl-mkl-debug",
"name": "ninja-opencl-relwithdebinfo",
"description": "Build OpenCL Backend in RelWithDebInfo configuration using Ninja Generator",
"inherits": "ninja-opencl-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "ninja-all-debug",
"name": "ninja-all-mkl-debug",
"description": "Build all feasible backends using Ninja Generator in Debug Configuraiton",
"inherits": "ninja-all-off-debug",
"cacheVariables": {
Expand All @@ -147,26 +151,25 @@
}
},
{
"name": "ninja-all-mkl-debug",
"description": "Build all feasible backends using Ninja Generator in Debug Configuraiton",
"inherits": "ninja-all-debug",
"name": "ninja-all-mkl-relwithdebinfo",
"description": "Build all feasible backends using Ninja Generator in RelWithDebInfo Configuraiton",
"inherits": "ninja-all-mkl-debug",
"cacheVariables": {
"USE_CPU_MKL": "ON",
"USE_OPENCL_MKL": "ON"
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "ninja-all-relwithdebinfo",
"description": "Build all feasible backends using Ninja Generator in RelWithDebInfo Configuraiton",
"inherits": "ninja-all-debug",
"name": "ninja-all-debug",
"description": "Build all feasible backends using Ninja Generator in Debug Configuraiton",
"inherits": "ninja-all-mkl-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
"AF_COMPUTE_LIBRARY": "FFTW/LAPCK/BLAS"
}
},
{
"name": "ninja-all-mkl-relwithdebinfo",
"name": "ninja-all-relwithdebinfo",
"description": "Build all feasible backends using Ninja Generator in RelWithDebInfo Configuraiton",
"inherits": "ninja-all-mkl-debug",
"inherits": "ninja-all-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ if(FreeImage_FOUND AND AF_WITH_IMAGEIO)
endif ()
endif()

if(USE_CPU_MKL OR USE_OPENCL_MKL)
if(BUILD_WITH_MKL)
target_compile_definitions(c_api_interface
INTERFACE
AF_MKL_INTERFACE_SIZE=${MKL_INTERFACE_INTEGER_SIZE}
Expand Down
41 changes: 13 additions & 28 deletions src/backend/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,51 +304,36 @@ target_compile_definitions(afcpu
AF_CPU
)

if(USE_CPU_MKL)
dependency_check(MKL_Shared_FOUND "MKL not found")
target_link_libraries(afcpu
PRIVATE
c_api_interface
cpp_api_interface
afcommon_interface
cpu_sort_by_key
Threads::Threads
)
if(BUILD_WITH_MKL)
target_compile_definitions(afcpu PRIVATE USE_MKL)
target_link_libraries(afcpu
PRIVATE
c_api_interface
cpp_api_interface
afcommon_interface
cpu_sort_by_key
Threads::Threads
)
if(AF_WITH_STATIC_MKL)
target_link_libraries(afcpu PRIVATE MKL::Static)
else()
target_link_libraries(afcpu PRIVATE MKL::RT)
endif()
else()
dependency_check(FFTW_FOUND "FFTW not found")
dependency_check(CBLAS_FOUND "CBLAS not found")

target_link_libraries(afcpu
PRIVATE
c_api_interface
cpp_api_interface
afcommon_interface
cpu_sort_by_key
${CBLAS_LIBRARIES}
FFTW::FFTW
FFTW::FFTWF
Threads::Threads
)
if(LAPACK_FOUND)
target_link_libraries(afcpu
PRIVATE
${LAPACK_LIBRARIES})
target_include_directories(afcpu
PRIVATE
${LAPACK_INCLUDE_DIR})
target_link_libraries(afcpu PRIVATE ${LAPACK_LIBRARIES})
target_include_directories(afcpu PRIVATE ${LAPACK_INCLUDE_DIR})
endif()
endif()

if(LAPACK_FOUND OR (USE_CPU_MKL AND MKL_Shared_FOUND))
target_compile_definitions(afcpu
PRIVATE
WITH_LINEAR_ALGEBRA)
if(LAPACK_FOUND OR BUILD_WITH_MKL)
target_compile_definitions(afcpu PRIVATE WITH_LINEAR_ALGEBRA)
endif()

af_split_debug_info(afcpu ${AF_INSTALL_LIB_DIR})
Expand Down
Loading