Jump to content

Running SystemC on new Apple M1 silicon


William Lock

Recommended Posts

Managed to run SystemC on new Apple M1 silicon, following are the steps 

1. modify configure file, add the following code highlighted in red

     # check CPU architecture

     case ${target_cpu} in #(

         x86_64|amd64) :

             TARGET_ARCH="${TARGET_ARCH}64"

          CPU_ARCH="x86_64"

          QT_ARCH="x86_64" ;; #(

  x*86|i*86) :

             CPU_ARCH="i386"

          QT_ARCH="iX86" ;; #(

  powerpc64) :

             TARGET_ARCH="${TARGET_ARCH}ppc64"

          CPU_ARCH="ppc64"

          QT_ARCH="pthreads" ;; #(

  powerpc) :

             TARGET_ARCH="${TARGET_ARCH}ppc"

          CPU_ARCH="ppc"

          QT_ARCH="powerpc-apple-macosx" ;; #(

  arm) :

             TARGET_ARCH="${TARGET_ARCH}arm"

          CPU_ARCH="arm64"

          QT_ARCH="pthreads" ;;

 

          #(

  *) :

    as_fn_error $? "\"sorry...architecture not supported\"" "$LINENO" 5 ;;

2. install g++ using homebrew

brew install gcc

3. setting CXX  and point to the homebrew g++-11 in step 2, run configure

export CXX=g++-11 

./configure

4. make all

5. make check

I would like to encourage others to share their experience of porting systemC to this new mac silicon. 

Link to comment
Share on other sites

  • 3 weeks later...

Thanks William for this, worked as a charm for me. I've made similar changes to the configure for SystemC AMS and succeeded in building it too. Too bad a google search on build systemc apple m1 doesn't point to this, would have saved me some time.

Link to comment
Share on other sites

  • 3 weeks later...

Hi William,

When I open the configure.ac file it does not look like in your example (at least not if I open it with TextEdit on Mac)      

# check CPU architecture
     AS_CASE([${target_cpu}], dnl
       [x86_64|amd64], dnl
         [TARGET_ARCH="${TARGET_ARCH}64"
          CPU_ARCH="x86_64"
          QT_ARCH="x86_64"],
       [x*86|i*86], dnl
         [CPU_ARCH="i386"
          QT_ARCH="iX86"],
       [powerpc64], dnl
         [TARGET_ARCH="${TARGET_ARCH}ppc64"
          CPU_ARCH="ppc64"
          QT_ARCH="pthreads"],
       [powerpc], dnl
         [TARGET_ARCH="${TARGET_ARCH}ppc"
          CPU_ARCH="ppc"
          QT_ARCH="powerpc-apple-macosx"],
       [AC_MSG_ERROR("sorry...architecture not supported")])
 

So trying to translate from your example I ended up with something that looks like below

 

# check CPU architecture

     AS_CASE([${target_cpu}], dnl

       [x86_64|amd64], dnl

         [TARGET_ARCH="${TARGET_ARCH}64"

          CPU_ARCH="x86_64"

          QT_ARCH="x86_64"],

       [x*86|i*86], dnl

         [CPU_ARCH="i386"

          QT_ARCH="iX86"],

       [powerpc64], dnl

         [TARGET_ARCH="${TARGET_ARCH}ppc64"

          CPU_ARCH="ppc64"

          QT_ARCH="pthreads"],

       [powerpc], dnl

         [TARGET_ARCH="${TARGET_ARCH}ppc"

          CPU_ARCH="ppc"

          QT_ARCH="powerpc-apple-macosx"],

       [arm], dnl

         [TARGET_ARCH="${TARGET_ARCH}arm"

          CPU_ARCH="arm64"

          QT_ARCH="pthreads"],

       [AC_MSG_ERROR("sorry...architecture not supported")])

 

but hen running ./configure I always end up with "sorry...architecture not supported"....

so something I apparently do wrong but I can't understand what.

 

below what happens when I run ./configure:

michaellebert@Michaels-Mini systemc-2.3.3 % ./configure                  

checking build system type... arm-apple-darwin20.5.0

checking host system type... arm-apple-darwin20.5.0

checking target system type... arm-apple-darwin20.5.0

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... config/install-sh -c -d

checking for gawk... no

checking for mawk... no

checking for nawk... no

checking for awk... awk

checking whether make sets $(MAKE)... yes

checking whether make supports nested variables... yes

checking how to create a pax tar archive... gnutar

checking whether make supports nested variables... (cached) yes

checking whether the C++ compiler works... yes

checking for C++ compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C++ compiler... yes

checking whether g++-11 accepts -g... yes

checking for style of include used by make... GNU

checking dependency style of g++-11... gcc3

checking whether we are using a Clang/LLVM C++ compiler... no

checking for gcc... g++-11

checking whether we are using the GNU C compiler... yes

checking whether g++-11 accepts -g... yes

checking for g++-11 option to accept ISO C89... unsupported

checking whether g++-11 understands -c and -o together... yes

checking dependency style of g++-11... gcc3

checking whether we are using a Clang/LLVM C compiler... no

checking for ar... ar

checking the archiver (ar) interface... ar

checking dependency style of g++-11... gcc3

checking whether ln -s works... yes

configure: error: "sorry...architecture not supported"

michaellebert@Michaels-Mini systemc-2.3.3 %

 

BR//Michael Lebert

 

Link to comment
Share on other sites

You should not edit the configure file directly, but rather the file configure.ac. After that, you'll have to run the config/bootstrap to regenerate the build system. For this to work, you'll have to install GNU libtool, GNU automake, and GNU autoconf, e.g., through MacPorts.

Link to comment
Share on other sites

  • 3 months later...

Hi @William Lock and all,

 

Thanks for your instruction and I am able to build it on my macbook pro m1. However, I encounter problem with "make check" as all tests are failed. I also tried running the test in examples separately and it also failed with fault "zsh: segmentation fault  ./simple_async". Do you know anything about it?

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

Hi all,

I have followed your instructions by modifying the configure file to install systemC and make check passes all tests. However, I am somewhat of a beginner when it comes to CMake and was wondering if anyone could provide a basic CMakeLists.txt file I could use for a basic hello world program. I have tried multiple ways and I always either get a linker problem where the library is not found or a segmentation error when executing the executable.

 

Nevertheless, thank you for your amazing help on tackling this issue.

 

Best regards,

Leo

CMakeLists.txt

Link to comment
Share on other sites

  • 1 year later...

I finished the whole process of systemC build and check and installation. All example cases passed in command line.

However, when I tried to integrate the env into vscode per https://github.com/fmuller-pns/systemc-vscode-project-template. It generated error like:

 *  Executing task: bash -c 'make all' 

g++  -L/Users/davidpeng/systemc/systemc/lib-macosxarm -lsystemc  -o build/main build/src/main.o
Undefined symbols for architecture arm64:
  "sc_core::sc_api_version_2_3_4_cxx199711L<&sc_core::SC_DISABLE_VIRTUAL_BIND_UNDEFINED_>::sc_api_version_2_3_4_cxx199711L(sc_core::sc_writer_policy, bool)", referenced from:
      ___cxx_global_var_init in main.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/main] Error 1

Any idea? please help.

Link to comment
Share on other sites

Hi, 

Thanks for David Black's reminder. I added -std=c++17 in my CXXFLAGS and it passed now.

I didn't use c++ for quite a while I encountered several issues in the whole process, I wonder whether you guys can explain or suggest better steps:

I used home-brew to install g++ instead of clang with Xcode.

1. config/boot strap

2. autoupdate

[dp] if don't run step 1 & 2, step 5 will report error as

config.status: error: cannot find input file: `src/Makefile.in'

3. update configure file, add arm section as above

4. run ../configure --enable-debug CXXFLAGS=-std=c++17 (in objdir)

[dp] i am not sure which c++ std is best, seems 17 is the latest one which SystemC supports. But at least c++11. Otherwise step 8 below will generate segment fault failure on semophone. Which c++ std is more popular in SystemC domain?

5. run make. it will run into "architecture not support" again

[dp] It seems this step will update configure file, as I checked the configure file before the step.

6. do same as step 3.

7. run make again, this time it passes.

8. make check.

9. make install

Thanks,

David

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Hi all,

Thanks for opening this discussion and all the helpful hints. I managed to build SystemC on Apple M2 silicon using the cmake approach. @William Lock and @Philipp A Hartmann already mentioned that you have to change the CMAKE_CXX_STANDARD in the CmakeLists.txt, but as some people seem to still have trouble, I’d like to share what I did.

git clone git@github.com:accellera-official/systemc.git systemc-2.3.4
cd systemc-2.3.4

open the CMakeLists.txt and replace:

set (CMAKE_CXX_STANDARD 98 CACHE STRING "C++ standard to build all targets. Supported values are 98, 11, 14, and 17.")
set (CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "The with CMAKE_CXX_STANDARD selected C++ standard is a requirement.")
mark_as_advanced (CMAKE_CXX_STANDARD_REQUIRED)

with:

set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

 

mkdir BUILD && mkdir INSTALL && cd BUILD
cmake -DCMAKE_INSTALL_PREFIX="../INSTALL" ..
make
make install
cd ../..

g++ -std=c++17 -I systemc-2.3.4/INSTALL/include -Lsystemc-2.3.4/INSTALL/lib -lsystemc -o systemc_helloworld systemc_helloworld.cpp


Add SystemC to default include path (to be able to use #include <systemc.h> in systemc_helloworld.cpp):

sudo cp -r systemc-2.3.4/INSTALL/include/* /usr/local/include/
sudo cp systemc-2.3.4/INSTALL/lib/libsystemc.dylib /usr/local/lib

g++ -std=c++17 -lsystemc -o systemc_helloworld systemc_helloworld.cpp


Greetings from Munich,
Lasse

Link to comment
Share on other sites

  • 2 months later...

Hi Lasse. after building systemc lib with your directions - systemc-2.3.4 and Apple MacBook with M2 - I get on the helloworld command the next error - mismatch between the ARCH versions. 

"ld: warning: ignoring file /'usr/local/lib/libsystemc.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64"

below is the output of the "cmake -DCMAKE_INSTALL_PREFIX="../INSTALL" .." 

have I missed any setup (I downloaded official 2.3.4 tar file from accellera.com and walkthrough you last post above.

 

"

-- Settings to build SystemC 2.3.4 (20221128) and TLM 2.0.6 (20191203)
-- ------------------------------------------------------------------------
-- BUILD_SHARED_LIBS = ON
-- BUILD_SOURCE_DOCUMENTATION = OFF
-- CMAKE_BUILD_TYPE = Release
-- DISABLE_ASYNC_UPDATES = OFF
-- DISABLE_COPYRIGHT_MESSAGE = OFF
-- DISABLE_VCD_SCOPES = OFF
-- DISABLE_VIRTUAL_BIND = OFF
-- ENABLE_ASSERTIONS = ON
-- ENABLE_EARLY_MAXTIME_CREATION = ON
-- ENABLE_IMMEDIATE_SELF_NOTIFICATIONS = OFF
-- ENABLE_PHASE_CALLBACKS = OFF
-- ENABLE_PHASE_CALLBACKS_TRACING = ON
-- ENABLE_PTHREADS = OFF
-- ENABLE_LEGACY_MEM_MGMT = OFF
-- SystemC_TARGET_ARCH = macosx64
-- SystemCLanguage_VERSION = 2.3.4
-- SystemCTLM_VERSION = 2.0.6
-- INSTALL_TO_LIB_BUILD_TYPE_DIR = OFF
-- INSTALL_TO_LIB_TARGET_ARCH_DIR = OFF
-- INSTALL_LIB_TARGET_ARCH_SYMLINK = OFF
-- ------------------------------------------------------------------------
-- CMAKE_CXX_STANDARD = 17
-- CMAKE_CXX_STANDARD_REQUIRED = ON
-- CMAKE_SYSTEM = Darwin-22.6.0
-- CMAKE_SYSTEM_PROCESSOR = x86_64
-- QT_ARCH = x86_64
-- CMAKE_OSX_ARCHITECTURES =
-- CMAKE_OSX_DEPLOYMENT_TARGET =
-- CMAKE_OSX_SYSROOT = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.4.sdk
-- Threads_FOUND = TRUE
-- CMAKE_USE_PTHREADS_INIT = 1
-- CMAKE_THREAD_LIBS_INIT =
-- ------------------------------------------------------------------------
-- CMAKE_INSTALL_PREFIX = /Users/oricohenmonbaz/debug/systemc/lib/systemc-2.3.4/install
-- CMAKE_INSTALL_BINDIR = bin
-- CMAKE_INSTALL_DOCDIR = share/doc/systemc
-- CMAKE_INSTALL_INCLUDEDIR = include
-- CMAKE_INSTALL_LIBDIR = lib
-- INSTALL_CMAKEDIR =

"

Thanks

Ori

Link to comment
Share on other sites

Hi Ori,

The following two lines of your provided output are wrong:

-- CMAKE_SYSTEM_PROCESSOR = x86_64
-- QT_ARCH = x86_64

You don't have x86 architecture. Your processor is arm64 and the qt_arch should be aarch64. It should be detected automatically, I don't know why it is not set correctly in your case. Please check your cmake installation and env variables, and go through the CMakeLists.txt for further debugging. A quick attempt can be to

set (CMAKE_SYSTEM_PROCESSOR arm64)
set (QT_ARCH aarch64)

in CMakeLists.txt. You might need to comment out the other logic setting the QT_ARCH variable. Please have a deeper look into the CMakeLists.txt and understand better what's going on there.

Best,
Lasse

Link to comment
Share on other sites

thanks Lasse. 

so with correct configuration I hit many errors like this on file "systemc-2.3.4/src/sysc/packages/qt/md/aarch64.s"

do you think its related to the clang++ version I am using (I compile on MACOS13 - Ventura)

"oricohenmonbaz@h-MacBook-Pro-sl-ori build % g++ -v
Apple clang version 15.0.0 (clang-1500.0.28.1.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix"

Error output:

Building ASM object src/CMakeFiles/systemc.dir/sysc/packages/qt/md/aarch64.s.o
/Users/oricohenmonbaz/debug/systemc/lib/systemc-2.3.4/src/sysc/packages/qt/md/aarch64.s:19:5: error: unknown use of instruction mnemonic without a size suffix
    mov x0, x25
    ^
/Users/oricohenmonbaz/debug/systemc/lib/systemc-2.3.4/src/sysc/packages/qt/md/aarch64.s:20:5: error: unknown use of instruction mnemonic without a size suffix
    mov x1, x26
    ^
/Users/oricohenmonbaz/debug/systemc/lib/systemc-2.3.4/src/sysc/packages/qt/md/aarch64.s:21:5: error: unknown use of instruction mnemonic without a size suffix
    mov x2, x27
    ^
/Users/oricohenmonbaz/debug/systemc/lib/systemc-2.3.4/src/sysc/packages/qt/md/aarch64.s:22:5: error: invalid instruction mnemonic 'br'
    br x28
    ^~

 

Best

Ori

Link to comment
Share on other sites

  • 2 weeks later...

You need to be sure you don't have any lingering x86_64 libraries (library files end in .a or .so)  lingering on your machine. I had to search out all my libraries and replace/upgrade them with the appropriate versions.

If you are using Qt, be sure it's compiled to arm64.

If you are using Homebrew or MacPorts, you will need to make sure they also compile to arm64.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...