Skip to content

Commit b283686

Browse files
committed
merge cnmatrix subtree
2 parents f686f09 + 18407cb commit b283686

File tree

22 files changed

+2560
-0
lines changed

22 files changed

+2560
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types:
8+
- created
9+
10+
env:
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
use_eigen: [ON]
20+
build_type: [Release]
21+
os: [ubuntu-18.04, windows-latest]
22+
use_single_precision: [ON, OFF]
23+
include:
24+
- os: ubuntu-18.04
25+
build_type: Debug
26+
use_eigen: OFF
27+
use_single_precision: ON
28+
- os: ubuntu-18.04
29+
build_type: Debug
30+
use_eigen: ON
31+
use_single_precision: ON
32+
- os: ubuntu-18.04
33+
build_type: Debug
34+
use_eigen: ON
35+
use_single_precision: OFF
36+
- os: windows-latest
37+
build_type: Debug
38+
use_eigen: ON
39+
steps:
40+
- uses: actions/checkout@v2
41+
with:
42+
fetch-depth: 0
43+
- if: contains(matrix.os, 'ubuntu')
44+
name: Get Dependencies
45+
run: |
46+
sudo apt-get update
47+
sudo apt-get install p7zip-full build-essential zlib1g-dev liblapacke-dev libopenblas-dev libatlas-base-dev python3 python3-pip apt-transport-https python-virtualenv ninja-build libeigen3-dev ${{ matrix.deps }}
48+
- uses: actions/setup-python@v2
49+
with:
50+
python-version: '3.x'
51+
- name: Setup windows flags
52+
if: contains(matrix.os, 'windows') && matrix.build_type == 'Release'
53+
id: flags
54+
run: echo "::set-output name=SETUP_PY_FLAGS::-G 'Visual Studio 16 2019'"
55+
- name: Get mac dependencies
56+
if: contains(matrix.os, 'macos')
57+
run: |
58+
brew install freeglut lapack openblas
59+
- name: Create Build Environment
60+
# Some projects don't allow in-source building, so create a separate build directory
61+
# We'll use this as our working directory for all subsequent commands
62+
run: cmake -E make_directory ${{runner.workspace}}/build
63+
64+
- name: Configure CMake
65+
shell: bash
66+
working-directory: ${{runner.workspace}}/build
67+
run: cmake $GITHUB_WORKSPACE -DUSE_EIGEN=${{matrix.use_eigen}} -DDOWNLOAD_EIGEN=${{matrix.use_eigen}} -DUSE_SINGLE_PRECISION=${{matrix.use_single_precision}} -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_TESTS=ON -DCMAKE_INSTALL_PREFIX=install_root ${{matrix.config_flags}}
68+
69+
- name: Build
70+
working-directory: ${{runner.workspace}}/build
71+
shell: bash
72+
# Execute the build. You can specify a specific target with "--target <NAME>"
73+
run: cmake --build . --config $BUILD_TYPE -v
74+
75+
- name: Install
76+
working-directory: ${{runner.workspace}}/build
77+
shell: bash
78+
# Execute the build. You can specify a specific target with "--target <NAME>"
79+
run: cmake --build . --config $BUILD_TYPE --target install
80+
81+
- name: Set bundle name
82+
id: bundle
83+
run: echo "BUNDLE_FILE_NAME=cnmatrix-$(git describe --tags)-${{ matrix.os }}.zip" >> $GITHUB_OUTPUT
84+
85+
- name: Bundle
86+
if: matrix.build_type == 'Release'
87+
working-directory: ${{runner.workspace}}/cnmatrix
88+
run: 7z a ${{runner.workspace}}/build/${{ steps.bundle.outputs.BUNDLE_FILE_NAME }} ${{runner.workspace}}/build/install_root/*
89+
90+
- uses: actions/upload-artifact@v4
91+
name: Upload
92+
if: matrix.build_type == 'Release'
93+
with:
94+
name: cnmatrix-${{ matrix.os }}-${{ matrix.build_type }}
95+
path: |
96+
${{runner.workspace}}/build/${{steps.bundle.outputs.BUNDLE_FILE_NAME}}
97+
# TODO: sort out single precision on/off collision
98+
overwrite: true
99+
100+
- name: Get release
101+
id: get_release
102+
if: github.event_name == 'release'
103+
uses: bruceadams/get-release@v1.2.2
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
107+
- name: Upload Release Asset
108+
id: upload-release-asset
109+
continue-on-error: true
110+
if: github.event_name == 'release'
111+
uses: actions/upload-release-asset@v1
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
with:
115+
upload_url: ${{ steps.get_release.outputs.upload_url }}
116+
asset_path: ${{runner.workspace}}/build/${{steps.bundle.outputs.BUNDLE_FILE_NAME}}
117+
asset_name: ${{steps.bundle.outputs.BUNDLE_FILE_NAME}}
118+
asset_content_type: application/zip
119+
120+
- name: Test
121+
working-directory: ${{runner.workspace}}/build
122+
shell: bash
123+
# Execute tests defined by the CMake configuration.
124+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
125+
run: ctest -C $BUILD_TYPE --output-on-failure -j30

libs/cnmatrix/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Linux
2+
.idea
3+
*.o
4+
*.so
5+
lib
6+
cmake-build-*
7+
build*
8+
9+
# Temp files
10+
*~
11+
*/\#*\#
12+
\#*\#
13+
14+
15+
# Windows specific
16+
*.dll
17+
*.exe
18+
obj/
19+
bin/
20+
x64/
21+
packages
22+
.vs/
23+
Debug/
24+
Release/
25+
*.VC.db
26+
*.user
27+
*.ipch
28+
*.tlog
29+
*.d
30+
build
31+
32+
.options
33+
.zip
34+
.avi
35+
36+
*/__pycache__
37+
*.pyc
38+
39+
venv
40+
.eggs/
41+
dist/

libs/cnmatrix/Android.mk

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
ifneq ($(TARGET_SURVIVE_MATH_BACKEND),)
4+
SURVIVE_MATH_BACKEND := $(TARGET_SURVIVE_MATH_BACKEND)
5+
else
6+
SURVIVE_MATH_BACKEND := eigen
7+
endif
8+
9+
include $(CLEAR_VARS)
10+
LOCAL_MODULE := libcnmatrix
11+
LOCAL_SRC_FILES := src/cn_matrix.c
12+
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
13+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
14+
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
15+
LOCAL_PROPRIETARY_MODULE := true
16+
17+
LOCAL_CFLAGS := \
18+
-Wno-error=unused-const-variable \
19+
-Wno-error=unused-function \
20+
-Wno-error=unused-parameter
21+
22+
ifeq ($(SURVIVE_MATH_BACKEND),eigen)
23+
LOCAL_SRC_FILES += src/eigen/core.cpp src/eigen/gemm.cpp src/eigen/svd.cpp
24+
LOCAL_CFLAGS += -DUSE_EIGEN
25+
LOCAL_HEADER_LIBRARIES += libeigen
26+
else ifeq ($(SURVIVE_MATH_BACKEND),blas)
27+
# This needs a blas library to link, which is not easily available
28+
LOCAL_SRC_FILES += src/cn_matrix.blas.c
29+
else
30+
$(error Unsupported cnmatrix backend: $(SURVIVE_MATH_BACKEND))
31+
endif
32+
33+
include $(BUILD_STATIC_LIBRARY)

libs/cnmatrix/CMakeLists.txt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(cnmatrix LANGUAGES C CXX)
4+
include(CTest)
5+
6+
option(ENABLE_TESTS "Enable tests" OFF)
7+
if (${ENABLE_TESTS})
8+
enable_testing()
9+
endif()
10+
11+
include(CheckIncludeFile)
12+
include (CheckSymbolExists)
13+
14+
15+
macro(CNMATRIX_OPTION ARG DESC)
16+
option(${ARG} ${DESC} ${ARGN})
17+
SET(${ARG} ${ARGN})
18+
message("-- CNMatrix option: ${ARG}: ${ARGN}")
19+
endmacro()
20+
21+
CNMATRIX_OPTION(DOWNLOAD_EIGEN "Download eigen if it isn't installed on the system" ON)
22+
CNMATRIX_OPTION(USE_EIGEN "Use eigen for math operations" ${DOWNLOAD_EIGEN})
23+
CNMATRIX_OPTION(USE_COLUMN_MAJOR_MATRICES "Use column major matrices for math operations" OFF)
24+
CNMATRIX_OPTION(USE_SINGLE_PRECISION "Use floats instead of doubles" OFF)
25+
26+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
27+
28+
find_package (Eigen3 3.3 QUIET)
29+
if(NOT EIGEN3_FOUND)
30+
if(DOWNLOAD_EIGEN)
31+
find_program(GIT git)
32+
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/libeigen-src/Eigen")
33+
execute_process(COMMAND ${GIT} clone -b 3.4 https://gitlab.com/libeigen/eigen.git "${CMAKE_CURRENT_BINARY_DIR}/libeigen-src")
34+
endif()
35+
set(EIGEN3_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/libeigen-src/")
36+
set(USE_EIGEN ON)
37+
else()
38+
message(WARNING "Could not find eigen; falling back to other backend")
39+
set(USE_EIGEN OFF)
40+
endif()
41+
else()
42+
MESSAGE("Found system eigen")
43+
endif()
44+
45+
IF(USE_EIGEN)
46+
add_compile_definitions(USE_EIGEN)
47+
48+
if(USE_COLUMN_MAJOR_MATRICES)
49+
add_compile_definitions(CN_MATRIX_IS_COL_MAJOR)
50+
endif()
51+
ENDIF()
52+
53+
find_library(CBLAS_LIB NAMES cblas)
54+
set(USE_OPENBLAS_DEFAULT OFF)
55+
if(NOT CBLAS_LIB)
56+
if(NOT USE_EIGEN)
57+
set(USE_OPENBLAS_DEFAULT ON)
58+
endif()
59+
endif()
60+
61+
CNMATRIX_OPTION(USE_OPENBLAS "Use OpenBLAS" ${USE_OPENBLAS_DEFAULT})
62+
63+
install(DIRECTORY include/cnmatrix DESTINATION include)
64+
include(GNUInstallDirs)
65+
configure_file(cnmatrix.pc.in cnmatrix.pc @ONLY)
66+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cnmatrix.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
67+
68+
IF(UNIX)
69+
set(SHARED_FLAGS "-fPIC -Wall -Wno-unused-variable -Wno-switch -Wno-parentheses -Wno-missing-braces -Werror=return-type -fvisibility=hidden -Werror=vla -fno-math-errno -Werror=missing-field-initializers -Werror=pointer-arith")
70+
71+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SHARED_FLAGS} -std=gnu99 -Werror=incompatible-pointer-types -Werror=implicit-function-declaration ")
72+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SHARED_FLAGS} -std=c++14")
73+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
74+
75+
if(ENABLE_WARNINGS_AS_ERRORS)
76+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
77+
endif()
78+
79+
ELSEIF(WIN32)
80+
add_compile_options(/wd4244 /wd4996 /wd4018 /wd4101 /wd4477 /wd4068 /wd4217)
81+
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
82+
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
83+
endif()
84+
85+
86+
add_subdirectory(src)
87+
88+
if(ENABLE_TESTS)
89+
add_subdirectory(tests)
90+
endif()
91+

libs/cnmatrix/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 cntools
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libs/cnmatrix/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CNMatrix [![.github/workflows/cmake.yml](https://github.com/cntools/cnmatrix/actions/workflows/cmake.yml/badge.svg)](https://github.com/cntools/cnmatrix/actions/workflows/cmake.yml)
2+
3+
This library provides a consistent C interface to a few matrix backends.
4+
5+
The interface itself is a little more sane than raw lapack / blas calls, and is meant to be reasonably performant for medium to large matrices. It should also be cross platform and work reasonably well on embedded low latency systems; as it consistently tries to avoid heap allocations.
6+
7+
As a caveat though; this library makes sense for C code bases, for C++ codebases it likely makes more sense to just use eigen directly.
8+
9+

0 commit comments

Comments
 (0)