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

Add extension with basic support for Blaze library #496

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
sudo -E apt-get update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install libpng-dev libjpeg-dev libtiff5-dev libraw-dev
displayName: 'Install dependencies'
- template: .ci/azure-pipelines/steps-install-blaze.yml
- template: .ci/azure-pipelines/steps-install-boost.yml
- template: .ci/azure-pipelines/steps-cmake-build-and-test.yml

Expand All @@ -41,6 +42,7 @@ jobs:
sudo -E apt-get update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install libpng-dev libjpeg-dev libtiff5-dev libraw-dev
displayName: 'Install dependencies'
- template: .ci/azure-pipelines/steps-install-blaze.yml
- template: .ci/azure-pipelines/steps-install-boost.yml
- template: .ci/azure-pipelines/steps-cmake-build-and-test.yml
parameters:
Expand All @@ -58,6 +60,7 @@ jobs:
architecture: 'x64'
- template: .ci/azure-pipelines/steps-check-cmake.yml
- template: .ci/azure-pipelines/steps-install-conan.yml
- template: .ci/azure-pipelines/steps-install-blaze.yml
- template: .ci/azure-pipelines/steps-install-boost.yml
- template: .ci/azure-pipelines/steps-cmake-build-and-test.yml
parameters:
Expand All @@ -75,6 +78,7 @@ jobs:
architecture: 'x64'
- template: .ci/azure-pipelines/steps-check-cmake.yml
- template: .ci/azure-pipelines/steps-install-conan.yml
- template: .ci/azure-pipelines/steps-install-blaze.yml
- template: .ci/azure-pipelines/steps-install-boost.yml
- template: .ci/azure-pipelines/steps-cmake-build-and-test.yml
parameters:
Expand All @@ -94,6 +98,7 @@ jobs:
- template: .ci/azure-pipelines/steps-install-boost.yml
parameters:
toolset: darwin
- template: .ci/azure-pipelines/steps-install-blaze.yml
- template: .ci/azure-pipelines/steps-cmake-build-and-test.yml
parameters:
use_conan: 'ON'
4 changes: 2 additions & 2 deletions .ci/azure-pipelines/steps-cmake-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ steps:
export BOOST_ROOT=$(Build.SourcesDirectory)/boost-root
export BOOST_INCLUDEDIR=$BOOST_ROOT
export BOOST_LIBRARYDIR=$BOOST_ROOT/lib
cmake -H. -B_build -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DCMAKE_CXX_STANDARD=${{ parameters.cxxver }} -DCMAKE_VERBOSE_MAKEFILE=ON -DBoost_DEBUG=ON -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_GIL_USE_CONAN=${{ parameters.use_conan }} -DBOOST_GIL_ENABLE_EXT_IO=${{ parameters.enable_ext_io }} -DBOOST_GIL_ENABLE_EXT_NUMERIC=${{ parameters.enable_ext_numeric }} -DBOOST_GIL_ENABLE_EXT_TOOLBOX=${{ parameters.enable_ext_toolbox }}
cmake -H. -B_build -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DCMAKE_CXX_STANDARD=${{ parameters.cxxver }} -DCMAKE_VERBOSE_MAKEFILE=ON -DBoost_DEBUG=ON -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_GIL_USE_CONAN=${{ parameters.use_conan }} -DBOOST_GIL_ENABLE_EXT_IO=${{ parameters.enable_ext_io }} -DBOOST_GIL_ENABLE_EXT_NUMERIC=${{ parameters.enable_ext_numeric }} -DBOOST_GIL_ENABLE_EXT_TOOLBOX=${{ parameters.enable_ext_toolbox }} -DBOOST_GIL_ENABLE_EXT_BLAZE=ON
workingDirectory: $(Build.SourcesDirectory)/boost-root/libs/gil
displayName: 'Run CMake to configure build on Unix'
condition: ne(variables['Agent.OS'], 'Windows_NT')
Expand All @@ -27,7 +27,7 @@ steps:
set BOOST_ROOT=$(Build.SourcesDirectory)\boost-root
set BOOST_INCLUDEDIR=%BOOST_ROOT%
set BOOST_LIBRARYDIR=%BOOST_ROOT%\lib
cmake -H. -B_build -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DCMAKE_CXX_STANDARD=${{ parameters.cxxver }} -DCMAKE_VERBOSE_MAKEFILE=ON -DBoost_DEBUG=ON -DBoost_ADDITIONAL_VERSIONS="1.70;1.71" -DBoost_ARCHITECTURE=-x32 -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_GIL_USE_CONAN=${{ parameters.use_conan }} -DBOOST_GIL_ENABLE_EXT_IO=${{ parameters.enable_ext_io }} -DBOOST_GIL_ENABLE_EXT_NUMERIC=${{ parameters.enable_ext_numeric }} -DBOOST_GIL_ENABLE_EXT_TOOLBOX=${{ parameters.enable_ext_toolbox }}
cmake -H. -B_build -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DCMAKE_CXX_STANDARD=${{ parameters.cxxver }} -DCMAKE_VERBOSE_MAKEFILE=ON -DBoost_DEBUG=ON -DBoost_ADDITIONAL_VERSIONS="1.70;1.71" -DBoost_ARCHITECTURE=-x32 -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_GIL_USE_CONAN=${{ parameters.use_conan }} -DBOOST_GIL_ENABLE_EXT_IO=${{ parameters.enable_ext_io }} -DBOOST_GIL_ENABLE_EXT_NUMERIC=${{ parameters.enable_ext_numeric }} -DBOOST_GIL_ENABLE_EXT_TOOLBOX=${{ parameters.enable_ext_toolbox }} -DBOOST_GIL_ENABLE_EXT_BLAZE=ON
workingDirectory: $(Build.SourcesDirectory)/boost-root/libs/gil
displayName: 'Run CMake to configure build on Windows'
condition: eq(variables['Agent.OS'], 'Windows_NT')
Expand Down
14 changes: 14 additions & 0 deletions .ci/azure-pipelines/steps-install-blaze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Azure pipelines for Boost.GIL
#
# Copyright 2019 Olzhas Zhumabek <[email protected]>
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)

steps:
- bash: |
git clone --depth=1 https://[email protected]/scarlet-roses/blaze.git
cd blaze
mkdir build && cd build
cmake -DUSE_LAPACK=OFF -DBLAZE_BLAS_MODE=OFF -DBLAZE_CACHE_SIZE_AUTO=OFF -DBLAZE_CACHE_SIZE_DEFAULT=131072 ..
sudo make install
displayName: "Install Blaze"
34 changes: 33 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ option(BOOST_GIL_ENABLE_EXT_NUMERIC "Enable Numeric extension, tests and example
option(BOOST_GIL_ENABLE_EXT_TOOLBOX "Enable Toolbox extension, tests and examples" ON)
option(BOOST_GIL_USE_CONAN "Use Conan to install dependencies" OFF)
option(BOOST_GIL_USE_CLANG_TIDY "Set CMAKE_CXX_CLANG_TIDY property on targets to enable clang-tidy linting" OFF)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)")
option(BOOST_GIL_ENABLE_EXT_BLAZE "Enable Blaze library extensions, tests and examples" OFF)
set(BOOST_GIL_BLAS_LIBRARY "" CACHE STRING "BLAS library to use with Blaze, only queried if BOOST_GIL_ENABLE_EXT_BLAZE is on")

if (BOOST_GIL_ENABLE_EXT_BLAZE)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard version to use (requires at least 17 for Blaze extension)")
else()
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)")
endif()

#-----------------------------------------------------------------------------
# Project
Expand Down Expand Up @@ -196,6 +203,31 @@ if(BOOST_GIL_ENABLE_EXT_IO)
endif()
endif()

#-----------------------------------------------------------------------------
# Optional dependency: Blaze
#-----------------------------------------------------------------------------
if (BOOST_GIL_ENABLE_EXT_BLAZE)
# Just add to the dependencies target
find_package(blaze REQUIRED)
target_link_libraries(gil_dependencies INTERFACE blaze::blaze)
# do nothing if BOOST_GIL_BLAS_LIBRARY is empty, hope that Blaze installation used defaults
# Usage notes for Intel MKL: either pass MKLROOT or have env variable MKLROOT set
# It is a requirement of find_package
if (BOOST_GIL_BLAS_LIBRARY STREQUAL MKL)
if (DEFINED MKLROOT)
set(ENV{MKLROOT} ${MKLROOT})
elseif(NOT DEFINED ENV{MKLROOT})
message(FATAL_ERROR "Please either pass MKLROOT variable or set environment variable MKLROOT")
endif()
add_library(mkl INTERFACE)
find_package(BLAS)
target_include_directories(mkl INTERFACE $ENV{MKLROOT}/include)
target_link_libraries(mkl INTERFACE ${BLAS_LIBRARIES})
target_link_libraries(gil_dependencies INTERFACE mkl)
endif()
# TODO: support for OpenBLAS and other BLAS libraries for Blaze
endif()

#-----------------------------------------------------------------------------
# clang-tidy
# - default checks specified in .clang-tidy configuration file
Expand Down
9 changes: 9 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ endforeach()

unset(_example)
unset(_examples)

# Blaze targets
if (BOOST_GIL_ENABLE_EXT_BLAZE)
foreach(blaze_example blaze)
add_executable(${blaze_example} ${blaze_example}.cpp)
target_link_libraries(${blaze_example} PRIVATE gil_include_directories gil_dependencies gil_compile_options)

endforeach()
endif()
18 changes: 18 additions & 0 deletions example/blaze.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <blaze/Blaze.h>
#include <boost/gil/extension/blaze/blaze.hpp>
#include <boost/gil/extension/io/png.hpp>
#include <boost/gil/image.hpp>
#include <boost/gil/image_view.hpp>
#include <boost/gil/typedefs.hpp>

namespace gil = boost::gil;

int main()
{
using element_type = blaze::StaticVector<std::uint8_t, 3>;
element_type v({0, 0, 255});
blaze::DynamicMatrix<element_type> matrix(16, 16, v);

auto image = gil::from_matrix<gil::rgb8_image_t>(matrix);
gil::write_view("output.png", gil::view(image), gil::png_tag{});
}
Loading