Skip to content

Commit

Permalink
Merge pull request #1 from CodeWithKyrian/main
Browse files Browse the repository at this point in the history
Support for Building Rindow Matlib Library on macOS
  • Loading branch information
yuichiis authored Apr 25, 2024
2 parents 185d60a + 9ba9bd8 commit 25cee59
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_subdirectory(./src)
add_subdirectory(./include)
add_subdirectory(./tests)

if(UNIX)
if(UNIX AND NOT APPLE)
add_subdirectory(./debian)
endif()

Expand Down
81 changes: 73 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ Rindow Math Matrix is the fundamental package for scientific matrix operation
You can call a high-speed calculation library written in C language to speed up matrix calculation processing.
Rindow Matlib includes many matrix operations functions used in machine learning.

Please see the documents about rindow mathematics on [Rindow Mathematics](https://rindow.github.io/mathematics/openblas/mathlibrary.html) web pages.
Please see the documents about rindow mathematics
on [Rindow Mathematics](https://rindow.github.io/mathematics/openblas/mathlibrary.html) web pages.

Requirements
============
- Windows 10 or later, Linux(Ubuntu 20.04 or later)

- Windows 10 or later, Linux(Ubuntu 20.04 or later)

How to setup pre-build binaries
===============================

### How to setup for Windows

Download the pre-build binary file.

- https://github.com/rindow/rindow-matlib/releases
Expand All @@ -33,11 +35,12 @@ C> PATH %PATH%;C:\path\to\bin
```

### How to setup for Ubuntu

Download the pre-build binary file.

- https://github.com/rindow/rindow-matlib/releases

Please install using the apt command.
Please install using the apt command.

```shell
$ sudo apt install ./rindow-matlib_X.X.X_amd64.deb
Expand All @@ -58,11 +61,37 @@ There are 2 choices for the alternative librindowmatlib.so (providing /usr/lib/l
Press <enter> to keep the current choice[*], or type selection number: 2
```

### How to setup for MacOS

Download the pre-build binary file.

- https://github.com/rindow/rindow-matlib/releases

Extract the tar.gz file to the tmp directory and navigate to the directory.

```shell
$ tar -xzf rindow-matlib-X.X.X-Darwin.tar.gz -C /tmp
$ cd /tmp/rindow-matlib-X.X.X-Darwin
```

Next, copy the include and lib directories to /usr/local.

```shell
$ sudo cp -r usr/include /usr/local/
$ sudo cp -r usr/lib /usr/local/
```

Depending on whether you are using OpenMP or not, you need to set the symbolic link.

```shell
$ sudo ln -s /usr/local/lib/rindowmatlib-openmp/librindowmatlib.dylib /usr/local/lib/librindowmatlib.dylib
```

How to build from source code on Windows
========================================
You can also build and use from source code.

### download source code
### Download source code

Download source code from release and unzip

Expand All @@ -81,6 +110,7 @@ C> ctest -C Release
C> cpack -C Release
C> cd ..\packages
```

Unzip the package file from packages directory.

```shell
Expand All @@ -91,7 +121,7 @@ How to build from source code on Ubuntu
=======================================
You can also build and use from source code.

### download source code
### Download source code

Download source code from release and extract

Expand All @@ -108,7 +138,8 @@ $ cmake --build build --config Release
$ (cd build; ctest -C Release)
$ (cd build; cpack -C Release)
```
Install with apt commnand.

Install with apt command.

```shell
$ sudo apt install ./packages/rindow-matlib_X.X.X_amd64.deb
Expand All @@ -129,10 +160,34 @@ There are 2 choices for the alternative librindowmatlib.so (providing /usr/lib/l
Press <enter> to keep the current choice[*], or type selection number: 2
```

How to build from source code on MacOS
=======================================

You can also build and use from source code.

### Download source code

Download source code from release and extract

- https://github.com/rindow/rindow-matlib/releases

### Build and Install on MacOS

Build with cmake.

```shell
$ cd \path\to\here
$ cmake -S . -B build
$ cmake --build build --config Release
$ (cd build; ctest -C Release)
$ (cd build; cpack -C Release)
```

How to use
==========

### sample program

```cpp
#include <iostream>
#include <string>
Expand Down Expand Up @@ -199,10 +254,20 @@ int main(int ac, char **av)
}
```
### build the sample program on Windows.
### Build the sample program on Windows.
```shell
C> cl /EHsc -I.\path\to\include sample.cpp \path\to\lib\rindowmatlib.lib
```

### build the sample program on Ubuntu.
### Build the sample program on Ubuntu.

```shell
$ g++ sample.cpp -lrindowmatlib -lm
```

### Build the sample program on MacOS.

```shell
$ g++ sample.cpp -lrindowmatlib -lm
```
2 changes: 2 additions & 0 deletions cmake/Packing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ if(MSVC)
set(CPACK_GENERATOR "ZIP")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_PACKAGING_INSTALL_PREFIX ".")
elseif(APPLE)
set(CPACK_GENERATOR "TGZ")
elseif(UNIX)
set(CPACK_GENERATOR "DEB")
endif()
Expand Down
19 changes: 19 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ add_library(rindowmatlib SHARED ${srcfiles})
target_compile_options(rindowmatlib PRIVATE -DRINDOW_COMPILING_DLL)
if (MSVC)
target_compile_options(rindowmatlib PRIVATE /openmp:experimental)

elseif(APPLE)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C "${CMAKE_C_COMPILER}" CACHE STRING "" FORCE)
set(OpenMP_C_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES} CACHE STRING "" FORCE)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX "${CMAKE_CXX_COMPILER}" CACHE STRING "" FORCE)
set(OpenMP_CXX_FLAGS "-fopenmp=libomp -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5" CACHE STRING "" FORCE)
set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES} CACHE STRING "" FORCE)
endif()

elseif(UNIX)
find_package(OpenMP REQUIRED)
if(OpenMP_FOUND)
Expand Down
22 changes: 14 additions & 8 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@
#include <stdint.h>

#ifdef _MSC_VER
#include <windows.h>
#include <windows.h> // For Windows
#elif defined(__APPLE__)
#include <sys/sysctl.h> // For macOS
#include <mach/mach.h> // For macOS
#else
#include <sys/sysinfo.h>
#include <sys/sysinfo.h> // For Linux and other Unix-like systems
#endif
#ifdef _OPENMP
#include <omp.h>
#endif

#include <stdlib.h>
#ifndef _OPENMP
#ifdef _MSC_VER
#include <sysinfoapi.h>
#else
#include <sys/sysinfo.h>
#include <pthread.h>
#endif
#ifdef _MSC_VER
#include <sysinfoapi.h> // Include Windows-specific header for system information
#elif defined(__APPLE__)
#include <sys/sysctl.h> // Include sysctl.h for system information
#include <pthread.h> // Include pthread.h for POSIX threads
#else
#include <sys/sysinfo.h> // Include sysinfo.h for system information (Linux)
#include <pthread.h> // Include pthread.h for POSIX threads
#endif
#include <memory.h>
#endif

Expand Down

0 comments on commit 25cee59

Please sign in to comment.