raisimTech / raisimLib

Visit www.raisim.com
http://www.raisim.com
Other
341 stars 91 forks source link

"symbol not found in flat namespace '_omp_get_thread_num'" is occurred when running 'runner.py' in raisimGymTorch #479

Closed OnesoulKang closed 1 year ago

OnesoulKang commented 1 year ago

Hello, I am trying to do a project using raisim on m1 macbook air.

I solved the error related to omp.h that occurred when I ran raisimGymTorch's python setup.py develop by referring to the method #221.

However, when I run the example code later, the following error occurs. (base) onesoulkang@Hansols-MacBook-Air raisimGymTorch % python raisimGymTorch/env/envs/rsg_anymal/runner.py Traceback (most recent call last): File "/Users/onesoulkang/Desktop/workspace/raisimLib/raisimGymTorch/raisimGymTorch/env/envs/rsg_anymal/runner.py", line 4, in <module> from raisimGymTorch.env.bin.rsg_anymal import NormalSampler ImportError: dlopen(/Users/onesoulkang/Desktop/workspace/raisimLib/raisimGymTorch/raisimGymTorch/env/bin/rsg_anymal.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_omp_get_thread_num'

Is anyone have any idea about this? Thank you

jhwangbo commented 1 year ago

I also get that problem. The main issue is that your python is built for x86. Make sure that your Anaconda supports M1 (https://www.anaconda.com/blog/new-release-anaconda-distribution-now-supporting-m1). and also check if there is omp support for M1. The error you get is due to the fact that dynamic linker cannot find omp library built for M1. Let me know if you solved the problem. Thx

OnesoulKang commented 1 year ago

I read that openmp cannot be used with the clang compiler provided by Apple, so I installed and used the gcc compiler through brew install gcc I tested a very simple example like below.

#include <iostream>
#include <omp.h>

int main(){
    #pragma omp parallel
    printf("omptest %d\n",
               omp_get_thread_num());
}

and CMakeLists.txt is here.

cmake_minimum_required(VERSION 3.10)
project(minimum_openmp_project)

set(CMAKE_CXX_STANDARD 17)

message(${CMAKE_CXX_COMPILER})

find_package(OpenMP REQUIRED)

add_executable(omptest omptest.cpp)
target_link_libraries(omptest PRIVATE OpenMP::OpenMP_CXX)

This is the output of cmake

[main] Configuring project: omptest 
[proc] Executing command: /opt/homebrew/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/opt/homebrew/Cellar/gcc/13.1.0/bin/aarch64-apple-darwin22-gcc-13 -DCMAKE_CXX_COMPILER:FILEPATH=/opt/homebrew/Cellar/gcc/13.1.0/bin/aarch64-apple-darwin22-g++-13 -S/Users/onesoulkang/Desktop/workspace/pythonWorkspace/omptest -B/Users/onesoulkang/Desktop/workspace/pythonWorkspace/omptest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 13.1.0
[cmake] -- The CXX compiler identification is GNU 13.1.0
[cmake] -- Checking whether C compiler has -isysroot
[cmake] -- Checking whether C compiler has -isysroot - yes
[cmake] -- Checking whether C compiler supports OSX deployment target flag
[cmake] -- Checking whether C compiler supports OSX deployment target flag - yes
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: /opt/homebrew/Cellar/gcc/13.1.0/bin/aarch64-apple-darwin22-gcc-13 - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Checking whether CXX compiler has -isysroot
[cmake] -- Checking whether CXX compiler has -isysroot - yes
[cmake] -- Checking whether CXX compiler supports OSX deployment target flag
[cmake] -- Checking whether CXX compiler supports OSX deployment target flag - yes
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: /opt/homebrew/Cellar/gcc/13.1.0/bin/aarch64-apple-darwin22-g++-13 - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] /opt/homebrew/Cellar/gcc/13.1.0/bin/aarch64-apple-darwin22-g++-13
[cmake] -- Found OpenMP_C: -fopenmp (found version "4.5") 
[cmake] -- Found OpenMP_CXX: -fopenmp (found version "4.5") 
[cmake] -- Found OpenMP: TRUE (found version "4.5")  
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /Users/onesoulkang/Desktop/workspace/pythonWorkspace/omptest/build

After make, I could see that the file was executed normally.

(base) onesoulkang@Hansols-MacBook-Air build % ./omptest
omptest 1
omptest 0
omptest 2
omptest 4
omptest 5
omptest 3
omptest 6
omptest 7

In my opinion, openmp seems to work fine with the gcc compiler. So I think it would work if I could specify the gcc compiler for setup.py. Is there a way to specify the gcc compiler for setup.py?

jhwangbo commented 1 year ago

You can set CXX and CC environment variable to the compiler that you want to use. I think this is the same in Mac

OnesoulKang commented 1 year ago

As your answer, I set CC and CXX environment variables and tried to compile. But there were some errors about mno-avx2 command line options.

After googled about that, I changed the compiler from gcc to llvm with brew install llvm. And I checked that llvm support openmp.

using llvm(from brew) solves the problems! the example is running at about 50k fps.

I have one more question. Despite using m1 chip, visualization is not possible when using raisimUnity for m1, but rather using raisimUnity for Mac. Anyway, it's not a big problem since I can visualize it, but if you have time, I'd like you to check it out in this regard.

jhwangbo commented 1 year ago

Thanks for the update. I will try it myself and update the documentation.