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
22 changes: 21 additions & 1 deletion cmake/cblas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# Find the CBlas and lapack libraries
#
# It will search MKLML, OpenBlas, reference-cblas, extern-openblas in order.
# On APPLE, accelerate framework (apple's blas implementation) will be
# used, if applicable.
#
# If any cblas implementation found, the following variable will be set.
# CBLAS_PROVIDER # one of MKLML, OPENBLAS, REFERENCE
# CBLAS_PROVIDER # one of MKLML, ACCELERATE, OPENBLAS, REFERENCE
# CBLAS_INC_DIR # the include directory for cblas.
# CBLAS_LIBS # a list of libraries should be linked by paddle.
# # Each library should be full path to object file.
Expand Down Expand Up @@ -45,6 +47,24 @@ if(WITH_MKLML)
"(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
endif()

## find accelerate on apple
if(APPLE AND NOT DEFINED CBLAS_PROVIDER)
find_library(ACCELERATE_FRAMEWORK Accelerate)
if(ACCELERATE_FRAMEWORK)
message(STATUS "Accelerate framework found " "${ACCELERATE_FRAMEWORK}")

set(CBLAS_PROVIDER ACCELERATE)
# no need to setup include dir if it's accelerate
# set(CBLAS_INC_DIR "")
set(CBLAS_LIBRARIES ${ACCELERATE_FRAMEWORK})

add_definitions(-DPADDLE_USE_ACCELERATE)
add_definitions(-DLAPACK_FOUND)
else()
message(WARNING "Accelerate framework not found")
endif()
endif()

## Then find openblas.
if(NOT DEFINED CBLAS_PROVIDER)
set(OPENBLAS_ROOT
Expand Down
5 changes: 5 additions & 0 deletions paddle/fluid/platform/cpu_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ limitations under the License. */

#ifdef PADDLE_USE_OPENBLAS
#include <cblas.h>
#elif PADDLE_USE_ACCELERATE
#include <Accelerate/Accelerate.h>
#endif

namespace paddle {
Expand All @@ -45,6 +47,9 @@ void SetNumThreads(int num_threads) {
#elif defined(PADDLE_USE_REFERENCE_CBLAS)
// cblas not support multi-thread
return;
#elif defined(PADDLE_USE_ACCELERATE)
// not sure about apple's blas
return;
#else
PADDLE_THROW(platform::errors::Unimplemented(
"This library (except OPENBLAS, MKLML) is not supported yet, so the"
Expand Down
3 changes: 3 additions & 0 deletions paddle/phi/kernels/funcs/blas/blas.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#if defined(PADDLE_USE_OPENBLAS) || defined(PADDLE_USE_REFERENCE_CBLAS)
#include <cblas.h>
#elif defined(PADDLE_USE_ACCELERATE)
#include <Accelerate/Accelerate.h>
#define CBLAS_LAYOUT CBLAS_ORDER
#endif

namespace phi {
Expand Down
2 changes: 2 additions & 0 deletions paddle/phi/kernels/funcs/math_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ limitations under the License. */

#ifdef PADDLE_USE_OPENBLAS
#include <cblas.h>
#elif PADDLE_USE_ACCELERATE
#include <Accelerate/Accelerate.h>
#endif

#include <memory>
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ if(${len} GREATER_EQUAL 1)
${test_name}
"-Wl,-rpath,$<TARGET_FILE_DIR:${paddle_lib}> -Wl,-rpath,$<TARGET_FILE_DIR:phi> -Wl,-rpath,$<TARGET_FILE_DIR:pir> -Wl,-rpath,$<TARGET_FILE_DIR:common>"
)
if(ACCELERATE_FRAMEWORK)
target_link_libraries(${test_name} ${ACCELERATE_FRAMEWORK})
message(STATUS "linking to accelerate blas library in ${test_name}")
endif()
endif()
if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
target_link_libraries(${test_name} ${PYTHON_LIBRARIES})
Expand Down