xtensor-stack / xtensor-blas

BLAS extension to xtensor
BSD 3-Clause "New" or "Revised" License
158 stars 55 forks source link

Using XTENSOR_USE_TBB with xtensor-blas fails compilation #118

Open fakufaku opened 5 years ago

fakufaku commented 5 years ago

Hi, I am trying to use both xtensor-blas and TBB acceleration at the same time. However, the compilation fails.

I am using the following CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(test_blas)

# Try to use only anaconda provided stuff
set(CMAKE_PREFIX_PATH /Users/scheibler/anaconda3/envs/mixiva ${CMAKE_PREFIX_PATH})

find_package(xtl REQUIRED)
find_package(xtensor REQUIRED)

add_executable(test_blas src/test_blas.cpp)

OPTION(XTENSOR_USE_XSIMD "simd acceleration for xtensor" ON)
OPTION(XTENSOR_USE_TBB "enable parallelization using intel TBB" ON)

if(XTENSOR_USE_XSIMD)
    set(xsimd_REQUIRED_VERSION 7.0.0)
    find_package(xsimd ${xsimd_REQUIRED_VERSION} REQUIRED)
    message(STATUS "Found xsimd: ${xsimd_INCLUDE_DIRS}/xsimd")
endif()

if(XTENSOR_USE_TBB)
    set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
    find_package(TBB REQUIRED)
    message(STATUS "Found intel TBB: ${TBB_INCLUDE_DIRS}")
endif()

if(MSVC)
    target_compile_options(test_blas PRIVATE /EHsc /MP /bigobj)
    set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
    CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
    (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
    target_compile_options(test_blas PRIVATE -march=native -std=c++14)
endif()

add_definitions(-DHAVE_CBLAS=1)
add_definitions(-DXTENSOR_USE_TBB)
add_definitions(-DXTENSOR_USE_SIMD)

# set(BLA_VENDOR Intel10_64lp)

if (WIN32)
    find_package(OpenBLAS REQUIRED)
    set(BLAS_LIBRARIES ${CMAKE_INSTALL_PREFIX}${OpenBLAS_LIBRARIES})
else()
    find_package(BLAS REQUIRED)
    find_package(LAPACK REQUIRED)
endif()

message(STATUS "BLAS VENDOR:    " ${BLA_VENDOR})
message(STATUS "BLAS LIBRARIES: " ${BLAS_LIBRARIES})

target_link_libraries(test_blas xtensor ${BLAS_LIBRARIES} tbb)

And the code is

#include <iostream>
#include <xtensor/xtensor.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor-blas/xlinalg.hpp>

int main()
{
  xt::xtensor<double, 2, xt::layout_type::row_major> x = xt::random::randn<double>({1000, 1000});
  xt::xtensor<double, 2, xt::layout_type::row_major> y = xt::random::randn<double>({1000, 1000});
  auto y_T = xt::transpose(y);

  xt::xtensor<double, 2> z = xt::linalg::dot(x, y_T);

  for (size_t i ; i < 10 ; i++)
    z = xt::linalg::dot(x, y_T);
  std::cout << z(0, 0) << std::endl;
}

The output of compilation is this.

make test_blas
Scanning dependencies of target test_blas
[ 50%] Building CXX object CMakeFiles/test_blas.dir/src/test_blas.cpp.o
In file included from /Users/scheibler/Documents/Research/Projects/Current/Separation/mixiva/test_xtensor/src/test_blas.cpp:5:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xtensor-blas/xlinalg.hpp:29:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xtensor-blas/xlapack.hpp:23:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/cxxlapack.cxx:37:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/cxxlapack.tcc:36:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/interface/interface.tcc:36:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/interface/bbcsd.tcc:39:
In file included from /Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/netlib.h:25:
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:973:39: error:
      expected ')'
                    const FLOAT      *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:968:20: note:
      to match this '('
LAPACK_IMPL(cggbak)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:990:39: error:
      expected ')'
                    FLOAT            *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:982:20: note:
      to match this '('
LAPACK_IMPL(cggbal)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:1087:39: error:
      expected ')'
                    FLOAT            *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:1070:20: note:
      to match this '('
LAPACK_IMPL(cggevx)(const char       *BALANC,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6787:39: error:
      expected ')'
                    const DOUBLE     *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6782:20: note:
      to match this '('
LAPACK_IMPL(dggbak)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6804:39: error:
      expected ')'
                    DOUBLE           *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6796:20: note:
      to match this '('
LAPACK_IMPL(dggbal)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6902:39: error:
      expected ')'
                    DOUBLE           *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:6884:20: note:
      to match this '('
LAPACK_IMPL(dggevx)(const char       *BALANC,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13109:39: error:
      expected ')'
                    const FLOAT      *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13104:20: note:
      to match this '('
LAPACK_IMPL(sggbak)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13126:39: error:
      expected ')'
                    FLOAT            *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13118:20: note:
      to match this '('
LAPACK_IMPL(sggbal)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13224:39: error:
      expected ')'
                    FLOAT            *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:13206:20: note:
      to match this '('
LAPACK_IMPL(sggevx)(const char       *BALANC,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19244:39: error:
      expected ')'
                    const DOUBLE     *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19239:20: note:
      to match this '('
LAPACK_IMPL(zggbak)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19261:39: error:
      expected ')'
                    DOUBLE           *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19253:20: note:
      to match this '('
LAPACK_IMPL(zggbal)(const char       *JOB,
                   ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19358:39: error:
      expected ')'
                    DOUBLE           *LSCALE,
                                      ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/sysctl.h:542:17: note:
      expanded from macro 'LSCALE'
#define LSCALE  1000            /* scaling for "fixed point" arithmetic */
                ^
/Users/scheibler/anaconda3/envs/mixiva/include/xflens/cxxlapack/netlib/interface/lapack.in.h:19341:20: note:
      to match this '('
LAPACK_IMPL(zggevx)(const char       *BALANC,
                   ^
12 errors generated.
make[3]: *** [CMakeFiles/test_blas.dir/src/test_blas.cpp.o] Error 1
make[2]: *** [CMakeFiles/test_blas.dir/all] Error 2
make[1]: *** [CMakeFiles/test_blas.dir/rule] Error 2
make: *** [test_blas] Error 2

The code is compiled on Mac OS X Mojave (10.14.4) with Apple LLVM

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

When I add #undef XTENSOR_USE_TBB at the beginning of the code, it compiles and runs as expected.

iminders commented 1 year ago

The same issue + 1

Add #undef XTENSOR_USE_TBB not work for me.

brccabral commented 1 month ago

Same issue described here https://github.com/xtensor-stack/xtensor/issues/2736