Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error, missing -lpthread for tests #172

Closed
greenpdx opened this issue Dec 29, 2017 · 10 comments
Closed

Build error, missing -lpthread for tests #172

greenpdx opened this issue Dec 29, 2017 · 10 comments
Labels
bug A confirmed library bug

Comments

@greenpdx
Copy link

Description

I had a problem building mkl-dnn. I fixed it with this patch but it is a hack.

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2a8e78ce..1ea11f9e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -42,7 +42,7 @@ endif()

add_executable(api-c api.c)
set_property(TARGET api-c PROPERTY C_STANDARD 99)
-target_link_libraries(api-c ${LIB_NAME} ${EXTRA_LIBS})
+target_link_libraries(api-c ${LIB_NAME} ${EXTRA_LIBS} -lpthread)
add_test(api-c api-c)

if(WIN32)

Environment

Intel MKL-DNN includes hardware-specific optimizations and may behave
differently on depending on the compiler and build environment. Include
the following information to help reproduce the issue:

  • CPU make and model (try lscpu)
    Architecture: x86_64
    CPU op-mode(s): 32-bit, 64-bit
    Byte Order: Little Endian
    CPU(s): 8
    On-line CPU(s) list: 0-7
    Thread(s) per core: 2
    Core(s) per socket: 4
    Socket(s): 1
    NUMA node(s): 1
    Vendor ID: GenuineIntel
    CPU family: 6
    Model: 60
    Model name: Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz
    Stepping: 3
    CPU MHz: 3500.000
    CPU max MHz: 3900.0000
    CPU min MHz: 800.0000
    BogoMIPS: 6996.45
    Virtualization: VT-x
    L1d cache: 32K
    L1i cache: 32K
    L2 cache: 256K
    L3 cache: 8192K
    NUMA node0 CPU(s): 0-7
    Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm xsaveopt dtherm ida arat pln pts

  • OS version (uname -a)
    Linux mlkdnn 4.4.0-104-generic benchdnn and rdpmc  #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

  • Compiler version (gcc --version)
    ubuntu@mlkdnn:~/mkl-dnn/tests$ clang -v
    clang version 5.0.0-3 (tags/RELEASE_500/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
    Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
    Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
    Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
    Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
    Candidate multilib: .;@m64
    Selected multilib: .;@m64

  • MKLROOT value (echo MKLROOT=$MKLROOT)
    echo MKLROOT=$MKLROOT
    MKLROOT=

  • CMake version (cmake --version)
    cmake version 3.9.1

  • CMake output log

Steps to reproduce

Please check that the issue is reproducible with the latest revision on
master. Include the steps to reproduce the issue. A short C/C++ program
or modified unit tests demonstrating the issue will greatly help
with the investigation.

[ 47%] Linking CXX executable test_convolution_backward_data_f32
/usr/bin/ld: gtest/libmkldnn_gtest.a(gtest-all.cc.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
tests/gtests/CMakeFiles/test_convolution_backward_data_f32.dir/build.make:125: recipe for target 'tests/gtests/test_convolution_backward_data_f32' failed
make[2]: *** [tests/gtests/test_convolution_backward_data_f32] Error 1
CMakeFiles/Makefile2:496: recipe for target 'tests/gtests/CMakeFiles/test_convolution_backward_data_f32.dir/all' failed
make[1]: *** [tests/gtests/CMakeFiles/test_convolution_backward_data_f32.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2

Actual behavior

Describe the behavior you see.

Expected behavior

Describe the behavior you expect.

@rsdubtso
Copy link

Thanks for the report. Can you please clarify: does the Clang you have support OpenMP? Can you just please paste the relevant portion of the cmake output?

@rsdubtso rsdubtso added the bug A confirmed library bug label Dec 29, 2017
@greenpdx
Copy link
Author

It found C but not C++.

cmake ..
-- The CXX compiler identification is Clang 5.0.0
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- Detecting Intel(R) MKL: trying mklml_intel
-- Intel(R) MKL: include /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/include
-- Intel(R) MKL: lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libmklml_intel.so
-- Intel(R) MKL: OpenMP lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libiomp5.so
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.13") found components: doxygen missing components: dot
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/mkl-dnn/build

@greenpdx
Copy link
Author

I just found this as a possible fix
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_CXX_LIB_NAMES "${CMAKE_CXX_LIB_NAMES} ${OpenMP_CXX_LIB_NAMES}")

@emfomenk
Copy link

Seems like the problem is exactly in mismatch of OpenMP flags in C and CXX.
Could you please dump the whole cmake output?

@emfomenk
Copy link

My current weird guess is that you make cmake use clang-5.0++ for C++ compiler, but not for C compiler. And C compiler has openmp, while C++ for some reasons doesn't.
Then cmake tries to detect whether it needs to add extra -lpthread (or similar) to a link line, and it seems for C compiler it hasn't. Which is not the case for C++.

By the way, how did you make cmake use clang instead of gcc? Did you specify CXX=clang++? If so, did you specify CC=clang?

@greenpdx
Copy link
Author

I did not specify

cmake ..
-- The CXX compiler identification is Clang 5.0.0
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- Detecting Intel(R) MKL: trying mklml_intel
-- Intel(R) MKL: include /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/include
-- Intel(R) MKL: lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libmklml_intel.so
-- Intel(R) MKL: OpenMP lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libiomp5.so
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.13") found components: doxygen missing components: dot
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/mkl-dnn/build

@emfomenk
Copy link

I am confused. Is this the whole output of cmake? I don't see the part where it dumps C compiler...

@greenpdx
Copy link
Author

greenpdx commented Dec 29, 2017

that is it. here is the steps I did to install and build mkl-dnn. I put all new projects in to new containers. allows me to not clutter up my desktop system.

Create new container and share /home/ubuntu and ssh authorized_keys,

sudo apt-get install cmake doxygen clang-5.0
** I had to link ln -s clang-5.0 clang and clang++, ..... for cmake to recognize clang
git clone git clone https://github.com/01org/mkl-dnn.git
cd mkl-dnn/
cd scripts/
./prepare_mkl.sh
cd ..
mkdir build
cd build
cmake ..
make

@emfomenk
Copy link

Hmm... really strange. Could you please clean the build directory and try the following:

CC=clang-5.0 CXX=clang++-5.0 cmake .. && make -j

@greenpdx
Copy link
Author

Thanks

-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: /usr/bin/clang-5.0
-- Check for working C compiler: /usr/bin/clang-5.0 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++-5.0
-- Check for working CXX compiler: /usr/bin/clang++-5.0 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- Detecting Intel(R) MKL: trying mklml_intel
-- Intel(R) MKL: include /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/include
-- Intel(R) MKL: lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libmklml_intel.so
-- Intel(R) MKL: OpenMP lib /home/ubuntu/mkl-dnn/external/mklml_lnx_2018.0.1.20171007/lib/libiomp5.so
-- Found OpenMP_C: -fopenmp=libomp (found version "3.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "3.1")
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.13") found components: doxygen missing components: dot
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/mkl-dnn/build

Running tests...
Test project /home/ubuntu/mkl-dnn/build
Start 1: simple-net-c
1/32 Test #1: simple-net-c ............................... Passed 0.06 sec
Start 2: simple-net-cpp
2/32 Test #2: simple-net-cpp ............................. Passed 0.03 sec
Start 3: simple-training-net-c
3/32 Test #3: simple-training-net-c ...................... Passed 3.04 sec
Start 4: simple-training-net-cpp
4/32 Test #4: simple-training-net-cpp .................... Passed 0.46 sec
Start 5: api-c
5/32 Test #5: api-c ...................................... Passed 0.01 sec
Start 6: test_c_symbols-c
6/32 Test #6: test_c_symbols-c ........................... Passed 0.01 sec
Start 7: test_iface_pd_iter
7/32 Test #7: test_iface_pd_iter ......................... Passed 0.01 sec
Start 8: test_iface_attr
8/32 Test #8: test_iface_attr ............................ Passed 0.01 sec
Start 9: test_sum
9/32 Test #9: test_sum ................................... Passed 0.23 sec
Start 10: test_reorder
10/32 Test #10: test_reorder ............................... Passed 2.93 sec
Start 11: test_concat
11/32 Test #11: test_concat ................................ Passed 0.02 sec
Start 12: test_softmax_forward
12/32 Test #12: test_softmax_forward ....................... Passed 1.55 sec
Start 13: test_eltwise
13/32 Test #13: test_eltwise ............................... Passed 19.90 sec
Start 14: test_relu
14/32 Test #14: test_relu .................................. Passed 2.42 sec
Start 15: test_lrn_forward
15/32 Test #15: test_lrn_forward ........................... Passed 5.56 sec
Start 16: test_lrn_backward
16/32 Test #16: test_lrn_backward .......................... Passed 13.85 sec
Start 17: test_pooling_forward
17/32 Test #17: test_pooling_forward ....................... Passed 7.08 sec
Start 18: test_pooling_backward
18/32 Test #18: test_pooling_backward ...................... Passed 7.03 sec
Start 19: test_batch_normalization
19/32 Test #19: test_batch_normalization ................... Passed 26.40 sec
Start 20: test_inner_product_forward
20/32 Test #20: test_inner_product_forward ................. Passed 0.13 sec
Start 21: test_inner_product_backward_data
21/32 Test #21: test_inner_product_backward_data ........... Passed 0.09 sec
Start 22: test_inner_product_backward_weights
22/32 Test #22: test_inner_product_backward_weights ........ Passed 0.49 sec
Start 23: test_convolution_format_any
23/32 Test #23: test_convolution_format_any ................ Passed 0.01 sec
Start 24: test_convolution_forward_f32
24/32 Test #24: test_convolution_forward_f32 ............... Passed 138.42 sec
Start 25: test_convolution_forward_s16s16s32
25/32 Test #25: test_convolution_forward_s16s16s32 ......... Passed 150.33 sec
Start 26: test_convolution_forward_u8s8s32
26/32 Test #26: test_convolution_forward_u8s8s32 ........... Passed 0.05 sec
Start 27: test_convolution_forward_u8s8fp
27/32 Test #27: test_convolution_forward_u8s8fp ............ Passed 0.03 sec
Start 28: test_convolution_relu_forward_f32
28/32 Test #28: test_convolution_relu_forward_f32 .......... Passed 29.90 sec
Start 29: test_convolution_relu_forward_s16s16s32
29/32 Test #29: test_convolution_relu_forward_s16s16s32 .... Passed 15.41 sec
Start 30: test_convolution_backward_data_f32
30/32 Test #30: test_convolution_backward_data_f32 ......... Passed 162.79 sec
Start 31: test_convolution_backward_data_s16s16s32
31/32 Test #31: test_convolution_backward_data_s16s16s32 ... Passed 15.78 sec
Start 32: test_convolution_backward_weights
32/32 Test #32: test_convolution_backward_weights .......... Passed 194.00 sec

100% tests passed, 0 tests failed out of 32

Total Test time (real) = 798.00 sec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A confirmed library bug
Projects
None yet
Development

No branches or pull requests

3 participants